2

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"

1
  • 1
    Show your observer code what you have tried?
    – Priyank
    May 25, 2017 at 5:27

1 Answer 1

0

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;
    }
}
3
  • I have done as mention but it is not working Nov 16, 2017 at 11:50
  • It is working fine for simple product not for configurable products Nov 16, 2017 at 12:52
  • @zedBlackbeard That is because configurable products have their own Price class: Magento\ConfigurableProduct\Model\Product\Type\Configurable\Price which does not issue a catalog_product_get_final_price event.
    – Zulakis
    May 23, 2020 at 19:22

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.