I see some answers about set custom price in product when add to cart.
But, I can't still solve my issue. I used observer for that to set custom price.
But, it's not working.
Can anyone please help me to solve it?
My code :
public function execute(\Magento\Framework\Event\Observer $observer) {
$item = $observer->getEvent()->getData('quote_item');
$product = $observer->getEvent()->getData('product');
$itemProId = $item->getProduct()->getId();
$custom_price = $product->getPrice() + 10;
$item->setCustomPrice($custom_price);
$item->setOriginalCustomPrice($custom_price);
$item->getProduct()->setIsSuperMode(true);
}
Best Answer
You doesn't return anything in your observer code. So, it's not update product price.
Make sure that you use checkout_cart_product_add_after event.
=> events.xml :
=> CustomPriceCartAddAfter.php (Observer File) :
Add return $this object at the end of your code inside