How to get selected simple product Id on checkout_card_add_after observer in magento2?
Question
I want to get selected associated product information from configurable product after an checkout_cart_add_after triggered. I'll look after it in mean time,if any helps would be appreciable.
Solution
Add below code in your observer file
$item = $observer->getQuoteItem();
$product = $item->getProduct();
$typeId = $product->getTypeId();
if ($typeId == \Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE) {
$attributes = $product->getTypeInstance()->getSelectedAttributesInfo($product);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange