how can I add multiple items to a cart from a served string that provides the product ids and their quantities? I suppose a rule could handle this somehow?
I'm trying to make some bigger changes to the add-to-cart form and the way it functions, for my client and I have specific needs here.
Usually the form only let's you add one type of product variation at a time, but I want visitors to be able to set multiple product variations of the same product node, and the 'Submit' button submits all of them, instead of just the currently selected variation.
To put this into perspective: Let's say I have a product (display node) called
This Brick holds three variations:
- Brick (Front) , Brick (Side) , Brick (Top)
Using a Custom Line Item, it gets these options added automatically (taxonomy term list reference):
- Red , Green , Blue
Here, we want users to be able to (for example) click Side and select Green, then hit Front and choose Red, and when they hit Submit, both of these get added to their cart. By default however, of course only one - the last selection - is added.
Now, using a
I can easily print the JS Object into the DOM as a string with a format such as
For example the string could read
31:2:1_32:3:1 (which for humans would read Side:Green:1, Front:Red:1).
From hereon, though, I dont really know how to progress. My idea would be to perhaps create a custom rule that (replacing the action of the default Submit button) receives that string, filters it and adds matching items to the cart.
Really hope someone here has an idea on how I could progress. Any suggestion and recommendation would be highly appreciated!