Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento 2 : ifconfig in xml for module enable/disable

I have created configuration for enable/disable module. If I select "Yes" from configuration settings, my module is visible for front otherwise not. For this , I have added ifConfig condition in checkout_cart_index.xml. The xml code is given below.

<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 is working only when block used. Ifconfig is not working in arguments.

I want to add condition in argument or item tag for enable and disable module like block tag.

How can I do this ? Please help me. Any help would be appreciated.

Thanks

like image 631
Niks Avatar asked Jan 18 '17 07:01

Niks


People also ask

How do I override layout xml in Magento 2?

Override theme layouts * To override page layout files, use the page_layout directory name instead of layout . * Remember to always name your new layout files with the same name as the file that you wish to override.

Where is config xml in Magento?

For example, the configuration object for config. xml is Magento\Framework\App\Config.

What is resource in menu xml in Magento 2?

resource – defines the ACL rule which the admin user must have in order to see and access this menu, it is defined in acl. xml. Otherwise, menu item won't be rendered.


1 Answers

Using this pulgin you can put module enable disable condition in items

<type name="Magento\Checkout\Block\Cart\LayoutProcessor">
<plugin name="CartStorecreditDisable" 
type="Vendor\Module\Plugin\CartStorecreditDisable"/>
</type>

In plugin,

 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;
 }
like image 64
Sagar V Avatar answered Nov 15 '22 07:11

Sagar V