# Dangling Carrot (Free Gift/Discount Contrib)

## Recommended Posts

In a nutshell, you have already answered your own question "I noticed that on Chris' site, www.session1.com, there are add to cart buttons next to the gift items."

Yes there should ;)

Thanks Reesy

Looking at his website, I couldn't be sure that it was not something he customized or not.

If they are supposed to be there, well, I don't have'em showing up! :huh:

When you go to the cart contents page on my shop, the offers show up as expected; however, there are no add to cart buttons showing.

Where is the code that puts adds the buttons? I think I did everything correctly.

Note: I am using the contrib that shows the estimated shipping costs under the cart contents. Most likely, this is causing a problem.

Any and all clues greatly appreciated. I want to get this one to work, for it is an EXCELLENT contrib. :thumbsup:

Best Regards, Ted

##### Share on other sites

Hi all,

I've got a question, which I think will need to be answered by someone with a bit of coding know-how.

I have been using Dangling Carrot for some time now. It works great!

One of my vendors seems to have a problem with me giving away free gifts with the sale of his products (trying to eliminate massive competition between vendors). The products happen to be the most expensive thing in my shop. So here's my question...

Is there anyway to add a piece of code that will tell the shopping cart that if the total is above a certain amount that there should be NO gifts offered (instead of showing every gift that qualifies under the price threshold)? So, basically, an "if" clause that states if the ot_total > x don't offer free gifts. Or, better yet, instead of creating levels to cross (price threshold) how about ranges? So, if the ot_total is between \$50-\$100... offer these gifts. If the ot_total is between \$100 - \$200... offer those gifts (not including the ones from \$50 - \$100). Is that possible?

In order to not show gifts for the expensive stuff I have to get rid of the Dangling Carrot all together (which is what I am trying to avoid) because the higher purchase total will include all gifts from all thresholds under it.

Hopefully this makes sense to someone. I believe it is an easy piece of code, I just don't know how to do it myself. Any help will much appreciated.

Thanks!!

##### Share on other sites

Hello,

I have just finished installing the Dangling Carrot Contribution. I have been using SPPC and Price break for SPPC. I have tried to merge the coding but am having some problems now :(

I have managed to get the gifts box on the admin screen but with limited functionality as seen on the screenshot.

catalog/includes/classes/shopping_cart.php is causing me a problem too, the SPPC has commented out some code which Dangling Carrot needs.

This code starts on line 281, the first line as you can see has been commented out right through to the bottom of this code.

```/*		\$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 . "'");
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'");
if (tep_db_num_rows(\$specials_query)) {
\$specials = tep_db_fetch_array(\$specials_query);
\$products_price = \$specials['specials_new_products_price'];
} */```

I have tried taking out the comments so the code is live but I keep receiving the same error message

Parse error: parse error, unexpected ';', expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/gloveclu/public_html/includes/classes/shopping_cart.php on line 392

It is the same line that needs to be replaced by this code from the installation instructions.

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

Since it stops my site from working for the time being I have put the comments back on.

Would really appreciate it if someone could assist me with this.

Kind regards

M Parmar

##### Share on other sites

Does anyone know how to modify this so a customer can add more then one gift?

Not several pcs of the same gift, but one of each gift.

##### Share on other sites

Great contrib Jack - thanks for your work on this :)

Everything is working fine. I have noticed though that customers can not add the product to their cart though, when viewing the product through the catalogue. Is this right or have I gone wrong somewhere?

I see from reading this thread that I can remove the product from the catalogue *but* was wondering if there was a way of making this function as a normal product as well as a gift item?

TIA

Kino

Edited by kinomuto

##### Share on other sites

:P :blush: Solved.

I am using BTS. I needed to put the button_add_now.gif in my templates/Original/images/buttons/english/ directory.

All works fine now.

Also, in answer to the latest question about having a product available in the catalog and also as a carrot, I suggest you use the Bundled Products contrib by the same author. You can keep the original item in the catalog and create a bundled product with the same item for the carrot. The bundled product-carrot only showing up when gift threshold is met.

Best, Ted

Thanks Reesy

Looking at his website, I couldn't be sure that it was not something he customized or not.

If they are supposed to be there, well, I don't have'em showing up! :huh:

When you go to the cart contents page on my shop, the offers show up as expected; however, there are no add to cart buttons showing.

