Magento 2 – Setting Final Product Price Globally

magento2price

I want to know for Entry point of Product final price calculation, those will be used globally in site like listing page,catalog page, shopping cart page,minicart.

I have to customize for product price, Is there any place we can set price and its used in global.

Where i can find final price of product is set(after special price, catalog/shopping rule if available) in magento 2?

Is there any place where product final price is calculated and its working for magento site Globally in all pages?

Thanks.

Best Answer

From my understanding, seem that you want to custom price on your shop. We should see some useful methods for customizing price.

vendor/magento/module-directory/Model/Currency.php

 public function formatPrecision(
        $price,
        $precision,
        $options = [],
        $includeContainer = true,
        $addBrackets = false
    ) {
       ......
    }

vendor/magento/module-directory/Model/PriceCurrency.php

 public function format(
            $amount,
            $includeContainer = true,
            $precision = self::DEFAULT_PRECISION,
            $scope = null,
            $currency = null
        ) {
            ......
        }

 public function convertAndRound($amount, $scope = null, $currency = null, $precision = self::DEFAULT_PRECISION)
 {
        ......
 }

vendor/magento/framework/Locale/Format.php

 public function getPriceFormat($localeCode = null, $currencyCode = null)
 {
   ......
 }

For sample di.xml:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Directory\Model\Currency">
        <plugin name="modify_around_precision" type="Vendor\YourModule\Model\Directory\Plugin\Precision" />
    </type>
    <type name="Magento\Directory\Model\PriceCurrency">
        <plugin name="modify_around_format" type="Vendor\YourModule\Model\Directory\Plugin\Format" />
        <plugin name="modify_around_round" type="Vendor\YourModule\Model\Directory\Plugin\PriceRound" />
    </type>
    <type name="Magento\Framework\Locale\Format">
        <plugin name="modify_around_price_format" type="Vendor\YourModule\Model\Locale\Plugin\ModifyPriceFormat" />
    </type>
</config>
Related Topic