Hi, I am trying to create an online store where the client is given a choice of around fourteen items, they can buy as many as they like, but only four items at a time per box, but as many boxes as they wish.
So I hoping to put up an image of each item where the client can click the image, add to cart, etc, etc, etc but after four clicks, the cart if full and they can either checkout, or start another cart ?
I have tried Wix support, but they say it cannot be done, so would be obliged if anyone has come across this problem before?
Thanks in advance
Hi,
I was able to find a similar question with an answer than is relevant to your question here . In GOS’s response, he mentions the use of the getCurrentCart() function. This function will be able to return information about the current cart. Since the number of items is one of the pieces of information that is returned from this function, you should be able to write some code that accomplishes the functionality that you are trying to create. You can also take a look at the addToCart function here .
If you feel like you cannot make this alone, please consider hiring a Wix Partner to help you build your site.
Hope this helps!
Edward | Corvid Team
I was looking for a similar limitation, like this post: [https://www.wix.com/velo/forum/coding-with-velo/wix-store-limit-quantity-of-a-product](post:
https://www.wix.com/velo/forum/coding-with-velo/wix-store-limit-quantity-of-a-product
But)
But I can’t find a solution for it. So I made a code in “masterPage.js” that always change the quantity of itens if this one is bigger than you want.
import {cart} from 'wix-stores';
$w.onReady(function() {
cart.onChange((changedCart) => {
const cartLineItems = changedCart.lineItems;
var limit = 1;
for (var i = 0; i < cartLineItems.length; i++) {
if (changedCart.lineItems[i].quantity > limit) {
cart.updateLineItemQuantity(changedCart.lineItems[i].id, limit)
}
}
});
})
You can determine witch product it is applicable, just make a verification by product id. Of course it isn’t the best way to do it, but until the Velo Team resolve it, this code can help.
what does this mean and which number should i change to set the cart limit???
Thank you- this was a copy-and-paste solution for the issue I was facing where I was trying to limit quantity of any product a customer can buy to one.