我有 Magento 2。
我寫了一個模塊。
我寫了這個檔案:app\code\Vendor\MyModule\etc\di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Catalog\Pricing\Render\FinalPriceBox" type="Vendor\MyModule\Block\Callforprice" />
</config>
我寫這個類:app\code\Vendor\MyModule\Block\Callforprice.php
namespace Vendor\MyModule\Block;
* Product price block
*/
class Callforprice extends \Magento\Catalog\Pricing\Render\FinalPriceBox
{
/**
* Wrap with standard required container
*
* @param string $html
* @return string
*/
protected function wrapResult($html)
{
return '-TEST-<div hljs-variable language_">$this->getData('css_classes') . '" ' .
'data-role="priceBox" ' .
'data-product-id="' . $this->getSaleableItem()->getId() . '" ' .
'data-price-box="product-id-' . $this->getSaleableItem()->getId() . '"' .
'>' . $html . '</div>';
}
}
此代碼適用于目錄視圖中的簡單產品,但不適用于可配置產品。如何在目錄視圖中覆寫可配置產品價格的 html?
uj5u.com熱心網友回復:
我找到了解決方案。我必須覆寫:
Magento\ConfigurableProduct\Pricing\Render\FinalPriceBox
我也把模板放在:
app\design\frontend\Vendor\myTheme\Magento_ConfigurableProduct\templates\product\price\final_price.phtml
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/516749.html
標籤:马金托
下一篇:如何使彈出視頻回應于移動設備
