I have write module for set custom price of product when adding to cart but my code not working.
namespace Navin\Testcart\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\App\RequestInterface;
class CustomPrice implements ObserverInterface
{
public function invoke(\Magento\Framework\Event\Observer $observer) {
//echo "test";exit();
$item=$observer->getEvent()->getData('quote_item');
$product=$observer->getEvent()->getData('product');
$item = ( $item->getParentItem() ? $item->getParentItem() : $item );
// Load the custom price
$price = $product->getPrice()+10; // 10 is custom price. It will increase in product price.
// Set the custom price
$item->setCustomPrice($price);
$item->setOriginalCustomPrice($price);
// Enable super mode on the product.
$item->getProduct()->setIsSuperMode(true);
}
}
Help for resolve my issue.