- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2020
02:22 AM
10-16-2020
02:22 AM
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.
Labels:
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2020
04:18 AM
10-22-2020
04:18 AM
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());
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2020
04:18 AM
10-22-2020
04:18 AM
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());
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2020
02:15 AM
10-28-2020
02:15 AM
Re: How to get item customizable option in Observer?
Thank you!
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2020
11:31 PM
11-01-2020
11:31 PM
Re: How to get item customizable option in Observer?
@antoniogur615a kindly accept as a solution if this works for you!