I have a grouped product composed of simple products with custom options. I am displaying the custom options in a dropdown. The trouble I am having is that on submission of the form ("Add to Cart") the custom options are not being recognized. I have listed part of the form post below to illustrate. Will the add action handle this or do I need to write my own controller action to do this?
Form Post to ~/checkout/cart/add/
product:1182
selected_configurable_option:
related_product:
form_key:f1TDY3pWTMTYZUWC
options[865]:11558
super_group[628]:1
super_group[1281]:0
Any help is appreciated.
Best Answer
I did indeed figure this out. But is has been a while since I wrote it so my memory is a little foggy.
I created a new module with a new controller. I believe basically copied the Magento AddToCart controller and modified it.
My controller looks like this
Create the Route and Action in Magento routes.xml
sections.xml
I had to override the existing group product model and not really sure why. I basically just copied it over to my extension. I wont list it here because it is not really different but here is the DI config.
The final piece was to modify the add to cart functionality to use my new controller. I just did this in my theme. In my theme I added a grouped-product.js file under Magento_Catalog/web/js/
It probably would have been better to do the last part in the template rather then the client-side. But I seem to recall trying to modify the action particularly painful. Doing through JavaScript was pretty painless and fast.