Forum

Thread tagged as: Question, Shop

Notifying User That Maximum Cart Qty Has Been Reached

Would the best way to notify the user that max_in_cart has been reached be to loop over each cart item, and then call perch_shop_products on each product and test against the value of the max_in_cart ID? Then display a message if true.

Toby Martin

Toby Martin 1 points

  • 4 years ago

Actually that's not going to work is it. The cart qty will never exceed max_in_cart so the test will always fail.

Duncan Revell

Duncan Revell 78 points
Registered Developer

I think you use max_in_cart when the customer is trying to add a product to the cart - either warn they have selected too many for that product or only allow them to select up to that amount.

Yes that's right but you don't just want to limit it on the cart page and not notify that user what has happened and/or why. ie "You have reached the maximum allowed in the cart for product x"

Duncan Revell

Duncan Revell 78 points
Registered Developer

Would the product description not include "maximum number per order" in the text?

Perhaps, but:

  1. You're relying on the client to add that content (never a good idea)
  2. Not everyone reads the description

I think it's a bad user experience to place limitations on something but not providing the user with any feedback.

Duncan Revell

Duncan Revell 78 points
Registered Developer

In that case you could possibly pass something to the cart using a cart_property - and use that value to display some text in the cart.

Yeah that is an option but the issue is testing if max_in_cart has been exceeded.

Duncan Revell

Duncan Revell 78 points
Registered Developer

Toby Martin said:

Yes that's right but you don't just want to limit it on the cart page and not notify that user what has happened and/or why. ie "You have reached the maximum allowed in the cart for product x"

When buying the product, if quantity = max_in_cart, use cart_property to pass some text to the cart. I'm still not sure how the customer is able to exceed max_in_cart.

Technically they can exceed it, Perch then handles reducing the number of items in the cart back down to the maximum allowed. A better way of wording it would be to test if a user has attempted to exceed max_in_cart.

if quantity === max_in_cart, use cart_property

This wouldn't work because I need to test if the quantity exceeds max_in_cart, but Perch performs the logic and takes the necessary actions on the cart before I can run my test.

I guess an alternative would be to create our own max_in_cart field and then test against that before the cart is loaded. Then reduce the number of items in the cart programmatically if it's been exceeded. But this seems a bit like reinventing the wheel to just show the user a message.

For a bit of context:

A user has added a product to the basket of qty 1. They then go to the cart page and change the qty to 6 but that product has max_cart_qty of 5. So when they then update the cart, Perch reduces it back down to 5 but there is no indication to the user why that's just happened.

Duncan Revell

Duncan Revell 78 points
Registered Developer

For each cartitem in the cart, max_in_cart is passed in (you won't need a cart_property) - edit the <perch:input for the Qty column to include

<perch:input id="qty:<perch:cartitem id="identifier" />" value="<perch:cartitem id="quantity" />" type="number" min="0" max="<perch:cartitem id="max_in_cart" />" />

Then the customer won't be able to add more to the cart than is allowed?

Yep that's not a bad idea but there's still no indication to the user as to why.

I'm thinking unless Drew can offer a solution then I may take this route and also dynamically display a note on the cart (and product) page next to the qty field about the maximum allowed, using <perch:cartitem id="max_in_cart" />.

Appreciate the effort Duncan.

Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

If you use max="<perch:cartitem id="max_in_cart" />" like Duncan suggested, you can use Javascript to display a note when appropriate. Proof of concept