2

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?

  • add the full ajax code to the question. – Sukumar Gorai Jul 4 '18 at 8:57
  • Im just using default grouped product ajax not quite sure where it is to be honest – harri Jul 4 '18 at 8:57
  • You can create hidden input. – Sukumar Gorai Jul 4 '18 at 8:58
  • This hidden input will always be sent no matter which button is pressed. Button names are not sent via post no, but values should be and only are sent if clicked so allows me to determine which button was pressed? – harri Jul 4 '18 at 9:02
1

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

  • But then that will be submitted no matter which button i press? – harri Jul 4 '18 at 8:58
  • Sorry think i need to explain that I want multiple submit buttons on the form to change functionality so only a single product added when each indicidual add to cart button is pressed. Button values however should be submitted by post like so: stackoverflow.com/questions/547821/… – harri Jul 4 '18 at 9:01
  • 1
    you can also add an 'onclick' event on the buttons to change the value of the hidden input to the value corresponding to your button. Also, the link you mentioned uses input instead of button. – Marius Jul 4 '18 at 9:12
  • Thanks Yeah i was thinking this may be my next best option i will go ahead with that. Yeah i tried inputs too, submit type ones dont send. There are many answers on that thread many use buttons however seems like normal behaviour say for a form with update or delete button for example. See answer by kiril – harri Jul 4 '18 at 9:14
  • Bit of jquery trickery will do the trick thanks for your time Marius – harri Jul 4 '18 at 10:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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