I try to set special prices for some customers / products. The new prices are calculated in a module. But how can I display these prices in list and view mode?
In 1.9. I could use an Observer. Tried the same in 2.1., but without success:
event name="prepare_catalog_product_collection_prices"
Observer:
use Magento\Framework\Event\ObserverInterface;
use Magento\Catalog\Model\Product;
use Magento\Customer\Model\Session as CustomerModelSession;
use Magento\Framework\Event\Observer as EventObserver;
class Discount implements ObserverInterface
{
/**
* @var CustomerModelSession
*/
protected $customerSession;
public function __construct(
CustomerModelSession $customerSession
) {
$this->customerSession = $customerSession;
}
public function execute(\Magento\Framework\Event\Observer $observer)
{
if ($this->customerSession->isLoggedIn()) {
$collection = $observer->getEvent()->getCollection();
$cId = $this->customerSession->getCustomerId();
foreach ($collection as $product) {
$finalPrice = min($product->getData('final_price'), $this->getmyPrice( $product,$cId));
$_product->setMinimalPrice($finalPrice)
->setPrice($finalPrice)
->setFinalPrice($finalPrice);
}
return $this;
}
return $this;
}
public function getmyPrice($product,$cid)
{
$price=2;
return price;
}
}
Any help / hint very welcome!!