Let’s initiate a discussion!!
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<?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="Magento\ConfigurableProduct\Pricing\Price\Pool" type="Magento\Framework\Pricing\Price\Pool"> <arguments> <argument name="prices" xsi:type="array"> <item name="regular_price" xsi:type="string">Magemonkeys\Pricesorting\Pricing\ConfigurableRegularPrice</item> <item name="final_price" xsi:type="string">Magento\ConfigurableProduct\Pricing\Price\FinalPrice</item> </argument> <argument name="target" xsi:type="object">Magento\Catalog\Pricing\Price\Pool</argument> </arguments> </virtualType> <type name="Magemonkeys\Pricesorting\Pricing\ConfigurableRegularPrice"> <arguments> <argument name="priceResolver" xsi:type="object">ConfigurableRegularPriceResolver</argument> </arguments> </type> </config> |
We need to create file under module Pricesorting/Pricing/ConfigurableRegularPrice.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ namespace Magemonkeys\Pricesorting\Pricing; use Magento\Catalog\Model\Product; use Magento\Framework\App\ObjectManager; use Magento\Framework\Pricing\Price\AbstractPrice; use Magento\ConfigurableProduct\Pricing\Price\ConfigurableRegularPriceInterface; use Magento\ConfigurableProduct\Pricing\Price\LowestPriceOptionsProviderInterface; use Magento\ConfigurableProduct\Pricing\Price\PriceResolverInterface; /** * 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 \Magento\Framework\Pricing\Amount\AmountInterface */ protected $maxRegularAmount; /** * @var \Magento\Framework\Pricing\Amount\AmountInterface */ protected $minRegularAmount; /** * @var array */ protected $values = []; /** * @var \Magento\ConfigurableProduct\Pricing\Price\PriceResolverInterface */ protected $priceResolver; /** * @var ConfigurableOptionsProviderInterface */ private $configurableOptionsProvider; /** * @var LowestPriceOptionsProviderInterface */ private $lowestPriceOptionsProvider; protected $resource; /** * @param \Magento\Framework\Pricing\SaleableInterface $saleableItem * @param float $quantity * @param \Magento\Framework\Pricing\Adjustment\CalculatorInterface $calculator * @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency * @param PriceResolverInterface $priceResolver * @param LowestPriceOptionsProviderInterface $lowestPriceOptionsProvider * @param \Magento\Framework\App\ResourceConnection $resource */ public function __construct( \Magento\Framework\Pricing\SaleableInterface $saleableItem, $quantity, \Magento\Framework\Pricing\Adjustment\CalculatorInterface $calculator, \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency, PriceResolverInterface $priceResolver, LowestPriceOptionsProviderInterface $lowestPriceOptionsProvider = null, \Magento\Framework\App\ResourceConnection $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 \Magento\Framework\Pricing\Amount\AmountInterface */ 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.
[crayon-64216ee6b1038025552804/] Using above fucntion Images can be imported directly from...
Override view block using di.xml and add the below code...
You can check a list of called layout XML for...
Follow the below steps to install and set up PWA...
If you want to remove all leading zero's from order,...
Let our Magento expert connect to discuss your requirement.
We offer Magento
certified developers.
Our Magento clientele
is 500+.
We sign NDA for the
security of your projects.
We’ve performed 100+
Magento migration projects.
Free quotation
on your project.
Three months warranty on
code developed by us.