How to get Product.
I am adding my code here...
<?php
/**
* Webkul Hello CustomPrice Observer
*
* @category Webkul
* @package Webkul_Hello
* @author Webkul Software Private Limited
*
*/
namespace Deep\Module\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\App\RequestInterface;
class CustomPrice implements ObserverInterface
{
public function execute(\Magento\Framework\Event\Observer $observer) {
$item = $observer->getEvent()->getData('quote_item');
$price1 = $item->getPrice();
$product = $item->getProduct();
if (null !== $product->getCustomAttribute('deep_sample_price')) {
$price = 5; //set your price here
$item->setCustomPrice($price);
$item->setOriginalCustomPrice($price);
$item->getProduct()->setIsSuperMode(true);
}
else if(null == $product->getCustomAttribute('deep_sample_price')){
echo $product->getCustomAttribute('deep_sample_price')->getValue();
}
}
}