Jump to content
thejungle

Dangling Carrot (Free Gift/Discount Contrib)

Recommended Posts

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

 

 

I'm installing version 2.0.

In the readme, your instructions for changes in 'catalog/includes/classes/shopping_cart.php' (section 6):

I think you have forgotten a line to add, after the ''weight' => $products['products_weight'],'

should be 'carrot' => $products['products_carrot'], ???

 

apart from that, I didn't have time to go over the admin code, it still doesn't work...

Share this post


Link to post
Share on other sites

This is the dirty way, but if you MUST have it now here goes.. There are better ways to do all this such as using proper TEP coding standards for forms etc. (BTW this is only for the update function to work. The add, delete, edit functions work fine.

 

This is all to gift_add.php in admin.

 

After case 'delete'' add

 

 

 case 'update' :
               $id = $HTTP_GET_VARS['ID'];
               $newthreshold = $HTTP_GET_VARS['newthreshold'];

               if ($id && $newthreshold) {
                       tep_db_query("update free_gifts set threshold ='".$newthreshold."' where products_id = '".$id."'");
               } else {
                       $message = '<font color="red">FORM ERROR</font>';
               }
               tep_redirect('gift_add.php');
       break;

 

 

For ease sake (not the good way, just being lazy right now) replace the whole "while" section that starts on line 92

 

while ($gift = tep_db_fetch_array($gift_query)) {

                               echo '<form action="gift_add.php" method="GET"><tr>
                               <td class="smallText">$<input type="text" size="4" name="threshold"
value="'.$gift['threshold'].'"></td>
                               <td class="smallText">'.$gift['products_id'].'</td>
                               <td class="smallText">'.$gift['products_name'].'</td>
                               <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>
                               </tr></form>';
                       }

 

with

 

                        while ($gift = tep_db_fetch_array($gift_query)) {
                               echo '<form action="gift_add.php" method="GET"><tr>
                               <td class="smallText">$<input type="text" size="4" name="newthreshold" value="'.$gift['threshold'].'"></td>
              <td class="smallText">'.$gift['products_id'].'</td>
              <td class="smallText">'.$gift['products_name'].'</td>
              <input type="hidden" name="ID" value="'.$gift['products_id'].'">
              <input type="hidden" name="action" value="update">
              <td class="smallText">'.tep_image_submit('button_update.gif', IMAGE_BUTTON_SUBMIT).'</form>
                 <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>
                       </tr>';
                       }

 

ps, backup just in case, it works here and I'll update it in the morning since I've been up for 32 hours straight working on other stuff...

Share this post


Link to post
Share on other sites
I'm installing version 2.0.

In the readme, your instructions for changes in 'catalog/includes/classes/shopping_cart.php' (section 6):

I think you have forgotten a line to add, after the ''weight' => $products['products_weight'],'

should be 'carrot' => $products['products_carrot'], ???

 

apart from that, I didn't have time to go over the admin code, it still doesn't work...

Yep, you are correct. I copied and pasted the code incorrectly.

 

Jack

Share this post


Link to post
Share on other sites

hi ! I begun to modify the requested files for the Dangling Carrot 2.0 and I found that my files catalog/includes/shopping-cart.php does have the lines:

 

  $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_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 . "'");

 

between /* and */ ,

 

I suppose the code was modified from a contribution Credit Calls GV, but i'm not sure. The shop works, but

 

 

how will can i get the Dangling Carrot working if i cannot modify this file ?

 

Thank you for your help

 

sincerely

 

Roberto

Edited by busonero

Share this post


Link to post
Share on other sites

I just had a look at the out-commentated code.

 

it should come from:

 

Quantity Price Breaks Per Product

 

Quantity Price Breaks Per Product

 

Sincerely

Roberto

 

hi ! I begun to modify the requested files for the Dangling Carrot 2.0 and I found that my files catalog/includes/shopping-cart.php does  have the lines:

 

$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_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 . "'");

 

between /* and */ ,

 

I suppose the code was modified from a contribution Credit Calls GV, but i'm not sure. The shop works, but

how will can i get the Dangling Carrot working if i cannot modify this file ?

 

Thank you for your help

 

sincerely

 

Roberto

Share this post


Link to post
Share on other sites
hi ! I begun to modify the requested files for the Dangling Carrot 2.0 and I found that my files catalog/includes/shopping-cart.php does  have the lines:

between  /* and  */ ,

 

