Jump to content
Latest News: (loading..)
thejungle

Dangling Carrot (Free Gift/Discount Contrib)

Recommended Posts

Install the database changes using the free_gifts.sql file.

 

I'm sorry for asking such a simple question, but do I have to enter all of that information manually, or is there a method of just importing it into the database?

Share this post


Link to post
Share on other sites

I was having issues with the Dangling Carrot add-on and the SPPC add-on working together in that I could not prevent Wholesalers (or any other group), from picking up the free gift.

 

I think I have fixed it by playing around with the SPPC_Customer_Group_id.

 

If you have these two contribs installed, try the following in \catalog\shopping_cart.php.

 

Around the beginning of the file you'll see:

 

//BOF //////////////////////// dangling carrot v2.0 //////////////////////////////////

 

if ($cart->count_contents() > 0){

// find any free gifts, and remove invalid ones

$num_in_cart = $cart->show_total();

$products = $cart->get_products();

 

Change this to:

 

//BOF //////////////////////// dangling carrot v2.0 //////////////////////////////////

if ($_SESSION['sppc_customer_group_id'] < '1') { // this is the variable you'll need to play with to make it work for you...

if ($cart->count_contents() > 0){

// find any free gifts, and remove invalid ones

$num_in_cart = $cart->show_total();

$products = $cart->get_products();

 

As a note, if you also have PWA installed this should also work as your 'guest' account will not have a group id.

 

If you have two groups that you wish to be able to receive the gift, simply make sure that the 2nd group are have a group id of 1 and then change the new line to: if ($_SESSION['sppc_customer_group_id'] < '2') {

 

Hope this helps.

 

Cheers,

 

stu


A crash reduces your expensive computer to a simple stone.

Share this post


Link to post
Share on other sites

Hi...can anyone tell me how to resize product images in the Gifts box please ... I want them to be the same size as all other images, like in the Specials box etc.

 

Thanks in advance :D

Share this post


Link to post
Share on other sites

Hi

 

I have installed this great contribution but am having a minor problem with my shopping cart box, due to another mod. The shopping cart box in column_right has the ability to change quantity but obviously I would like to prevent that happening for carrots.

 

Could someone help me with this code for catalog/includes/boxes/shopping cart.php

 

 

Many Thanks

 

Simon

 

<?php
/*
 $Id: (advanced) shopping_cart.php,v 1.1 2005/08/31 beer monster Exp $

 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com

 Copyright (c) 2003 osCommerce

 Released under the GNU General Public License
*/
 require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_SHOPPING_CART);
?>
<!-- shopping_cart //-->
<script type="text/javascript" src="includes/boxes/rollovers.js"></script>
<script type="text/javascript">
<!--
function decrement(index) {
if(document.forms["cart_box"].elements["cart_quantity[]"][index].value >1) {
  document.forms["cart_box"].elements["cart_quantity[]"][index].value--;
  document.cart_box.submit();
}
}

function increment(index) {
  document.forms["cart_box"].elements["cart_quantity[]"][index].value++;
  document.cart_box.submit();
}

function mark(pid) {
  document.forms["remove_product"].elements["cart_delete[]"][0].value=pid;
  document.forms["remove_product"].elements["products_id[]"][0].value=pid;
  document.remove_product.submit();
}

var sURL = document.URL.toString();
if (sURL.indexOf("?") > 0){
urlsplitter = '';
} else {
urlsplitter = '?';
}
document.write('<form ');
document.write(' name="remove_product" ');
document.write(' action="' + document.URL + urlsplitter + '&action=update_product"');
document.write(' method="post">');
//one element is not an array so add 2 of each!
document.write('<input type="hidden" name="products_id[]">');
document.write('<input type="hidden" name="cart_delete[]">');
document.write('<input type="hidden" name="products_id[]">');
document.write('<input type="hidden" name="cart_delete[]">');
document.write('</form>');

document.write('<form ');
document.write(' name="cart_box" ');
document.write(' action="' + document.URL + urlsplitter + '&action=update_product"');
document.write(' method="post">');
  //-->
</script>

<body onLoad="MM_preloadImages('images/btn-up.gif','images/btn-dn.gif','images/btn-up-ov.gif', 'images/btn-dn-ov.gif')"></body>
<tr id="colright">
 <td id="shopcartbox">
<?php
 $info_box_contents = array();
 $info_box_contents[] = array('text' => BOX_HEADING_SHOPPING_CART);
 new infoBoxHeading($info_box_contents, true, true, tep_href_link(FILENAME_SHOPPING_CART));

 if ($cart->count_contents() > 0) {
$info_box_contents = array();
$any_out_of_stock = 0;
$products = $cart->get_products();
for ($i=0, $n=sizeof($products); $i<$n; $i++) {
// Push all attributes information in an array
  if (isset($products[$i]['attributes']) && is_array($products[$i]['attributes'])) {
	while (list($option, $value) = each($products[$i]['attributes'])) {
	  echo tep_draw_hidden_field('id[' . $products[$i]['id'] . '][' . $option . ']', $value);
	  $attributes = tep_db_query("select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix
								  from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa
								  where pa.products_id = '" . $products[$i]['id'] . "'
								   and pa.options_id = '" . $option . "'
								   and pa.options_id = popt.products_options_id
								   and pa.options_values_id = '" . $value . "'
								   and pa.options_values_id = poval.products_options_values_id
								   and popt.language_id = '" . $languages_id . "'
								   and poval.language_id = '" . $languages_id . "'");
	  $attributes_values = tep_db_fetch_array($attributes);

	  $products[$i][$option]['products_options_name'] = $attributes_values['products_options_name'];
	  $products[$i][$option]['options_values_id'] = $value;
	  $products[$i][$option]['products_options_values_name'] = $attributes_values['products_options_values_name'];
	  $products[$i][$option]['options_values_price'] = $attributes_values['options_values_price'];
	  $products[$i][$option]['price_prefix'] = $attributes_values['price_prefix'];
	}
  }
}

//Build the infobox...
for ($i=0, $n=sizeof($products); $i<$n; $i++) {

  $cur_row = sizeof($info_box_contents);

 if ((tep_session_is_registered('new_products_id_in_cart')) && ($new_products_id_in_cart == $products[$i]['id'])) {
   $style_text = '<span class="newItemInCart">';
 } else {
   $style_text ='<span class="infoBoxContents">';
 }

//Product Details First...
  $products_name = '  <tr>' .
 // uncomment this line to get micro thumbnails!					 '	 <td><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products[$i]['id']) . '">' . tep_image(DIR_WS_IMAGES . $products[$i]['image'], $products[$i]['name'], '30') . ' </a></td>' .
				   '	<td colspan="4" class="infoBoxContents" valign="top"> <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products[$i]['id']) . '">'  . $style_text . $products[$i]['name'] . '</span></a>';

//--Add any attributes...
  if (isset($products[$i]['attributes']) && is_array($products[$i]['attributes'])) {
	reset($products[$i]['attributes']);
	while (list($option, $value) = each($products[$i]['attributes'])) {

	  $products_name .= '<br><small><i> - ' . $products[$i][$option]['products_options_name'] . ' ' . $products[$i][$option]['products_options_values_name'] . '</i></small>';
	}
  }

  $products_name .= '	</td>' .
					'  </tr>';


//Now build the Quantity form...
  //--Make sure we have a form array...one element is not an array and
  //--javascript doesn't like elements with [] so add some extra fields if there is only one product in the cart!
  if (sizeof($products)==1){
	 $j =$i+1;
	 $extra_elements = tep_draw_hidden_field('cart_quantity[]', $products[$i]['quantity']) . tep_draw_hidden_field('products_id[]', $products[$i]['id']);
  } else {
	 $j =$i;
	 $extra_elements = '';
  }

  $products_form ='	<tr>' .
				 '	  <td>Qty </td>' .
				 '	  <td> ' . $extra_elements . tep_draw_input_field('cart_quantity[]', $products[$i]['quantity'], 'class="quantitybox"') . tep_draw_hidden_field('products_id[]', $products[$i]['id']) . '</td>' .
				 '	  <td><a href="java script:void(increment('. $j . '));" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'document.up' . $i . '\',\'document.up' . $i . '\',\'images/btn-up-ov.gif\')" ><img name="up' . $i . '" src="images/btn-up.gif" border="0" width=21 height=11></a><br><a href="java script:void(decrement('. $j . '));" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'document.dn' . $i . '\',\'document.dn' . $i . '\',\'images/btn-dn-ov.gif\')" ><img name="dn' . $i . '" src="images/btn-dn.gif" border="0" width=21 height=11></td>' .
				 '	  <td width="100%" align="right"><b>' . $currencies->display_price($products[$i]['final_price'], tep_get_tax_rate($products[$i]['tax_class_id']), $products[$i]['quantity']) . '</b></td>' .
				 '	</tr>'.
				 '	<tr><td colspan="5" align="right" width="100%" class="infoBoxContents"><a href="java script:void(mark(\'' . $products[$i]['id'] . '\'));"><span class="removeProduct">' . TABLE_HEADING_REMOVE . ' <img src="images/remove.gif" border="0" height="8" width="8"> </span></a></td></tr>' .
				 '	<tr><td colspan="5" width="100%">' . tep_draw_separator('pixel_silver.gif') . '</td></tr>';

  $cart_contents .= $products_name . $products_form;
}

//Finally, add the total...
//--If we are already at the checkout, don't show the checkout button!
  if (preg_match("/checkout/", $PHP_SELF)) {
 $co_link = '';
  } else {
 $co_link = '<a href="' . tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL') . '">' . tep_image_button('button_checkout_small.gif', IMAGE_BUTTON_CHECKOUT) . '</a>';
  }

  $total = '  <tr height="20">' .
		   '	<td colspan="3" align"left">' . $co_link . '</td>' .
		   '	<td colspan="1" align="right" width="100%" class="infoBoxContents"><b>' . $currencies->format($cart->show_total()) . '</b></td>' .
		   '  </tr>';

  $cart_contents .= $total;

 $info_box_contents = array();
 $info_box_contents[] = array('text' => $cart_contents);

 new cartBox($info_box_contents);

 } else {
 new infoBox(array(array('text' => BOX_SHOPPING_CART_EMPTY)));
 }
?>
</form>
 </tr>
</td>
<!-- shopping_cart_eof //-->

Share this post


Link to post
Share on other sites

Hi all, great contribution and I installed without problems.

I can not seem to accomplish 3 things though.

My shoppingcart page is ssl secured, but when adding a free gift the page returns to http.

I would like to know how to edit the link to prevent this from happening.

The code to edit is probably this one:

	$freebie[$p]['link'] = '<a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=, SSL' . $gift['products_id']) . '">' . tep_image_button('button_add_now.gif', 'Select Freebie/Special' . $gift['products_id'] ) . '</a>';

 

Secondly, I've included the box in specials.php but failed to change the produclisting. I use the product listing in even columns contrib. Also the images for the carrots are not the SMALL IMAGE WIDTH/HEIGHT that is set for thumbnails.

Does anyone have any solutions to these "issues"?

Share this post


Link to post
Share on other sites
I have just completed installing this mod to our site and I noticed that the user is able to change the quantity of the FREE gift and receive more?(or think they will). Also what if you want the user to be able to choose between several gifts?

 

thanks for any help

 

P.S. - other than these two concerns this is a very great mod:)

Same issue here. Any progress made?

Share this post


Link to post
Share on other sites

Ok, So to get the right size thumbnails in the gifts box, I needed to use GIFTS_IMAGE_WIDTH/HEIGHT instead of SMALL_IMAGE_WIDTH/HEIGHT.

Still did not manage to get the listing in columns though.

Share this post


Link to post
Share on other sites

I looked at the new_products box and managed to get the productlisting in columns.

Just borrow the code from that module and the gift box will list like that.

Share this post


Link to post
Share on other sites

Hi,

 

I just installed the Dangling Carrot mod and sofar it looks very nice and seems to be doing what I was looking for. I just noticed some minor problems with the mod. The biggest one is that the gift does not appear on the invoice. It appears in the shopping cart, but after payment is finalized, it's gone. A smaller issue is that when the quantity is changed in the shopping cart, the "dangling carrot" or near limit message does not appear if the amount goes below the threshold. A page refresh or a second click on update solves this, but of course would be nicer if this would not be necessary.

 

Any suggestions how to solve the above?

 

Thanks,

Richard

Share this post


Link to post
Share on other sites
Same issue here. Any progress made?

 

Guy, did you modify includes/classes/shoppingcart.php. If yYou don't change the get_shopping list function this qty box will appear. I noticed that in teh last version there is a wrong shoppping cart classes file. Here is the instruction to edit:

 

catalog/includes/classes/shopping_cart.php

 

FIND:

 

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

 

REPLACE it with

 

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

 

--------------------------------------------------------

 

[NOTE: in my 2.2 MS2 file this line is already there. Check for it.]

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'],

 

ADD after it:

 

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

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

Share this post


Link to post
Share on other sites

ahah! Thanks Hans.

 

I just came looking here as I was having the same problem as many of you - the quantity box still appearing for carrots. I'd used the classes/shopping_cart.php that came with the package but it was missing the line

 

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

 

thanks!


bugrit! millenium hand and shrimp - I told 'em!

Share this post


Link to post
Share on other sites

Hi - me again!

 

I'm finding a weird bug with this. If I duplicate a product then set the duplicate as the carrot, it adds the original products_id to the free_gifts table instead of the new one, which means all the references to it don't work properly.

 

any ideas?


bugrit! millenium hand and shrimp - I told 'em!

Share this post


Link to post
Share on other sites

I wanted all of my items to be available for purchase so I created 'new' items in the Top level of my categories. Meaning, anything created in 'Top' won't be visible for purchase in the website but the 'real' listing will still be searchable and available for purchase. I also employed all of the other fixes in the contrib to keep carrot items out of What's New, etc. Everything is great.

 

My problem is this: Let's say I created 10 new items as carrots in the Top level. But, I've only added 3 of them to appear beneath one's shopping cart available as freebies once they reach a certain price threshold.

 

I want to use the Gifts box in the left column on my product pages. But, if I turn that on....the box is displaying all 10 items that have been created as carrots and not just displaying the 3 that are 'active' underneath the shopping cart.

 

How can I make the Gifts infobox display only the 3 that are active and stop picking up every single carrot item created?

 

Really nice contrib, by the way. I had to mess a bit in order to make the items in the Gifts box unclickable, but other than that...I'm glad I installed it. It's been a boost to my bank account already.

 

Andrea

Share this post


Link to post
Share on other sites

Well...seeing as I've had no replies I had to go about this the hard way. LOL.

 

I'm now creating carrot items with a quantity of zero. And when I choose to add them to the carrot 'list' of freebies to be displayed underneath my shopping cart, I simply change the quantity to 1 or greater and add them.

 

In order for all carrot items created to not be displayed in the Gifts infobox, it was all I could do. But, I had to change the query within catalog/includes/boxes/gifts.php in order for this to work. Basically, I just added a small line that checks for quantity before display. Any carrot items with zero or less in stock will not show. In that file I mentioned, I changed this:

 

// retreive the gifts  
 $gift_list_query = tep_db_query("SELECT p.products_id, p.products_image, p.products_status, p.products_carrot, 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 p.products_status = '1' AND p.products_carrot = '1' ORDER BY pd.products_name ASC");

if (tep_db_num_rows($gift_list_query)) {

 

To read like this:

 

// retreive the gifts  
 $gift_list_query = tep_db_query("SELECT p.products_id, p.products_image, p.products_status, p.products_carrot, 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 p.products_status = '1' AND p.products_carrot = '1' AND p.products_quantity > 0 ORDER BY pd.products_name ASC");

if (tep_db_num_rows($gift_list_query)) {

 

All I added was that line of AND p.products_quantity > 0 to the existing file.

 

If anyone else is wrestling with it, I feel well about having posted again. :) It really is a nice contrib.

 

Andrea

Share this post


Link to post
Share on other sites
Hi - me again!

 

I'm finding a weird bug with this. If I duplicate a product then set the duplicate as the carrot, it adds the original products_id to the free_gifts table instead of the new one, which means all the references to it don't work properly.

 

any ideas?

 

I noticed this too, fixed it and posted the fix on the contribution page.


Most Valuable OsCommerce Contributions:

Also Purchased (AP) Preselection (cuts this resource hogging query down to nothing) -- Contribution 3294

FedEx Automated Labels -- Contribution 2244

RMA Returns system -- Contribution 1136

Sort Products By Dropdown -- Contribution 4312

Ultimate SEO URLs -- Contribution 2823

Credit Class & Gift Voucher -- Contribution 282

Cross-Sell -- Contribution 5347

Share this post


Link to post
Share on other sites

Hi, :blush:

 

I've a problem after Dangling Carrot V2.6a installation; I thought it was a problem due to some other

modifications made on this website then I start from a brent new standard Osc v2.2 (french edition but...it works normally!)

The problem is:

in the Admin-->Catalog I find a new line and a new window for gifts.

the threshold box is there but the pull-down box with TEXT_Add is very narrow with nothing in?!

I should normally find the Categories products, shouldn't I?!

The new values have been included in the Database (file in the package) and some products have a price reduced to 0

(I don't know if it's necessary? but I did it!)

Thanks for any help and any explanation : how should this contribution normally works and administrated? ;)

 

Have a nice Sunday! :rolleyes:

 

Stef


OSC V2.2 RC1 WC FR V3

Installed addons: More Pics 6V2 / XSell 2_6 / Dynamic Site Map V4.0.1 with Update SSL / FCK HTML Editor / Admin Order Sort /

Export Order / Dynamic Force Attribute / GV & DC RC1 V1.2 / Free Amount / and much more in the future...

Share this post


Link to post
Share on other sites

Hi, :rolleyes:

 

back with a fresh installation on an Osc base site: the Admin is working fine (it's seems to be!)

but the problem now is that nothing happends for any "add to cart" selection... :(

Any idee about that?!

 

Enjoy your monday... B)

 

Stef


OSC V2.2 RC1 WC FR V3

Installed addons: More Pics 6V2 / XSell 2_6 / Dynamic Site Map V4.0.1 with Update SSL / FCK HTML Editor / Admin Order Sort /

Export Order / Dynamic Force Attribute / GV & DC RC1 V1.2 / Free Amount / and much more in the future...

Share this post


Link to post
Share on other sites

Hi, :blush:

 

last for today !

No more problem to buy a product, then the gift is added automaticaly; any idea to add something like that:

from 0 to 30$ gift1

from30 to 70$ gift2

for more than 100$ gift 3

and maybe to live the choise between two different gifts in the range of buing ?

 

Thanks for any idea :)

Stef


OSC V2.2 RC1 WC FR V3

Installed addons: More Pics 6V2 / XSell 2_6 / Dynamic Site Map V4.0.1 with Update SSL / FCK HTML Editor / Admin Order Sort /

Export Order / Dynamic Force Attribute / GV & DC RC1 V1.2 / Free Amount / and much more in the future...

Share this post


Link to post
Share on other sites

Hi, :blush:

 

I'm back and have now a Dangling Carrot contrib which works fine...

No other glitch until now! B)

The last was a mistake in \catalog\shopping_cart.php file.

 

Sheers :D

 

Stef


OSC V2.2 RC1 WC FR V3

Installed addons: More Pics 6V2 / XSell 2_6 / Dynamic Site Map V4.0.1 with Update SSL / FCK HTML Editor / Admin Order Sort /

Export Order / Dynamic Force Attribute / GV & DC RC1 V1.2 / Free Amount / and much more in the future...

Share this post


Link to post
Share on other sites

I have one problem with contribution.

 

Always show 0.00EUR in:

 

By spending over 0.00EUR you have qualified for the following gift!

 

Spend just 0.00EUR more to get ...

 

it must would show something that.

 

By spending over 60.00EUR you have qualified for the following gift!

 

Spend just 13.50EUR more to get ...

 

can somebody help me?

 

thanks

Share this post


Link to post
Share on other sites

I think is one mistake in sql because always I call prices and threshold I give 0...

 

example

 

define('TEXT_FREE_GIFT', 'Free gift with $' . $currencies->display_price($product_gift['threshold'], $product_gift['threshold'], tep_get_tax_rate($product_gift['products_tax_class_id'])) . ' purchase.');

define('TEXT_DISCOUNT_GIFT', 'Only ' . $currencies->display_price($product_gift['threshold'], $gift['products_price'], tep_get_tax_rate($gift['products_tax_class_id'])) . ' with $' . $product_gift['threshold'] . ' purchase.');

 

 

I give 0.00 too

 

but I run sql:

 

CREATE TABLE `free_gifts` (
 `gift_id` tinyint(4) NOT NULL auto_increment,
 `threshold` mediumint(9) NOT NULL default '0',
 `products_id` mediumint(9) NOT NULL default '0',
 PRIMARY KEY  (`gift_id`)
) TYPE=MyISAM;

insert into configuration (configuration_id, configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, last_modified, date_added, use_function, set_function) values (1200, 'Gifts Image Width', 'GIFTS_IMAGE_WIDTH', '90', 'The pixel width of heading images', '4', '25', now(), now(), NULL, NULL);
insert into configuration (configuration_id, configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, last_modified, date_added, use_function, set_function) values (1201, 'Gifts Image Height', 'GIFTS_IMAGE_HEIGHT', '100', 'The pixel height of heading images', '4', '26', now(), now(), NULL, NULL);
UPDATE configuration_group SET sort_order=last_insert_id() WHERE configuration_group_id=last_insert_id();

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

 

and it looks work fine

 

please, help me

Share this post


Link to post
Share on other sites
Solved...

 

It works with changes at languages version 2.6b... not 2.7

 

 

Hello,

 

Got the same problem. Could you please write what you exactly did?

Share this post


Link to post
Share on other sites

I can't find it now... either remember it

 

but knowing mistakes compare two version with "beyond compare" or similiar... and when you watch something diferent about languages... there is the bug

 

If you cant find it so i will try it another time

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

×