Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

adding free items to cart

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 07-07-2005, 07:02 PM
 
Tosin23 Tosin23 is offline
 

Member
  
Join Date: Jan 2005
Location: Atlanta, USA
Posts: 28
 

Default adding free items to cart

Hello,
I am offering free items in my store and I'd like these free items to be AUTOMATICALLY added to a customers shopping cart when they add ANY item to their shopping cart. i.e if a customer wants to buy a xbox game, i'd like the free xbox game that i'm offering to be added automatically to his/her shopping cart.

Does anyone has a code to help me do this?

I'd appreciate your help on this matter.

Thanks
__________________
Tosin : Using X-Cart Gold, Version 4.0.9
Reply With Quote
  #2  
Old 07-07-2005, 07:16 PM
 
instinctual instinctual is offline
 

eXpert
  
Join Date: Nov 2003
Posts: 247
 

Default exact code

I don't know the exact code to do it, but I would assume that on the detail page of the product, you could put some other hidden inputs so that you were adding the other product to the cart at the same time in the background.

That make sense? Poke around a bit on the detail product tpl - skin1/customer/main/product.tpl - and see if you can get some hidden inputs going in there.

Hope that helps!
__________________
Instinctual
8,000 feet up in the Rocky Mountains of Colorado
X-Cart Versions 3.5.x - 4.0.x

IF you xcart, THEN you prosper, ELSE you fail. ELSEIF xcart fails, THEN you fix it, all the WHILE {loop}\'ing {section}\'s to feed your $smarty mind.
Reply With Quote
  #3  
Old 07-08-2005, 05:26 AM
 
balinor balinor is offline
 

Veteran
  
Join Date: Oct 2003
Location: Connecticut, USA
Posts: 30,253
 

Default

Here is a nice mod that I used to solve this problem. Doesn't automatically add the item to the cart, but it still works well:

http://forum.x-cart.com/viewtopic.php?t=18380
__________________
Padraic Ryan
Ryan Design Studio
Professional E-Commerce Development
Reply With Quote
  #4  
Old 08-24-2005, 09:37 AM
 
Nancy Nancy is offline
 

Newbie
  
Join Date: Feb 2005
Posts: 1
 

Default Automatically adding free items

I had the same situation you had. I wanted to automatically add free items to each user's shopping cart. I am running version 4.0.12. Here is the reply I got from tech support. Hope it helps.

Please perform following steps :

1. Open '<xcart_root_dir>/cart.php' file.

2. Replace :

Code:
--- } elseif($from == 'partner' && $productid) { func_header_location($xcart_catalogs['customer']."/product.php?productid= ".$productid); } } # # DELETE PRODUCT FROM THE CART # ---
with

Code:
--- } elseif($from == 'partner' && $productid) { func_header_location($xcart_catalogs['customer']."/product.php?productid= ".$productid); } if ($productid<>%ID%) func_header_location($xcart_catalogs['customer']."/cart.php?mode=add&productid= %ID%&amount=1"); } # # DELETE PRODUCT FROM THE CART # ---
Just replace %ID% with the ID of 'free' product.
For example :

--
if ($productid<>16126)
func_header_location($xcart_catalogs['customer']."/cart.php?mode=add&productid= 16126&amount=1");
--
--
Reply With Quote
  #5  
Old 08-24-2005, 08:48 PM
  Dongan's Avatar 
Dongan Dongan is offline
 

X-Wizard
  
Join Date: Jul 2005
Location: www.mercuryminds.com
Posts: 1,531
 

Default

Thanx for sharing.
Reply With Quote
  #6  
Old 08-18-2006, 07:10 AM
 
QVS QVS is offline
 

Senior Member
  
Join Date: Nov 2004
Posts: 136
 

Default Re: Automatically adding free items

Quote:
Originally Posted by Nancy
I had the same situation you had. I wanted to automatically add free items to each user's shopping cart. I am running version 4.0.12. Here is the reply I got from tech support. Hope it helps.

Please perform following steps :

1. Open '<xcart_root_dir>/cart.php' file.

2. Replace :

Code:
--- } elseif($from == 'partner' && $productid) { func_header_location($xcart_catalogs['customer']."/product.php?productid= ".$productid); } } # # DELETE PRODUCT FROM THE CART # ---
with