Where is the code that puts adds the buttons? I think I did everything correctly.

Note: I am using the contrib that shows the estimated shipping costs under the cart contents. Most likely, this is causing a problem.

Any and all clues greatly appreciated. I want to get this one to work, for it is an EXCELLENT contrib. :thumbsup:

Best Regards, Ted

There is a new contribution called Impulse Item Impulse Item that may do what many are looking to do.

I think what many of us want to do is offer special items only at checkout.

Dangling Carrot would be the best solution for doing this; however, we need to be able to control whether or not the customer can add just one gift or many. WE NEED THIS FLEXIBILITY. ;)

I have not had time to find a way to allow more than one item, but would rather rely on someone with more know-how.

Best Regards, Ted

##### Share on other sites

Hi guys. I'm relatively new to OSc, but have successfully installed the software along with CCGV and Dangling Carrot.

My only issue with Dangling Carrot is that I cannot create duplicate products since finishing the install. When I select 'copy to' and 'duplicate product', I get the following error:

1062 - Duplicate entry '0-39' for key 1

insert into products_to_categories (products_id, categories_id) values ('0', '39')

[TEP STOP]

I checked the db and the products are being put in the db, but with a products_date_available of 0000-00-00 00:00:00 (the others all have Null).

I can muddle through code, but I'm no expert...and I'm relatively new to mysql. Any help would be greatly appreciated.

##### Share on other sites

Done some more playing...

apparently the duplicate products are being created, they just aren't being assigned to any category and don't show up in the admin panel. They do show up under the manufacturer in the catalog, but not in the category they were supposed to be copied to.

##### Share on other sites

Has anyone seen the following problem?

After adding a gift to the cart and then later adding another product, if you then update the quantity of the item that is listed after the gift - the quantity does not update for that product?

##### Share on other sites
Hi guys. I'm relatively new to OSc, but have successfully installed the software along with CCGV and Dangling Carrot.

My only issue with Dangling Carrot is that I cannot create duplicate products since finishing the install. When I select 'copy to' and 'duplicate product', I get the following error:

QUOTE

1062 - Duplicate entry '0-39' for key 1

insert into products_to_categories (products_id, categories_id) values ('0', '39')

[TEP STOP]

I checked the db and the products are being put in the db, but with a products_date_available of 0000-00-00 00:00:00 (the others all have Null).

I can muddle through code, but I'm no expert...and I'm relatively new to mysql. Any help would be greatly appreciated.

David - I had exactly the same problem which I've just solved. In my case, the code in admin/categories.php that adds the duplicate product to the database was repeated (the original code was there, followed by more or less the same code for the Header Tags mod that is also installed).

Just check that you have no duplicate code.

Hope that helps,

Ali.

##### Share on other sites

No dup code....here's the part that I think is messing things up:

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

\$description_query = tep_db_query("select language_id, products_name, products_description, products_url from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . (int)\$products_id . "'");

while (\$description = tep_db_fetch_array(\$description_query)) {

tep_db_query("insert into " . TABLE_PRODUCTS_DESCRIPTION . " (products_id, language_id, products_name, products_description, products_url, products_viewed) values ('" . (int)\$dup_products_id . "', '" . (int)\$description['language_id'] . "', '" . tep_db_input(\$description['products_name']) . "', '" . tep_db_input(\$description['products_description']) . "', '" . tep_db_input(\$description['products_url']) . "', '0')");

}

tep_db_query("insert into " . TABLE_PRODUCTS_TO_CATEGORIES . " (products_id, categories_id) values ('" . (int)\$dup_products_id . "', '" . (int)\$categories_id . "')");

\$products_id = \$dup_products_id;

But I don't know enough to see anything wrong in there....

##### Share on other sites
Has anyone seen the following problem?

After adding a gift to the cart and then later adding another product, if you then update the quantity of the item that is listed after the gift - the quantity does not update for that product?

Yes I just noticed this after reading your comment. I will look at the code and try to get this resolved.

##### Share on other sites
Has anyone seen the following problem?

After adding a gift to the cart and then later adding another product, if you then update the quantity of the item that is listed after the gift - the quantity does not update for that product?

OK...I seem to have fixed the issue. For the instructions pertaining to the changes in catalog/shopping_cart.php around line 228:

Find:

```//<!--BOF dangling carrot v2.0-->

if (\$products[\$i]['carrot'] == "1"){
\$info_box_contents[\$cur_row][] = array('align' => 'center',
'params' => 'class="productListing-data" valign="top"',
'text' => \$products[\$i]['quantity']. tep_draw_hidden_field('products_id[]', \$products[\$i]['id']));
}```

and Change to:

```	  if (\$products[\$i]['carrot'] == "1"){
\$info_box_contents[\$cur_row][] = array('align' => 'center',
'params' => 'class="productListing-data" valign="top"',
'text' => \$products[\$i]['quantity'] .

tep_draw_hidden_field('cart_quantity[]', \$products[\$i]['quantity']) . tep_draw_hidden_field('products_id[]',

\$products[\$i]['id']));
}```

Notice the 2 tep_draw_hidden_field calls in the new version.

If someone can test the full functionality of the shopping cart and post back on this thread, we can then release a new version with this fix.

##### Share on other sites
If someone can test the full functionality of the shopping cart and post back on this thread, we can then release a new version with this fix.

Looks good so far - thanks. :)

