7

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

Dhiren Vasoya
  • 668
  • 7
  • 20
Niks
  • 615
  • 2
  • 14
  • 26

1 Answers1

2

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;
 }
Sagar V
  • 21
  • 2