0

etc/di.xml

<preference for="Custom\Pricerule\Observer\Frontend\Catalog\Catalog\ProductGetFinalPrice" type="Lof\RequestForQuote\Observer\ProductGetFinalPrice2" />

observer/ProductGetFinalPrice2.php

   <?php
    namespace Lof\RequestForQuote\Observer;
    use Magento\Customer\Model\Session as CustomerModelSession;
    use Magento\CatalogRule\Model\RuleFactory as RuleFactory;
    use Custom\Pricerule\Helper\Data;
    use PaarthMage\Document\Model\DocFactory as DocFactory;
    class ProductGetFinalPrice2 implements \Magento\Framework\Event\ObserverInterface
    {

        protected $customerSession;

        protected $catalogRuleFactory;
        protected $helper;
 public function __construct(

        CustomerModelSession $customerSession,
        RuleFactory $catalogRuleFactory,
        DocFactory $DocFactory,
        \Magento\Framework\App\State $state,
        Data $helper

        ) {
        $this->customerSession = $customerSession;
        $this->docFactory =  $DocFactory;
        $this->catalogRuleFactory =  $catalogRuleFactory;
        $this->_state = $state;
        $this->helper =  $helper;

        }


    /**
     * Execute observer
     *
     * @param \Magento\Framework\Event\Observer $observer
     * @return void
     */
    public function execute(
        \Magento\Framework\Event\Observer $observer
    ) {
$event = $observer->getEvent();
        $product = $event->getProduct();


    $productFinalPrice=100;
     $product->setData('special_price', $productFinalPrice);
       $product1=$product->getSpecialprice();

        }
        return $this;
        }
        }
    }

Why I am getting special in this module preference not working in my Lof_RequestForQuote module how I can solve this??

Thanks in advance.

  • your ProductGetFinalPrice2 should extend ProductGetFinalPrice – magefms Apr 20 at 7:18
  • i'm extending that calss i want the same action performed in productGetPrice – prabhakaran7 Apr 20 at 7:27
  • I mean it should be like this class ProductGetFinalPrice2 extends \Custom\Pricerule\Observer\Frontend\Catalog\Catalog\ProductGetFinalPrice implements \Magento\Framework\Event\ObserverInterface { – magefms Apr 20 at 7:40
  • no............................................... – prabhakaran7 Apr 20 at 7:47
  • i have one question??? – prabhakaran7 Apr 20 at 7:50
0

Add below sequence at Lof\RequestForQuote\etc\module.xml

<sequence>
    <module name="Custom_Pricerule"/>
</sequence>

Add below code to your observer:

<?php
namespace Lof\RequestForQuote\Observer;

use Magento\Customer\Model\Session as CustomerModelSession;
use Magento\CatalogRule\Model\RuleFactory as RuleFactory;
use Custom\Pricerule\Helper\Data;
use PaarthMage\Document\Model\DocFactory as DocFactory;

class ProductGetFinalPrice2 implements \Custom\Pricerule\Observer\Frontend\Catalog\Catalog\ProductGetFinalPrice
{

    protected $customerSession;

    protected $catalogRuleFactory;
    protected $helper;
    public function __construct(
        CustomerModelSession $customerSession,
        RuleFactory $catalogRuleFactory,
        DocFactory $DocFactory,
        \Magento\Framework\App\State $state,
        Data $helper
    ) {
        $this->customerSession = $customerSession;
        $this->docFactory =  $DocFactory;
        $this->catalogRuleFactory =  $catalogRuleFactory;
        $this->_state = $state;
        $this->helper =  $helper;
        parent::__construct($customerSession, $catalogRuleFactory, $DocFactory, $state, $helper);
    }


    /**
     * Execute observer
     *
     * @param \Magento\Framework\Event\Observer $observer
     * @return void
     */
    public function execute(
        \Magento\Framework\Event\Observer $observer
    ) {
        $event = $observer->getEvent();
        $product = $event->getProduct();


        $productFinalPrice=100;
        $product->setData('special_price', $productFinalPrice);
        $product1=$product->getSpecialprice();

    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.