Code:
--- } elseif($from == 'partner' && $productid) { func_header_location($xcart_catalogs['customer']."/product.php?productid= ".$productid); } if ($productid<>%ID%) func_header_location($xcart_catalogs['customer']."/cart.php?mode=add&productid= %ID%&amount=1"); } # # DELETE PRODUCT FROM THE CART # ---
Just replace %ID% with the ID of 'free' product.
For example :

--
if ($productid<>16126)
func_header_location($xcart_catalogs['customer']."/cart.php?mode=add&productid= 16126&amount=1");
--
--


Im trying to get this working on 4.0.14 and its not adding the item to the cart and causing the cart to freeze at points, does anyone know what the updated code would be for my version, thanks in advance.
__________________
xcart version 4.1.6
UK - Brighton

QVS ELECTRICAL SUPPLIES - http://www.qvsdirect.com

We supply a huge range of cables, electrical accessories, heating, ventilation, fire and security products, consumer units & circuit distribution, indoor and outdoor lighting, showers and water heating, tools and fixings, timer switches, sockets, switches, air conditioning, trunking, and much much more.
Reply With Quote
  #7  
Old 09-06-2006, 06:19 AM
 
simonhelps simonhelps is offline
 

Member
  
Join Date: Sep 2005
Location: Australia
Posts: 27
 

Default Re: adding free items to cart

Really appreciate some help on this one as well
Anyone!
__________________
x-cart 4.0.14 (unix)
Reply With Quote
  #8  
Old 09-06-2006, 06:43 AM
  wjbrewer's Avatar 
wjbrewer wjbrewer is offline
Banned
 

X-Adept
  
Join Date: Feb 2005
Location: Pittsburgh, PA
Posts: 504
 

Default Re: adding free items to cart

The above code will add the free product to every order. If you just want free products with other specific products use this:

PHP Code:
if ($productid == %ID%)
func_header_location($xcart_catalogs['customer']."/cart.php?mode=add&productid=%FREEID%&amount=1"); 

For example: If someone purchases productid 5 (and X-Box), it will automatically add productid=20 (a free game).

The bad thing about this code is that you will have to add these lines for every product that you want to have a freebee with. A better way would be to add a field to the database called free_products and then check for every added product is there is a freebee. But this way will work.
Reply With Quote
  #9  
Old 09-06-2006, 06:45 AM
  wjbrewer's Avatar 
wjbrewer wjbrewer is offline
Banned
 

X-Adept
  
Join Date: Feb 2005
Location: Pittsburgh, PA
Posts: 504
 

Default Re: Automatically adding free items

Quote:
Originally Posted by QVS
Im trying to get this working on 4.0.14 and its not adding the item to the cart and causing the cart to freeze at points, does anyone know what the updated code would be for my version, thanks in advance.

You need to remove the space before the product number.
Reply With Quote
  #10  
Old 09-06-2006, 12:56 PM
 
simonhelps simonhelps is offline
 

Member
  
Join Date: Sep 2005
Location: Australia
Posts: 27
 

Default Re: Automatically adding free items

Quote:
Originally Posted by wjbrewer
You need to remove the space before the product number.

Quote:
if ($productid<>%ID%)
func_header_location($xcart_catalogs['customer']."/cart.php?mode=add&productid=%ID%&amount=1");
}

Bill - I cannot thank you enough for solving that one for us!

Just 2 questions:-

The most important one is how can you limit the free product qty to 1 item only regardless of how many products are put in the cart (the code above adds a free item every time a product is added but our store is giving a free gift per order made not per product.

Is there code that could be added that checks that the cart has a product in it (other then the free one). At the moment if someone puts a product in the cart the code above adds the free item (or whatever item specified) to the cart, but if the original item is then deleted from the cart , this free item remains there. Is there a bit of code that can check for this? As it is the item I am specifing is a free item and the cart will not allow a checkout with a subtotal of $0.00 but if this code was straight forward it would be nice.

Many thanks
Simon
__________________
x-cart 4.0.14 (unix)
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 08:20 AM.

   

 
X-Cart forums © 2001-2020