Knowing that all other actions besides update-cart has been deprecated I'm curious what needs to be passed with the action to remove a line item from the cart using a button as opposed to check a checkbox > update cart (essentially removing a click for the user). The same would apply for +/- buttons/inputs for adding/removing from quantity.

I see in the example templates there's a checkbox input with name="lineItems[{{ item.id }}][remove]". Is it as simple as changing the input to a submit (or button submit) using the same name tag contents? Would this then also carry over to be posted via ajax in the same way as an update-cart action?

That's a long question. Trying to wrap my head around the changes as I'm just getting into Craft 3 and Commerce 2...

up vote 1 down vote accepted

Is it as simple as changing the input to a submit (or button submit) using the same name tag contents?

Yes.

Would this then also carry over to be posted via ajax in the same way as an update-cart action?

Yes.

Everything can be done on a single line item basis to the update-cart acton, just use the new param names.

  • Should have just tested before asking, but was away. Anyway... I know multiple submits in a form is a little iffy in older browsers, however as long as the name is different it certainly works across modern browsers. How would one go about wrapping each remove submit within one ajax function? Javascript is typically where I trip up in spaghetti with these types of things. I essentially want to keep the update cart submit for discount codes and so on, but have each individual remove (or +/- to change quantity) to go through the same form and ideally the same ajax function. 🤯 – Anders Jul 26 at 2:33

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.