我想更改定价计算,为此我尝试通过首选项覆盖可配置块,但它不起作用
这是我的 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;
}
}