X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   adding free items to cart (https://forum.x-cart.com/showthread.php?t=15066)

Tosin23 07-07-2005 07:02 PM

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

instinctual 07-07-2005 07:16 PM

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!

balinor 07-08-2005 05:26 AM

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

Nancy 08-24-2005 09:37 AM

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");
--
--

Dongan 08-24-2005 08:48 PM

Thanx for sharing.

QVS 08-18-2006 07:10 AM

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.

simonhelps 09-06-2006 06:19 AM

Re: adding free items to cart
 
Really appreciate some help on this one as well
Anyone!

wjbrewer 09-06-2006 06:43 AM

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.

wjbrewer 09-06-2006 06:45 AM

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.

simonhelps 09-06-2006 12:56 PM

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

wjbrewer 09-06-2006 10:21 PM

Re: Automatically adding free items
 
Quote:

Originally Posted by simonhelps
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.


Sorry, I don't have an easy solution for you on these. You will either have to dig into the cart functions, or have a custom mod that limits the quantity based on price, and delete all products when the cart has items but the total is 0.


All times are GMT -8. The time now is 11:37 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.