[英]Magento 2 : ifconfig in xml for module enable/disable
我已經為啟用/禁用模塊創建了配置。 如果我從配置設置中選擇“是”,則我的模塊在前面可見,否則不可見。 為此,我在 checkout_cart_index.xml 中添加了 ifConfig 條件。 xml代碼如下。
<referenceContainer name="cart.summary">
<block class="Mageniks\Test\Block\Test" before="-" ifconfig="mageniks/general/active" name="displaytest" template="Mageniks_Test::cart.phtml">
</block>
</referenceContainer>
<referenceBlock name="checkout.cart.totals">
<arguments>
<argument name="jsLayout" xsi:type="array">
<item name="components" xsi:type="array">
<item name="block-totals" xsi:type="array">
<item name="children" xsi:type="array">
<item name="fee" xsi:type="array" remove="true">
<item name="component" xsi:type="string">Mageniks_Test/js/view/checkout/cart/totals/fee</item>
<item name="sortOrder" xsi:type="string">20</item>
<item name="config" xsi:type="array">
<item name="template" xsi:type="string">Mageniks_Test/checkout/cart/totals/fee</item>
<item name="title" xsi:type="string" translate="true">Fee</item>
</item>
</item>
</item>
</item>
</item>
</argument>
</arguments>
</referenceBlock>
Ifconfig 僅在使用塊時才起作用。 Ifconfig 在參數中不起作用。
我想在參數或項目標簽中添加條件以啟用和禁用模塊(如塊標簽)。
我怎樣才能做到這一點 ? 請幫我。 任何幫助,將不勝感激。
謝謝
使用此插件,您可以在項目中放置模塊啟用禁用條件
<type name="Magento\Checkout\Block\Cart\LayoutProcessor">
<plugin name="CartStorecreditDisable"
type="Vendor\Module\Plugin\CartStorecreditDisable"/>
</type>
在插件中,
use Magento\Checkout\Block\Cart\LayoutProcessor;
public function afterProcess(
LayoutProcessor $processor,
array $jsLayout
){
$enable = $this->helper->getConfig('storecredit/general/enable');
if($enable == 0){
$jsLayout['components']['block-totals']['children']['storecredit']['config']['componentDisabled'] = true;
}
return $jsLayout;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.