If you need to set our custom price or to perform any customization in price, them follow below steps.
Create di.xml under etc folder in module
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <virtualType name="MagentoConfigurableProductPricingPricePool" type="MagentoFrameworkPricingPricePool"> <arguments> <argument name="prices" xsi:type="array"> <item name="regular_price" xsi:type="string">MagemonkeysPricesortingPricingConfigurableRegularPrice</item> <item name="final_price" xsi:type="string">MagentoConfigurableProductPricingPriceFinalPrice</item> </argument> <argument name="target" xsi:type="object">MagentoCatalogPricingPricePool</argument> </arguments> </virtualType> <type name="MagemonkeysPricesortingPricingConfigurableRegularPrice"> <arguments> <argument name="priceResolver" xsi:type="object">ConfigurableRegularPriceResolver</argument> </arguments> </type> </config>
We need to create file under module Pricesorting/Pricing/ConfigurableRegularPrice.php
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ namespace MagemonkeysPricesortingPricing; use MagentoCatalogModelProduct; use MagentoFrameworkAppObjectManager; use MagentoFrameworkPricingPriceAbstractPrice; use MagentoConfigurableProductPricingPriceConfigurableRegularPriceInterface; use MagentoConfigurableProductPricingPriceLowestPriceOptionsProviderInterface; use MagentoConfigurableProductPricingPricePriceResolverInterface; /** * Class RegularPrice */ class ConfigurableRegularPrice extends AbstractPrice implements ConfigurableRegularPriceInterface { const ATTRIBUTE_CODE = 333; const PRICE_TABLE = 'catalog_product_index_price'; const ENTITY_TABLE = 'catalog_product_entity_int'; /** * Price type */ const PRICE_CODE = 'regular_price'; /** * @var MagentoFrameworkPricingAmountAmountInterface */ protected $maxRegularAmount; /** * @var MagentoFrameworkPricingAmountAmountInterface */ protected $minRegularAmount; /** * @var array */ protected $values = []; /** * @var MagentoConfigurableProductPricingPricePriceResolverInterface */ protected $priceResolver; /** * @var ConfigurableOptionsProviderInterface */ private $configurableOptionsProvider; /** * @var LowestPriceOptionsProviderInterface */ private $lowestPriceOptionsProvider; protected $resource; /** * @param MagentoFrameworkPricingSaleableInterface $saleableItem * @param float $quantity * @param MagentoFrameworkPricingAdjustmentCalculatorInterface $calculator * @param MagentoFrameworkPricingPriceCurrencyInterface $priceCurrency * @param PriceResolverInterface $priceResolver * @param LowestPriceOptionsProviderInterface $lowestPriceOptionsProvider * @param MagentoFrameworkAppResourceConnection $resource */ public function __construct( MagentoFrameworkPricingSaleableInterface $saleableItem, $quantity, MagentoFrameworkPricingAdjustmentCalculatorInterface $calculator, MagentoFrameworkPricingPriceCurrencyInterface $priceCurrency, PriceResolverInterface $priceResolver, LowestPriceOptionsProviderInterface $lowestPriceOptionsProvider = null, MagentoFrameworkAppResourceConnection $resource ) { parent::__construct($saleableItem, $quantity, $calculator, $priceCurrency); $this->priceResolver = $priceResolver; $this->lowestPriceOptionsProvider = $lowestPriceOptionsProvider ?: ObjectManager::getInstance()->get(LowestPriceOptionsProviderInterface::class); $this->resource = $resource; } /** * @inheritdoc */ public function getMinRegularAmount() { if (null === $this->minRegularAmount) { $this->minRegularAmount = $this->doGetMinRegularAmount() ?: parent::getAmount(); } return $this->minRegularAmount; } /** * Get min regular amount * * @return MagentoFrameworkPricingAmountAmountInterface */ protected function doGetMinRegularAmount() { $minAmount = null; foreach ($this->lowestPriceOptionsProvider->getProducts($this->product) as $product) { $parentId = $this->product->getId(); $connection = $this->resource->getConnection(); $tableName = $connection->getTableName(self::ENTITY_TABLE); $table2 = $connection->getTableName(self::PRICE_TABLE); $select = $connection->select() ->from( ['c' => $tableName], ['*'] ) ->joinLeft( ['ca' => $table2], 'c.value = ca.entity_id', ['*'] ) ->where('c.attribute_id = ?', self::ATTRIBUTE_CODE) ->where('c.row_id = ?', $parentId); $result = $connection->fetchRow($select); if ($result) { $priceValue = $result['price']; $product->setPriceCalculation(false); $product->setPrice($priceValue); $minAmount = $product->getPriceInfo()->getPrice('regular_price')->getAmount(); } else { $childPriceAmount = $product->getPriceInfo()->getPrice(self::PRICE_CODE)->getAmount(); if (!$minAmount || ($childPriceAmount->getValue() < $minAmount->getValue())) { $minAmount = $childPriceAmount; } } } return $minAmount; } }
That’s it.