Question

I want individual add to cart buttons for grouped products but keep the original add to cart button so that multiple products can be added to cart if needs be with a single click. This was fine without ajax as I did not need forms. Nested forms are not valid however worked perfectly for everything except the first grouped product so am trying to find an alternative.

I thought i could add a button for each product that will include the ID and then modify the controller for add to cart server side to detect this button was clicked and modify the array of IDs down to just the item which add to cart button was clicked with a plugin before the add to cart execute function or something along these lines.

I have only tested this with ajax add to cart however want a second button which will change functionality and so added below button:

<button type="submit" name="singleadd" value="<?= $_item->getId() ?>">Add</button>

The above however whether and input or button, when submitted the singleadd paramater is not available using $this->getRequest()->getParam('singleadd') or $_POST['singleadd'] to get the value. I believe I should be able to do this and am wondering why not.

Is this the way the ajax add to carts are working that are just not sending the submit type elements?

Was it helpful?

Solution

Button names are not submitted via POST.
you should add a hidden input with the value you need and that one will get submitted.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top