4

I am trying to override ConfigurablePriceResolver but can't override

app/code/vender/module/etc/di.xml

<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">       
    <preference for="Magento\ConfigurableProduct\Pricing\Price\ConfigurablePriceResolver" type="Vender\Module\Pricing\Price\ConfigurablePriceResolver" />
</config>

app\code\Vender\module\Pricing\Price\ConfigurablePriceResolver.php

<?php

namespace Vender\Module\Pricing\Price;

class ConfigurablePriceResolver extends \Magento\ConfigurableProduct\Pricing\Price\ConfigurablePriceResolver
{   

    /**
     * @param \Magento\Framework\Pricing\SaleableInterface|\Magento\Catalog\Model\Product $product
     * @return float
     * @throws \Magento\Framework\Exception\LocalizedException
     */
    public function ResolvePrice(\Magento\Framework\Pricing\SaleableInterface $product) {       
        $price = null;
        foreach ($this->configurable->getUsedProducts($product) as $subProduct) {
            $productPrice = $this->priceResolver->resolvePrice($subProduct);
            $price = $price ? min($price, $productPrice) : $productPrice;
        }
        /* if (!$price) {
            throw new \Magento\Framework\Exception\LocalizedException(
                __('Configurable product "%1" do not have sub-products', $product->getName())
            );
        } */
         return $price === null ? null : (float)$price;
    }
}
  • check your namespace and module name in di.xml – Ramkishan Suthar Jan 31 '17 at 6:47
  • app/code/vender/modile/etc/di.xml this should be app/code/Vender/module/etc/di.xml – Ramkishan Suthar Jan 31 '17 at 6:47
4

ConfigurablePriceResolver is virtual type both used by ConfigurableFinalPriceResolver and ConfigurableRegularPriceResolver. Therefore, to override it, you have to override the virtual type, not the class itself.

<preference for="ConfigurableFinalPriceResolver" type="Vendor\Module\Pricing\Price\ConfigurablePriceResolver" />

<preference for="ConfigurableRegularPriceResolver" type="Vendor\Module\Pricing\Price\ConfigurablePriceResolver" />
3

Solution:

app/code/vender/module/etc/di.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">           
    <virtualType name="ConfigurableFinalPriceResolver" type="Vender\Module\Pricing\Price\ConfigurablePriceResolver">
        <arguments>
            <argument name="priceResolver" xsi:type="object">Magento\ConfigurableProduct\Pricing\Price\FinalPriceResolver</argument>
        </arguments>
    </virtualType>
</config>

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.