1

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

这是我的 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;
}
}
4

2 回答 2

1

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

于 2016-11-22T05:43:31.320 回答
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类。

于 2021-05-07T15:13:20.533 回答