Page 1 of 1

Only one item in the cart

Posted: Sun Mar 06, 2011 12:48 am
by dim565
Hello. Sorry if I ask the last time too many questions. If someone can help - I will be grateful.
I want to be when you click add to cart on the page caterogy.tpl (a href="<?php echo $products[$j]['add']; ?>">) - the goods are not added to the basket to the existing elements and do not add the quantity of the previously added item.

ie that the basket was always one (last added) goods.

it is possible?

Re: Only one item in the cart

Posted: Thu Apr 28, 2011 9:19 pm
by Qphoria
So you always want 1 item only for each item?

1. EDIT: system/library/cart.php

2. FIND:

Code: Select all

$this->session->data['cart'][$key] += (int)$qty;
3. REPLACE WITH:

Code: Select all

$this->session->data['cart'][$key] = (int)$qty;

Re: Only one item in the cart

Posted: Thu Apr 28, 2011 9:48 pm
by dim565
Thank you for trying to help, unfortunately this is not what I need
I want to delete function that when you add a product to the cart and there is already another product, then the new product is added to the old.

Instead, I need to make an old product is replaced by a new one. In other words, the buyer could buy for 1 time only one product (but in any quantity)

Re: Only one item in the cart

Posted: Fri Apr 29, 2011 8:34 pm
by dim565
Please write at least where the code. which adds an item to Cart. But I really would grateful if someone writes a ready solution

Re: Only one item in the cart

Posted: Fri Apr 29, 2011 8:39 pm
by Qphoria
So you want ONLY 1 type of product in the cart at one time and if another is added it deletes the existing products and replaces with the new one?

1. EDIT: system/library/cart.php

2a. FIND (1.4.x):

Code: Select all

if (!$options) {
2b. FIND (1.5.x):

Code: Select all

if (!$option) {
3. BEFORE, ADD:

Code: Select all

$this->clear();

Re: Only one item in the cart

Posted: Fri Apr 29, 2011 9:04 pm
by dim565
Yes! This is what I wanted! I did not think so simple, but without your help I would not do!
Qphoria, Thank you very much! :)

Re: Only one item in the cart

Posted: Fri Jun 15, 2012 2:18 am
by onlinephilately
Q your first answer helped me a lot. thx!

Now, would it be possible to have this function (only allow one item per product) for all products except products with certain Manufacturer ID's?

Re: Only one item in the cart

Posted: Fri Jan 10, 2014 11:18 pm
by utgJ
Qphoria, would you mind letting me know how to achieve this on Opencart 1.5.6? Would be much appreciated if you could, thanks.

Re: Only one item in the cart

Posted: Sat Nov 15, 2014 1:29 am
by brandd
I tried this in OpenCart 1.5.6 but it does not work
Can you please help us
Would be much appreciated
Thanks

Re: Only one item in the cart

Posted: Sat Jun 01, 2019 7:10 pm
by soundslider
Hi all , please help me , how can i used this on Opencart 2.3 ?