Jump to content
thejungle

Dangling Carrot (Free Gift/Discount Contrib)

Recommended Posts

Same problem here.

To try to isolate this problem, find this section of code in admin/gifts.php (starts at line 47)
$freeGifts = array();
 $gift_list_query = tep_db_query("SELECT p.products_id, pd.products_id, pd.products_name FROM products p, products_description pd WHERE pd.language_id = '".$languages_id."'
	 AND p.products_id = pd.products_id AND pd.products_name LIKE 'Gift%' ORDER BY pd.products_name ASC");
 while ($gift_list = tep_db_fetch_array($gift_list_query)) 
  $freeGifts[] = array('id' => $gift_list['products_name'], 'text' => $gift_list['products_name']);

and replace it with this code

  $freeGifts = array();
 $gift_list_query = tep_db_query("SELECT p.products_id, pd.products_id, pd.products_name FROM products p, products_description pd WHERE pd.language_id = '".$languages_id."'
	 AND p.products_id = pd.products_id AND pd.products_name LIKE 'Gift%' ORDER BY pd.products_name ASC");
 echo 'There are '. tep_db_num_rows($gift_list_query) . ' gift products<br><br>';
 while ($gift_list = tep_db_fetch_array($gift_list_query))
 { 
 echo 'Adding ' . $gift_list['products_name'].'<br>';
  $freeGifts[] = array('id' => $gift_list['products_name'], 'text' => $gift_list['products_name']);
  }

Save the file and go to admin->catalog->gifts. What do you see displayed at the top of the page?

 

Jack

Share this post


Link to post
Share on other sites

How is the best way to insert gifts, because the only possibity now is to plase "gift" in front off the product name and that's not so nice.

 

And I can't put it out off stock, when I do that I don't see the gift anymore, anyone with an idea?

Share this post


Link to post
Share on other sites
To try to isolate this problem, find this section of code in admin/gifts.php (starts at line 47)
$freeGifts = array();
?$gift_list_query = tep_db_query("SELECT p.products_id, pd.products_id, pd.products_name FROM products p, products_description pd WHERE pd.language_id = '".$languages_id."'
?	AND p.products_id = pd.products_id AND pd.products_name LIKE 'Gift%' ORDER BY pd.products_name ASC");
?while ($gift_list = tep_db_fetch_array($gift_list_query)) 
? $freeGifts[] = array('id' => $gift_list['products_name'], 'text' => $gift_list['products_name']);

and replace it with this code

 ?$freeGifts = array();
?$gift_list_query = tep_db_query("SELECT p.products_id, pd.products_id, pd.products_name FROM products p, products_description pd WHERE pd.language_id = '".$languages_id."'
?	AND p.products_id = pd.products_id AND pd.products_name LIKE 'Gift%' ORDER BY pd.products_name ASC");
?echo 'There are '. tep_db_num_rows($gift_list_query) . ' gift products<br><br>';
?while ($gift_list = tep_db_fetch_array($gift_list_query))
?{ 
?echo 'Adding ' . $gift_list['products_name'].'<br>';
? $freeGifts[] = array('id' => $gift_list['products_name'], 'text' => $gift_list['products_name']);
? }

Save the file and go to admin->catalog->gifts.  What do you see displayed at the top of the page?

 

Jack

 

 

Thank you for the updates!

Still, cannot update, delete, edit...

Share this post


Link to post
Share on other sites
To try to isolate this problem, find this section of code in admin/gifts.php (starts at line 47)
$freeGifts = array();
?$gift_list_query = tep_db_query("SELECT p.products_id, pd.products_id, pd.products_name FROM products p, products_description pd WHERE pd.language_id = '".$languages_id."'
?	AND p.products_id = pd.products_id AND pd.products_name LIKE 'Gift%' ORDER BY pd.products_name ASC");
?while ($gift_list = tep_db_fetch_array($gift_list_query)) 
? $freeGifts[] = array('id' => $gift_list['products_name'], 'text' => $gift_list['products_name']);

and replace it with this code

 ?$freeGifts = array();
?$gift_list_query = tep_db_query("SELECT p.products_id, pd.products_id, pd.products_name FROM products p, products_description pd WHERE pd.language_id = '".$languages_id."'
?	AND p.products_id = pd.products_id AND pd.products_name LIKE 'Gift%' ORDER BY pd.products_name ASC");
?echo 'There are '. tep_db_num_rows($gift_list_query) . ' gift products<br><br>';
?while ($gift_list = tep_db_fetch_array($gift_list_query))
?{ 
?echo 'Adding ' . $gift_list['products_name'].'<br>';
? $freeGifts[] = array('id' => $gift_list['products_name'], 'text' => $gift_list['products_name']);
? }

Save the file and go to admin->catalog->gifts.  What do you see displayed at the top of the page?

 

Jack

 

 

Thanks for the v1.8 updates.

Still cannot edit, delete or update products...

Share this post


Link to post
Share on other sites
Save the file and go to admin->catalog->gifts.  What do you see displayed at the top of the page?

 

Jack

 

Hi Jack and everyone,

I have also had this problem (can't update, edit, or delete gifts from the admin) since I first added the contribution version 1.7.

 

When I changed the code in gift_add.php in the admin section, here is what shows (whether I hit the update, edit, or delete button):

 

There are 2 gift products

 

Adding Gift - FREE Rose Quartz

Adding Gift -1 oz. Jasmine

 

However, there is only one gift showing on the list, the other is only a possible addition (if that makes a difference).

 

Thanks for any help!

 

Peace,

Erin

Share this post


Link to post
Share on other sites
Hi Jack and everyone,

I have also had this problem (can't update, edit, or delete gifts from the admin) since I first added the contribution version 1.7.

 

One More Thing....

 

I just tried something new.

 

In admin/gift_add.php I replaced this line

<td class="smallText">'.tep_image_submit('button_update.gif', IMAGE_SEARCH).'    <a href="gift_add.php?ID='.$gift['products_id'].'&action=delete">'.tep_image_submit('button_delete.gif', 'Delete').'</a>   <a href="categories.php?pID='.$gift['products_id'].'&action=new_product">'.tep_image_submit('button_edit.gif', 'Edit').'</a> </td>

 

with this line from previous version 1.3

<td class="smallText"><input type="submit" name="submit" value="update">    [ <a href="gift_add.php?ID='.$gift['products_id'].'&action=delete">DELETE</a> ]   [ <a href="categories.php?pID='.$gift['products_id'].'&action=new_product">EDIT ITEM</a> ]</td>

 

Now, the item can be deleted from the admin AND I can hit "edit" and it takes me to the product description page. "Update" does not seem to do anything that I can tell, outside of refreshing the page.

 

So it appears that the problem is in the one line of code, somewhere. I am just not very good at this yet... :-"

 

At least mine seems to work for now, not as pretty, but functional. Hope this helps!

 

Peace,

Erin :D

Share this post


Link to post
Share on other sites

I just uploaded a new version. It eliminates the need to name the product starting with Gift by placing a check box in the admin->catalog products page.

 

To upgrade, run the following sql statement

ALTER TABLE `products` ADD `products_carrot` tinyint(1) default '0' AFTER `products_status`;

Then install the changes for the admin/categories.php and admin/includes/languages/english/categories.php files. Also replace the admin/gift_add.php and the includes/boxes/gifts.php files.

 

Jack

Share this post


Link to post
Share on other sites
I just uploaded a new version. It eliminates the need to name the product starting with Gift by placing a check box in the admin->catalog products page.

 

To upgrade, run the following sql statement

ALTER TABLE `products` ADD `products_carrot` tinyint(1) default '0' AFTER `products_status`;

Then install the changes for the admin/categories.php and admin/includes/languages/english/categories.php files. Also replace the admin/gift_add.php and the includes/boxes/gifts.php files.

 

Jack

 

Excellent update!

But... still cannot edit, delete and update carrots...

Share this post


Link to post
Share on other sites

Hmm. I'm not sure what to say to that then. The code is standard code so it should work. When you place the mouse over the edit button on the admin/gift_add.php page, the url to the product page should be displayed at the bottom of the browser. Do you see that? What does it say if you do?

 

Jack

Share this post


Link to post
Share on other sites
Hmm. I'm not sure what to say to that then. The code is standard code so it should work. When you place the mouse over the edit button on the admin/gift_add.php page, the url to the product page should be displayed at the bottom of the browser. Do you see that? What does it say if you do?

 

Jack

 

Edit:

edit.jpg

 

Delete:

delete.jpg

 

Update:

update.jpg

Share this post


Link to post
Share on other sites

Same problem here, but also when I take the product out of stock I can't see the gift anymore.

Share this post


Link to post
Share on other sites
Hmm. I'm not sure what to say to that then. The code is standard code so it should work. When you place the mouse over the edit button on the admin/gift_add.php page, the url to the product page should be displayed at the bottom of the browser. Do you see that? What does it say if you do?

 

Jack

 

 

When clicking 'update' link goes to: admin/gift_add.php?threshold=30&x=26&y=7

 

When clicking 'delete' link goes to: admin/gift_add.php?threshold=30&x=30&y=6

 

when clicking 'edit' link goes to: admin/gift_add.php?threshold=30&x=36&y=9

 

What do the x's and y's reffer to?

Share this post


Link to post
Share on other sites
Same problem here, but also when I take the product out of stock I can't see the gift anymore.

This is the way it works. If the item is out of stock, you shouldn't offer it as something to add to the cart since it won't be available.

 

Jack

Share this post


Link to post
Share on other sites
When clicking 'update' link goes to: admin/gift_add.php?threshold=30&x=26&y=7

 

When clicking 'delete' link goes to: admin/gift_add.php?threshold=30&x=30&y=6

 

when clicking 'edit' link goes to: admin/gift_add.php?threshold=30&x=36&y=9

 

What do the x's and y's reffer to?

I'm confused. The images you posted show a different link than the one you list here. In the image, the link to the product appears correct when you hover over the edit button. Are you saying that if you click on the edit button, the displayed link is not the one that it goes to? The above x and y appear to be variables posted by the code. I can't imagine why they are shoing up in the link. If you type in the link that appears when you hover over the edit button into the browsers url string, does the link work then?

 

Jack

Share this post


Link to post
Share on other sites

Sorry for the above, can anyone help out with this step of the install....

 

catalog/shopping_cart.php

FIND (around line 228):

 

$info_box_products_name = '<table border="0" cellspacing="2" cellpadding
                                            'params' => 'class="productListing-data" valign="top"',
                                            'text' => tep_draw_input_field('cart_quantity[]', $products[$i]['quantity'], 'size="4"') . tep_draw_hidden_field('products_id[]', $products[$i]['id']));

 

This doesnt actually exist in catalog/shopping_cart.php at all

Ive tried searching for "$info_box_products_name" and thats not in the file anywhere at all.

I redownloaded a fresh MS2.2 and its not in the shopping_cart.php file there either.

The rest of the install is fine, its just this code above.

Thanks in advance.

Share this post


Link to post
Share on other sites

Aha... getting somewhere... maybe.

I just searched for

'text' => tep_draw_input_field('cart_quantity[]', $products[$i]['quantity'], 'size="4"') . tep_draw_hidden_field('products_id[]', $products[$i]['id']));

Which is the last line of the code above, and its only on one line in shopping_cart.php and reads...

$info_box_contents[$cur_row][] = array('align' => 'center',
                                            'params' => 'class="productListing-data" valign="top"',
                                            'text' => tep_draw_input_field('cart_quantity[]', $products[$i]['quantity'], 'size="4"') . tep_draw_hidden_field('products_id[]', $products[$i]['id']));

 

Is this what gets replaced in the step above please?

Thank you.

Share this post


Link to post
Share on other sites

The problem you found is a mistake. If fact, it highlighted another problem I missed. I have uploaded a new version. The last one was still using "Gift" to check for the gift items. I replaced that code so it now checks for the value from the database. In order to do that, the shopping_cart class had to be edited. All of the changes are in the readme. I apologize for any inconvenience this has caused anyone.

 

Jack

Share this post


Link to post
Share on other sites
The problem you found is a mistake. If fact, it highlighted another problem I missed. I have uploaded a new version.  The last one was still using "Gift" to check for the gift items. I replaced that code so it now checks for the value from the database. In order to do that, the shopping_cart class had to be edited. All of the changes are in the readme. I apologize for any inconvenience this has caused anyone.

 

Jack

 

No need to apologise Jack, infact quite the opposite is true!!

Thank you very much for checking this thread, ill give the new upload a shot and see how I get on. :thumbsup: B)

Share this post


Link to post
Share on other sites

Thanks Jack and others for all the work put into this contrib! Just a quick note on those with the multiple pricing contribution installed since I've seen a few questions about it.

 

In step 6 (from instructions for v2.0 of Dangling Carrot) when it comes to the query modification, you'll have to modify your catalog/includes/classes/PriceFormatter.php file instead.

 

Find the loadProduct function:

 

function loadProduct($product_id, $language_id=1)
 {
$sql="select pd.products_name, p.products_model, p.products_image,  p.products_id," .
" p.manufacturers_id, p.products_price, p.products_weight, p.products_carrot," .

 

Note the p.products_carrot addition to that line above... That's about it. Everything else seems to work at this point as far as the 2.0 update.

 

Again, thanks to Jack and other Carrot contributors :) Awesome job.

 

 

--Wlad

Share this post


Link to post
Share on other sites

I tried the new version Jack and got...

 

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /pathtomysite/includes/classes/shopping_cart.php on line 297

 

Lines 295-299 read...

$products_query = tep_db_query("select p.products_id, pd.products_name, p.products_model, p.products_image, p.products_price, p.products_weight, p.products_carrot, p.products_tax_class_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . (int)$products_id . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "');
       if ($products = tep_db_fetch_array($products_query)) {
         $prid = $products['products_id'];
         $products_price = $products['products_price'];
         $specials_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . (int)$prid . "' and status = '1'");

Share this post


Link to post
Share on other sites

hmmmmmmmm not sure what I did wrong there but I tried the install instructions again on shopping_cart.php and it worked fine.

 

Seems I have the same problem of not being able to Edit or Delete, am going to try the suggested fix above to see if that works.

Share this post


Link to post
Share on other sites
I'm confused. The images you posted show a different link than the one you list here.  In the image, the link to the product appears correct when you hover over the edit button. Are you saying that if you click on the edit button, the displayed link is not the one that it goes to?  The above x and y appear to be variables posted by the code. I can't imagine why they are shoing up in the link. If you type in the link that appears when you hover over the edit button into the browsers url string, does the link work then?

 

Jack

 

FYI Jack, the answer to your last question here is yes it does. ;)

Share this post


Link to post
Share on other sites

Not wanting to spam the board with my BS, but I just wanted to report in:

 

Some of the contribs installed:

 

Gv/Coupons

Multiple Pricing + discount/customer

an inhouse contrib for rewards based on total sales for set period

Paypal shopping cart

Hide/Show categories

and some others that can not affect Dangling carrot or other checkout/payment functions.

 

Using 2.0 of Dangling carrot went without any problems and all aspects have been tested with 23 orders over the last hour after installation.

 

Not sure if I missed something but I have to set the gift product to in stock, but because I have that show/hide contrib installed it works out fine that way (it does not show up for customers even if they search for it)

 

So no code or parse errors with 2.0; Job well done Jack!!

Share this post


Link to post
Share on other sites
Not wanting to spam the board with my BS, but I just wanted to report in:

 

Some of the contribs installed:

 

Gv/Coupons

Multiple Pricing + discount/customer

an inhouse contrib for rewards based on total sales for set period

Paypal shopping cart

Hide/Show categories

and some others that can not affect Dangling carrot or other checkout/payment functions.

 

Using 2.0 of Dangling carrot went without any problems and all aspects have been tested with 23 orders over the last hour after installation.

 

Not sure if I missed something but I have to set the gift product to in stock, but because I have that show/hide contrib installed it works out fine that way (it does not show up for customers even if they search for it)

 

So no code or parse errors with 2.0;  Job well done Jack!!

 

 

Oops, spoke to soon: The update button in admin is missing the actual update function/case in the code. The delete or edit links/functions work fine. I'll post the case "update" code here in a few...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×