Magento – Magento 2 catalog_product_get_final_price event not working for configurable product

configurable-productevent-observermagento2

I have to set the product price to a custom value depends up on the customer. So I have written an event catalog_product_get_final_price and in the observer I have set the custom price for the product. But this is working only for "Simple Product" (visibility both). When I view the configurable product nothing is happened. Even I have write a die() in the observer and it is working when I view the Simple product but not for the configurable product. That means when I view the configurable product, the event is not triggering.

How can I set the simple product's price to a custom value using event? I need this for the "listing" and "view page"

Best Answer

First, you should tried your event on a default magento Instance.

If it will work then there might be some other module that have overridden final price using plugin, or event.

if it won't work on default magento then there probanly are some issues in your observer code.

Observer.code should like this:

<?php

namespace [Vendorname]\[Modulename]\Observer;

use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\Event\Observer as EventObserver;

class ProcesschangeFinalPriceObserver implements ObserverInterface
{


    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        $product = $observer->getEvent()->getProduct();
        $pId = $product->getId();
        $storeId = $product->getStoreId();
        $finalPrice = 100;
        $product->setPrice($finalPrice);
        $product->setFinalPrice($finalPrice); // set final price here 
        return $this;
    }
}
Related Topic