【问题标题】:Magento 2.0 override core CofigurableProduct module blockMagento 2.0 覆盖核心 CofigurableProduct 模块块
【发布时间】:2016-03-11 09:43:42
【问题描述】:

我想更改定价计算,为此我尝试通过首选项覆盖可配置块,但它不起作用

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

可配置.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;
}
}

【问题讨论】:

    标签: magento magento-2.0


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-02-29
        • 1970-01-01
        • 1970-01-01
        • 2012-02-16
        相关资源
        最近更新 更多