I want to get selected associated product id after an checkout_cart_add_after triggered. If any helps would be appreciable.
I will be speaking for Magento 2.2.6
There is an event dispatch like this
$this->_eventManager->dispatch( 'checkout_cart_product_add_after', ['quote_item' => $result, 'product' => $product] ;
addProduct method of the
$result variable that is dispatched, and will be available to you if you were to listen to the
checkout_cart_product_add_after event, is actually of type
\Magento\Quote\Model\Quote\Item, i.e. this is the item that is added to the quote.
In this screenshot you will see all relevant data that you need. For example, in the
_data array there is the
product_type which in my example is
configurable, but in the
sku, this is the sku of the actual simple product that I have chosen.
And don't worry, here it will have the appropriate data if you need to extract data from a grouped or a bundle product. It is simply there, and this is what you should utilize.
So, the event again is
checkout_cart_product_add_after, and you should be able to collect the data from the
Observer $observer in your
I hope this helps.