Solved

How can I restrict basket to one item type only?

lecker_bierchen
Visitor
1 0 0

Hi. I plan a strange setup for selling virtual goods. With my current setup I am not able to split different product types in my order processing. I plan to do a MVP and do not want to spent to much resources in it.

 

Is there a way to only allow one item (but in higher quantities) in the basket. So I add 5 times item A. When I add item B I get an error message "Please finish the order for every item separate".

Accepted Solution (1)

JoesIdeas
Shopify Expert
2222 202 592

This is an accepted solution.

Ya, the way I would approach it is with javascript + the Shopify ajax api.

1) Set an event listener on your add to cart button so that when someone clicks on it, before adding to cart it checks to see how many line items are in the cart.

2) If there are > 0 line items in the cart, check to see if the line item in the cart is the same as the product you're adding (so they can add more quantity any time).

3) If > 0 line items and the line item in cart does not match the one on the product page, then show an error message instead of adding the product to cart.

Here's the documentation: https://shopify.dev/docs/themes/ajax-api. You'll want to use GET cart.js specifically for this project: https://shopify.dev/docs/themes/ajax-api/reference/cart#get-cart-js

If you need help from a developer feel free to reach out to my team at speedboostr.com/contact. We do customizations like this all the time.

• Creator of Order Automator (automate tagging, fulfillment, Amazon, notifications + more)
• Shopify developer for 10+ years, store owner for 7 years
• I also make guides like Shopify Automation Tips and How to Deal with Fraud / Chargebacks

View solution in original post

Reply 1 (1)

JoesIdeas
Shopify Expert
2222 202 592

This is an accepted solution.

Ya, the way I would approach it is with javascript + the Shopify ajax api.

1) Set an event listener on your add to cart button so that when someone clicks on it, before adding to cart it checks to see how many line items are in the cart.

2) If there are > 0 line items in the cart, check to see if the line item in the cart is the same as the product you're adding (so they can add more quantity any time).

3) If > 0 line items and the line item in cart does not match the one on the product page, then show an error message instead of adding the product to cart.

Here's the documentation: https://shopify.dev/docs/themes/ajax-api. You'll want to use GET cart.js specifically for this project: https://shopify.dev/docs/themes/ajax-api/reference/cart#get-cart-js

If you need help from a developer feel free to reach out to my team at speedboostr.com/contact. We do customizations like this all the time.

• Creator of Order Automator (automate tagging, fulfillment, Amazon, notifications + more)
• Shopify developer for 10+ years, store owner for 7 years
• I also make guides like Shopify Automation Tips and How to Deal with Fraud / Chargebacks