Magento 2:用于模块启用/禁用的XML中的ifconfig

7

我已经创建了启用/禁用模块的配置。如果我从配置设置中选择“是”,则我的模块就会在前端可见,否则不可见。 为此,我在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只在块标记中起作用,而在参数中不起作用。

我想在参数或项标记中添加条件,以启用和禁用模块,就像块标记一样。

我该怎么做?请帮帮我。任何帮助都将不胜感激。

谢谢

1个回答

2
使用这个插件,您可以在项目中设置模块的启用/禁用条件。
<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;
 }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接