Cart Maximum Qty Values

Ask the community for help and support.
Post Reply
mhsuffolk
VIP Member
VIP Member
Posts: 54
Joined: Sat Oct 26, 2019 9:13 am
Location: Ipswich UK
Has thanked: 5 times
Been thanked: 4 times

Cart Maximum Qty Values

Post by mhsuffolk »

Phoenix 1.0.5.0 PHP 7.3

I have the Maximum Values in Configuration for "Product Quantities In Shopping Cart" set to 1 as 99.99% of my customers buy many different DVDs but just 1 of each but sometimes revisit an item that is in the cart already, click Add to Cart again and inadvertently buy 2 copies.

However I would like the Qty Up/Down arrows to still function in the cart to cater for the very occasional customer who is buying a second copy for a friend etc. The maximum Values setting reverts any Qty changes back to 1

Is this achievable please?

Martin
Live shop Phoenix 1.0.7.0 on PHP 7.4 Test Shop under construction 1.0.8.0 on PHP 7.4
burt
Lead Developer
Lead Developer
Posts: 1182
Joined: Tue Oct 29, 2019 9:37 am
Has thanked: 14 times
Been thanked: 31 times

Re: Cart Maximum Qty Values

Post by burt »

I don't think you'll be able to have that as you are pulling in two directions in that tug of war;

pull to the right: limit buy ability to one
pull to the left: allow to buy more than one

Maybe the best way would be to have some type of message that says

"you have already bought this DVD"

That would only work for logged in customers though.
Open Source is like a recipe — if you don’t like how it tastes, add your own ingredients and share that new improved recipe with the world. HPDL 2021
ecartz
Lead Developer
Lead Developer
Posts: 1149
Joined: Tue Nov 05, 2019 6:02 pm
Has thanked: 4 times
Been thanked: 119 times

Re: Cart Maximum Qty Values

Post by ecartz »

1. Get rid of the maximum quantity setting (or make it high enough to cover the rare cases).
2. Override the add_product action.

Replace

Code: Select all

        $qty = (!empty($_POST['qty'])) ? (int)$_POST['qty'] : 1;

        $_SESSION['cart']->add_cart($_POST['products_id'], $_SESSION['cart']->get_quantity(tep_get_uprid($pid, $attributes))+$qty, $attributes);
with

Code: Select all

        $_SESSION['cart']->add_cart($_POST['products_id'], max(1, $_SESSION['cart']->get_quantity(tep_get_uprid($pid, $attributes))), $attributes);
The max is just to make sure that if there are already two items in the cart, you don't reduce the number when reaching the cart. Possibly add more logic to change the message when this happens (you already have this in your cart; if you really want to update the quantity, please do so on the cart page). Make a similar change to buy_now if desired. Do not change update_product, which is what is used from the cart page.

I believe that this will give the behavior that you describe or close to it.
mhsuffolk
VIP Member
VIP Member
Posts: 54
Joined: Sat Oct 26, 2019 9:13 am
Location: Ipswich UK
Has thanked: 5 times
Been thanked: 4 times

Re: Cart Maximum Qty Values

Post by mhsuffolk »

Thank you for the replies, I will have a play later today and report back
Live shop Phoenix 1.0.7.0 on PHP 7.4 Test Shop under construction 1.0.8.0 on PHP 7.4
mhsuffolk
VIP Member
VIP Member
Posts: 54
Joined: Sat Oct 26, 2019 9:13 am
Location: Ipswich UK
Has thanked: 5 times
Been thanked: 4 times

Re: Cart Maximum Qty Values

Post by mhsuffolk »

Sad to say I cannot get it to work.
It does not break anything but the behaviour does not change.
Live shop Phoenix 1.0.7.0 on PHP 7.4 Test Shop under construction 1.0.8.0 on PHP 7.4
Post Reply