Hi, I have configurable product with customizable option "custom width" and I need to read this value in Observer for event 'checkout_cart_product_add_after'. Observer class:
use Magento\Framework\Event\ObserverInterface;
use Magento\Catalog\Model\Product\Type\Configurable;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Serialize\Serializer\Serialize;
class FooClass implements ObserverInterface
{
public function execute(\Magento\Framework\Event\Observer $observer)
{
//$serializer = ObjectManager::getInstance()->get(Serialize::class);
$item = $observer->getEvent()->getData('quote_item');
$item = ($item->getParentItem() ? $item->getParentItem() : $item);
// get 'custom width'
// logic for changing custom price depends of option 'custom width'
// $customPrice = ...............
$item->setCustomPrice($customPrice);
$item->setOriginalCustomPrice($customPrice);
$item->getProduct()->setIsSuperMode(true);
}
}
Solved! Go to Solution.
you can use the below code to get all options for quote item
$item->getProductOptions()
if that returns null then you can use the below code
$item->getProduct()->getTypeInstance(true)->getOrderOptions($item->getProduct());
you can use the below code to get all options for quote item
$item->getProductOptions()
if that returns null then you can use the below code
$item->getProduct()->getTypeInstance(true)->getOrderOptions($item->getProduct());
Thank you!
@antoniogur615a kindly accept as a solution if this works for you!