Magento 2.0覆盖核心CofigurableProduct模块块

时间:2016-03-11 09:43:43

标签: magento magento-2.0

我想更改定价计算,我试图通过首选项覆盖可配置块,但它无法正常工作

这是我的di.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" />

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;
}
}

2 个答案:

答案 0 :(得分:1)

您需要覆盖Magento\Swatches\Block\Product\Renderer\Configurable,而不是覆盖Magento\ConfigurableProduct\Block\Product\View\Type\Configurable类。

答案 1 :(得分:0)

您需要覆盖 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 类。