##### Share on other sites

I just fixed the issue of duplicate products not being placed in the admin panel.

This line: \$dup_products_id = tep_db_insert_id();

was deleted when the 'Find around line 289' change was made. If you're having this problem, insert the above line under the Dangling Carrot code for entering a duplicate item. In the code quoted in post 161, it goes after the //--EOF Dangling Carrot v2.0-- line.

Edited by otgrouch

##### Share on other sites

Anyone been able to get this contribution working alongside SPPC and Price break for SPPC (seperate pricing per customer) ?

My OScommerce is quite heavily modified and my last attempt to install this contrib was a failure :'(

Regards

M Parmar

##### Share on other sites

Ive installed this mod with no problems at all. Everything works OK apart from one thing.

When testing the mod I seem to be able to add more than one free item, I can also change the quantity of a free item in the the basket.

Im not too worried about the quantity thing but is there a way to stop more than one free item being added to the basket?

Ive installed version 2a

edit: I should make my problem clearer.....

After I add the free item the list of free gifts is still listed below the basket, but if I click on the image, allowing me to go into the product description page, and click add to cart the free item can be placed in the cart a second time.

Edited by rikpotts

##### Share on other sites

rikpotts - any luck with changing this? it's not horrible but it's a little wierd. any help would be great! :)

Ive installed this mod with no problems at all. Everything works OK apart from one thing.

When testing the mod I seem to be able to add more than one free item, I can also change the quantity of a free item in the the basket.

Im not too worried about the quantity thing but is there a way to stop more than one free item being added to the basket?

Ive installed version 2a

edit: I should make my problem clearer.....

After I add the free item the list of free gifts is still listed below the basket, but if I click on the image, allowing me to go into the product description page, and click add to cart the free item can be placed in the cart a second time.

##### Share on other sites

In catalog/includes/classes/shopping_cart.php

FIND (around line 282)

