How to Set Product final price using catalog_product_get_final_price Event in Magento 2.

You can modify the final price value by define events in your XML file with Magento 2.

catalog_product_get_final_price the event defined under the Magento\Catalog\Model\Product\Type\Price class.

You can also interested to check,  A Complete List of all events in Magento 2.

Refer the GetFinalPrice() method from the Price.php class which defined the event to modify the final price value of the product.

If you are working with the REST or SOAP API, You need to define events in the webapi_rest or webapi_soap area of the module to trigger events.

Let’s take a simple example to set Product price as Maximum 100.
We have created an observer to fetch product final price and we are checking if the product price is greater than 100, we set it to max 100 by observer class.

Define Events in your module front area, 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="Jesadiya\MarketingPrice\Observer\ProcessFinalPriceObserver" />
    </event>
</config>

Create an Observer file to trigger event action to set the final price,

<?php
namespace Jesadiya\MarketingPrice\Observer;

class ProcessFinalPriceObserver
{
    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        $product = $observer->getEvent()->getProduct();
        $pId = $product->getId();
        $qty = $observer->getEvent()->getQty();
        $storeId = $product->getStoreId();

        $finalPrice = 100;
        $finalPrice = min($product->getData('final_price'), $finalPrice);
        $product->setFinalPrice($finalPrice);

        return $this;
    }
}

In this Example, We are 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.

You can set your logic to the observer file based on your requirements. In the Observer file, You get the product Object data and Product Qty value.