Magento 2.0 переопределяет основной блок модуля CofigurableProduct

Я хочу изменить расчет цены, для чего я пытался переопределить настраиваемый блок через предпочтение, но это не работает

Вот мой ди.xml

   <?xml version="1.0"?>
   <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
   <preference for="Magento\ConfigurableProduct\Block\Product\View\Type\Configurable" type="Vendor\demo\Block\ConfigurableProduct\Block\Product\View\Type\Configurable" />

Конфигурируемый.php:

class Configurable extends \Magento\Catalog\Block\Product\View\AbstractView {
$prices = [];
foreach ($this->getAllowProducts() as $product) {
$priceInfo = $product->getPriceInfo();
$product_weight=$product->load($product->getId())->getWeight();
 $prices[$product->getId()] =
 [
'oldPrice' => [
'amount' => $this->_registerJsPrice(
                        $priceInfo->getPrice('regular_price')->getAmount()->getValue()
                    ),],
'basePrice' => [
                    'amount' => $this->_registerJsPrice(
                        $priceInfo->getPrice('final_price')->getAmount()->getBaseAmount()
                    ),
                ],
'finalPrice' => [
                    'amount' => $this->_registerJsPrice(
                        ((($product->getAttributeText('purity')/24)*100)/100)*(100000/10)*$product_weight
                    ),
                ]
 ];
    }
 return $prices;
}
}

person Shachi Arkatkar    schedule 11.03.2016    source источник


Ответы (2)


Вам нужно переопределить Magento\Swatches\Block\Product\Renderer\Configurable вместо переопределения класса Magento\ConfigurableProduct\Block\Product\View\Type\Configurable.

person Rejoe    schedule 22.11.2016

Вам нужно переопределить Magento\Swatches\Block\Product\Renderer\Configurable вместо переопределения класса Magento\ConfigurableProduct\Block\Product\View\Type\Configurable. Потому что Magento\Swatches\Block\Product\Renderer\Configurable уже переопределяет класс Magento\ConfigurableProduct\Block\Product\View\Type\Configurable.

person Saurabh Magespider    schedule 07.05.2021