\$products_array[] = array('id' => \$products_id,

'name' => \$products['products_name'],

'model' => \$products['products_model'],

'image' => \$products['products_image'],

'price' => \$products_price,

'quantity' => \$this->contents[\$products_id]['qty'],

'weight' => \$products['products_weight'],

'carrot' => \$products['products_carrot'],

##### Share on other sites

oneill,

'carrot' => \$products['products_carrot'],

in catalog/includes/classes/shopping_cart.php apply?

all,

there was some talk in this forum about a new version around nov2005.

the current version listed in contribs is 2.1, dated 25aug2005.

I want to confirm this is the lastest release.

I think there may be a clue in removing the check for

while leaving the check

"does the quantity of the gift item = 1"

I will keep note of this as I install as I would like to offer multiple incremental gifts as well.

Toward Continued Success - - > Carol Hawkey - - > KidsLearnToSew.com - - > Wyoming, USA

Mods Installed - - > Authnet AIM2 - Bundled Products 1.4 - Fancier Invoice 6.1 - Email_HTML_Order_Link_Fixed - Header Tags Controller - Login aLa Amazon - JustOneAttribute - Article Manager - SPPC w/PB - spiders.txt - Dangling Carrot/Olive - Printable Catalog - CCGV(trad)

Planned Mods - - > Purchase Without Account - USPS Label - Ultimate SEO

##### Share on other sites

I went ahead and installed Dangling Carrot and had it working, but it does not suit my needs. So I started working on an update, mostly to handle downloads and multiple gifts in cart, but I seem to be getting nowhere fast. Lots of pieces doing something, but not what they are supposed to. I need more joy! Turns out that the finished "upgrade" will really be a new mod that can exist along with Dangling Carrots.

I really want to be able to offer some nice gifts to my customers when their order reaches a certain level, and not be limited to offering only one as it is in Dangling Carrot, which has some other limitations as well (no downloads as gifts). I've been at this all day every day for the last week and I'm pretty sure I'm just tilting at windmills now. hack, upload, no joy. hack, upload, no joy. ad infinitum.

So I'm asking for help to develop this mod from someone who's been around osC long enough to know the interactions between files, and if a thingy is changed here it will also need changed there. Also needs to understand attributes and their little 1{2}3 system. Also preferrably one who has their own store modded with SPPC w/PB, but who would also be able to adjust the code for stock _if_ this turns into a contribution.

I do not want to turn it over to a developer who will "just do it" as that won't help me learn how & why thingys work & don't work. I can "code" (depending on your definition) if I know what code is supposed to go where and why and how it interacts. And I 'm a good install instruction writer. Will you help bring all these pieces I've been working on into a working whole?

I have the following in my bribe sharing bag: money, cookies, pizza, appreciation. cap-feathers.

<cross posted to "support - dangling carrots" and "contribution development">

Toward Continued Success - - > Carol Hawkey - - > KidsLearnToSew.com - - > Wyoming, USA

Mods Installed - - > Authnet AIM2 - Bundled Products 1.4 - Fancier Invoice 6.1 - Email_HTML_Order_Link_Fixed - Header Tags Controller - Login aLa Amazon - JustOneAttribute - Article Manager - SPPC w/PB - spiders.txt - Dangling Carrot/Olive - Printable Catalog - CCGV(trad)

Planned Mods - - > Purchase Without Account - USPS Label - Ultimate SEO

##### Share on other sites

Hi there.

Great contribution...thanks to all responsible.

Could somebody tell me where I change the text colour, and the background of the box where the free gifts show up, along with the add to cart button?

Are they controlled by the stylesheet?

At the moment I have white text on a white background! (Not very effective I'm sure you'll all agree)

Also....

how do I move the box displaying the free gifts up a little?

At the moment in my shopping cart, if the customer is only buying one item the following occurs.

The item is shown, along with its price and along the bottom is the bar with the buttons, update cart, checkout etc. Unless they actually scroll down the page, they will not know that the free gifts exist!

Isit possible to display the free gifts box above the 'checkout' button?

Regards,

Claire

##### Share on other sites

After installing this mod per instructions, I had to make the following change in /catalog/shopping_cart.php to get this to work for "out of stock" or inactive products.

Find this:

```	\$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 " . TABLE_CARROT . " fg, " . TABLE_PRODUCTS . " p
LEFT JOIN " . TABLE_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");```

and change to this

```	\$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 " . TABLE_CARROT . " fg, " . TABLE_PRODUCTS . " p
LEFT JOIN " . TABLE_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 = '0' ORDER BY fg.threshold ASC");```

Just change p.products_status = '1' to p.products_status = '0' in the where clause.

Brian Christensen

##### Share on other sites

i need to chage the bgcolor of the "just spend" box where it shows which gift you will get if you spent more.

where do i change it. it has a white #ffffff color and it doesnt show the text since my store is dark and all the text is white.

Thanks

p.s. maybe u can help me with this one also.

i have a bg picture in the index beneath the text thrue the css like this :

TD.main, P.main {

font-family: Verdana, Arial, sans-serif;

background-image:url(indexbg.jpg); background-repeat:no-repeat; background-position: center;

font-size: 11px;

line-height: 1.5;

}

the problem is that the image is showing up beneath the back button on the product info page.

i want it to be shown only under the index text and the description of all prods is it possible ?

##### Share on other sites

ras,

in catalog/shopping_cart.php look for:

```	<td class="smallText" bgcolor="#FFFFFF">

replace with:

```	<td class="smallText">

i also have a question:

is it possible to have the gift product added automatically to the customer's cart once they've reached the threshold?

due to my current search engine friendly url's, the buy now button doesn't seem to work.

Edited by eww