I suppose the code was modified from a contribution Credit Calls GV, but i'm not sure. The shop works, but

how will can i get the Dangling Carrot working if i cannot modify this file ?

 

Thank you for your help

 

sincerely

 

Roberto

I don't fully understand the question but if the instructions in this contributions is telling you to replace the existing code but you can't because it is part of another contribution, then you need to merge the two sections of code (in the case of a database call as you showed).

 

Jack

Share this post


Link to post
Share on other sites

I loaded all the scripts and updated the db. Now when I go into Admin to review any products I get the following errors:

 

 

Warning: reset(): Passed variable is not an array or object in /homepages/7/d115638055/htdocs/catalog/admin/includes/classes/object_info.php on line 17

 

Warning: Variable passed to each() is not an array or object in /homepages/7/d115638055/htdocs/catalog/admin/includes/classes/object_info.php on line 18

 

 

Please help :(

 

Installed to fresh install of OSC. Now I cannot update or edit any products. Even if I add a new product and then try to go back and see it same message

Share this post


Link to post
Share on other sites
I loaded all the scripts and updated the db. Now when I go into Admin to review any products I get the following errors:

Warning: reset(): Passed variable is not an array or object in /homepages/7/d115638055/htdocs/catalog/admin/includes/classes/object_info.php on line 17

 

Warning: Variable passed to each() is not an array or object in /homepages/7/d115638055/htdocs/catalog/admin/includes/classes/object_info.php on line 18

Please help :(

 

Installed to fresh install of OSC. Now I cannot update or edit any products. Even if I add a new product and then try to go back and see it same message

 

Resolved the issue by updating a new copy of categories.php in the admin folder

Share this post


Link to post
Share on other sites

I just installed this and have the same problem everyone else has. If the product is set to inactive it will not show up as a gift option. I have stock on it. It appears the fix is to just label it as gift only.... I am correct or is there something I am missing?

Share this post


Link to post
Share on other sites

open shopping_cart.php

 

in the query:

$gift_query = tep_db_query("SELECT fg.*, p.products_id, p.products_model, p.products_price, p.products_image, p.products_status, pd.products_name FROM free_gifts fg, products p

LEFT JOIN products_description pd ON (pd.products_id=fg.products_id)

WHERE pd.language_id = '".$languages_id."' AND p.products_id = fg.products_id AND p.products_status = '1' ORDER BY fg.threshold ASC");

 

remove this:

AND p.products_status = '1'

 

now you should be able to use gifts set as inactive items.

 

Kevin

Share this post


Link to post
Share on other sites

Hi Jack,

 

well, the instructions says I should replace the existing code but my code is not there anymore.

 

Actually I cannot merge anything , 'cause the code is commented out :-(

 

the Price Brake Contribution was installed nearly 1.5 vears ago, and everything works in the store even without this lines of code.

 

So I don't know how to proceed installing this contribution.

 

Thank you for your help

 

Sincerely

Roberto

 

 

 

I don't fully understand the question but if the instructions in this contributions is telling you to replace the existing code but you can't because it is part of another contribution, then you need to merge the two sections of code (in the case of a database call as you showed).

 

Jack

Share this post


Link to post
Share on other sites

That's a tough problem. You could try still replacing the code but un-comment it. I don't know the code in question and how it affects Price Break but as long as you make a backup, there shouldn't be a problem to do a quick test.

 

Jack

Share this post


Link to post
Share on other sites

I've just installed Dangling Carrot and the install seems fine but i left out a chunk of code. The reason being is that I'm using Master Products as well and Dangling Carrot asks me to replace a chuck of code that I already replaced using Master Products...

 

the instructions for Dangling Carrot says:

 

In admin/categories.php FIND (around line 289)

 

 } elseif ($HTTP_POST_VARS['copy_as'] == 'duplicate') {
? ? ? ? ? ?$product_query = tep_db_query("select products_quantity, products_model, products_image, products_price, products_date_available, products_weight, products_tax_class_id, manufacturers_id from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
? ? ? ? ? ?$product = tep_db_fetch_array($product_query);

? ? ? ? ? ?tep_db_query("insert into " . TABLE_PRODUCTS . " (products_quantity, products_model,products_image, products_price, products_date_added, products_date_available, products_weight, products_status, products_tax_class_id, manufacturers_id) values ('" . tep_db_input($product['products_quantity']) . "', '" . tep_db_input($product['products_model']) . "', '" . tep_db_input($product['products_image']) . "', '" . tep_db_input($product['products_price']) . "', ?now(), '" . tep_db_input($product['products_date_available']) . "', '" . tep_db_input($product['products_weight']) . "', '0', '" . (int)$product['products_tax_class_id'] . "', '" . (int)$product['manufacturers_id'] . "')");

REPLACE with 

? ? ? ? } elseif ($HTTP_POST_VARS['copy_as'] == 'duplicate') {
? ? ? ? ? ?//--BOF dangling carrot v2.0--
? ? ? ? ? ?$product_query = tep_db_query("select products_quantity, products_model, products_image, products_price, products_date_available, products_weight, products_carrot, products_tax_class_id, manufacturers_id from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
? ? ? ? ? ?$product = tep_db_fetch_array($product_query);

? ? ? ? ? ?tep_db_query("insert into " . TABLE_PRODUCTS . " (products_quantity, products_model,products_image, products_price, products_date_added, products_date_available, products_weight, products_status, products_carrot, products_tax_class_id, manufacturers_id) values ('" . tep_db_input($product['products_quantity']) . "', '" . tep_db_input($product['products_model']) . "', '" . tep_db_input($product['products_image']) . "', '" . tep_db_input($product['products_price']) . "', ?now(), '" . tep_db_input($product['products_date_available']) . "', '" . tep_db_input($product['products_weight']) . "', '0', '" . (int)$product['products_carrot'] . "', '" . (int)$product['products_tax_class_id'] . "', '" . (int)$product['manufacturers_id'] . "')");
? ? ? ? ? ?//--EOF dangling carrot v2.0--

 

 

the problem is Master Products had me replace that chuck of code with:

 

 ? ? ? ? ?} elseif ($HTTP_POST_VARS['copy_as'] == 'duplicate') {
// Master Products ? ? ? ? ? ?
? ? ? ? ? ?$product_query = tep_db_query("select products_quantity, products_model, products_image, products_price, products_date_available, products_weight, products_tax_class_id, manufacturers_id, products_master, products_master_status from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
? ? ? ? ? ?$product = tep_db_fetch_array($product_query);
? ? ? ? ? ?tep_db_query("insert into " . TABLE_PRODUCTS . " (products_quantity, products_model,products_image, products_price, products_date_added, products_date_available, products_weight, products_status, products_tax_class_id, manufacturers_id, products_master, products_master_status) values ('" . tep_db_input($product['products_quantity']) . "', '" . tep_db_input($product['products_model']) . "', '" . tep_db_input($product['products_image']) . "', '" . tep_db_input($product['products_price']) . "', ?now(), '" . tep_db_input($product['products_date_available']) . "', '" . tep_db_input($product['products_weight']) . "', '0', '" . (int)$product['products_tax_class_id'] . "', '" . (int)$product['manufacturers_id']. "', '" . $product['products_master']. "', '" .(int)$product['products_master_status'] . "')");
? ? ? ? ? ?$dup_products_id = tep_db_insert_id();
// Master Products EOF

 

 

Is there a way to combine the two so that they play nicely together?

Edited by Mediajuggle

My Contribution

Music Download Store Template

http://www.oscommerce.com/community/contributions,4275

Share this post


Link to post
Share on other sites
I've just installed Dangling Carrot and the install seems fine but i left out a chunk of code. The reason being is that I'm using Master Products as well and Dangling Carrot asks me to replace a chuck of code that I already replaced using Master Products...

? ? ? ? ? ?**SNIP**

Is there a way to combine the two so that they play nicely together?

 

Mediajuggle,

Try this (BACK UP FIRST)

 

 

  } elseif ($HTTP_POST_VARS['copy_as'] == 'duplicate') {
// Master Products            
          $product_query = tep_db_query("select products_quantity, products_model, products_image, products_price, products_date_available, products_weight, products_carrot, products_tax_class_id, manufacturers_id, products_master, products_master_status from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
          $product = tep_db_fetch_array($product_query);
          tep_db_query("insert into " . TABLE_PRODUCTS . " (products_quantity, products_model,products_image, products_price, products_date_added, products_date_available, products_weight, products_status, products_carrot, products_tax_class_id, manufacturers_id, products_master, products_master_status) values ('" . tep_db_input($product['products_quantity']) . "', '" . tep_db_input($product['products_model']) . "', '" . tep_db_input($product['products_image']) . "', '" . tep_db_input($product['products_price']) . "',  now(), '" . tep_db_input($product['products_date_available']) . "', '" . tep_db_input($product['products_weight']) . "', '0', '" . (int)$product['products_carrot'] . "', '" . (int)$product['products_tax_class_id'] . "', '" . (int)$product['manufacturers_id']. "', '" . $product['products_master']. "', '" .(int)$product['products_master_status'] . "')");
          $dup_products_id = tep_db_insert_id();
// Master Products EOF

 

Hope this helps! :)

 

Peace,

Erin

Share this post


Link to post
Share on other sites
made the modifications:

 

i made the modifications and got this error:

 

Hi Mediajuggle,

Sorry, about that! :(

 

I didn't get a notice of reply, just happened to check in.

Do you know what information is on line 382?

If you can post just the FEW lines before and after line 382, that may provide the answer.

 

Is it the code I just gave you, or is it another line?

 

If it is the code I gave you,

Are the first and last line beginning with //?

I believe the error is related to unexpected text in the code.

 

I don't think I will be back today, but if you post your reply, I will see what I can come up with. Mind you, I am not great at this stuff, but it is probably a VERY minor error.

 

Peace,

Erin

Share this post


Link to post
Share on other sites

Ok, I have installed this contrib which I think will be benificial to business! So THANK YOU!!!!!! Now what do I do with it? I mean how do I get the free items listed? Is it by making a new cat called gifts? And not showing the free items as active? I just completed the install with only 1 parse error which was because of another install and is now corrected. This is great!!! And I am a newbie too!

Share this post


Link to post
Share on other sites

Congratulations on the install. :) As far as using it, go into your admin section and click on a product to edit it. You will see a checkbox that says Product is Carrot. Checking that will make that product a gift item for this contribution. Then, go to the admin->catalog->gifts section. You will see the iproduct you just changed in the list. Add it and set its threshold. Then try placing an order to see if it shows up.

 

Jack

Share this post


Link to post
Share on other sites
Congratulations on the install. :) As far as using it, go into your admin section and click on a product to edit it. You will see a checkbox that says Product is Carrot. Checking that will make that product a gift item for this contribution. Then, go to the admin->catalog->gifts section. You will see the iproduct you just changed in the list. Add it and set its threshold. Then try placing an order to see if it shows up.

 

Jack

Wow, thanks. I am looking forward to usingf this contrib! This was pretty easy to install and Will test to see if I did it right :) LOL

Share this post


Link to post
Share on other sites

ok, major major problem.

 

I tried the admin fix above, which rendered my admin buttons useless, so have reverted to the install version of gift_add.php. The only problem is I cant edit or remove my carrot items - great except that i tested the system out and now have a product set at a ridiculously low price available on my site. Please help and point me in the right direction for a functional gift_add.php file ;)


Please note - if I have suggested a contrib above, it doesnt mean it will work! Most of the contribs are not ones I've used, but may be useful for your particular problem....

Have you tried a refined search? Chances are your problem has already been dealt with elsewhere on the forums.....

if (stumped == true) {

return(square_one($start_over)

} else {

$random_query = tep_fetch_answer($forum_query)

}

Share this post


Link to post
Share on other sites

Below is a fix for the Delete, Edit issue in the Admin section. We just needed to replace the "tep_image_submit" with "tep_image_button". I also removed the "Update" button as there was no code behind it. I figure if I want to update a threshold I'll just remove the gift and add it again.

 

OLD:

 

<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>

 

NEW:

 

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

 

 

Jack, thanks for a great contrib...

Share this post


Link to post
Share on other sites
Jack, thanks for a great contrib...

Thanks, but it's not mine. I just made some changes.

 

Jack

Share this post


Link to post
Share on other sites

Hello,

 

i have the MS1-Version of oscommerce. Can i use this Modul in my Version?

The shopping_card.php is not the same :-(

 

MfG

Andreas

Share this post


Link to post
Share on other sites

Hi :)

I am not sure my problem comes form this contrib but I am going to asI have added this contrib, only this many & the add a pic to shopping cart & invoice contrib. Now when a customers shops and goes to the cart to remove an item that option is not avail any more. Everything is out of line with the heading too.

https://www.2daysmarketplace.com/catalog/shopping_cart.php

does anyone have a clue? Thank you for your assistance in advance :)

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

×