Magento 2: Set Product final price using catalog_product_get_final_price Event
-
22-03-2021 - |
문제
Using event catalog_product_get_final_price, setting the maximum price to be 100, if the price of a product is greater than 100 then it will set automatically to 100 and the product price is below 100 then it will be displayed that price. But that event is not working. Below is the code.
Ahmad/MarketingPrice/etc/frontend/events.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="catalog_product_get_final_price">
<observer name="marketing-rule" instance="Ahmad\MarketingPrice\Observer\ProcessFinalPriceObserver" />
</event>
</config>
Ahmad/MarketingPrice/Observer/ProcessFinalPriceObserver.php
<?php
namespace Ahmad\MarketingPrice\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\Event\Observer as EventObserver;
class ProcessFinalPriceObserver implements ObserverInterface
{
public function execute(\Magento\Framework\Event\Observer $observer)
{
echo "test123";
$product = $observer->getEvent()->getProduct();
$pId = $product->getId();
$storeId = $product->getStoreId();
$finalPrice = 100;
$product->setPrice($finalPrice);
$product->setFinalPrice($finalPrice); // set final price here
return $this;
}
}
올바른 솔루션이 없습니다
제휴하지 않습니다 magento.stackexchange