2

I've to override checkout_cart_index.xml file from vendor/Magento for removing estimate shipping and discount code block! It's working successfully but my requirement is...it only should run when an admin or user select Yes from config part.I've tried ifconfig part but it's not working. Can anyone suggest any better idea to fulfil this requirement!? Here's my code of checkout_cart_index.xml. In this code set true in checkout.cart.coupon part is for removing Discount code and the above part is for for removing estimated shipping block and also override shipping.phtml

        <action method="setTemplate">
            <argument name="template" xsi:type="string">vender_extensionname::shipping.phtml</argument>
        </action>
        <arguments>
            <argument name="jsLayout" xsi:type="array">
                <item name="components" xsi:type="array">
                    <item name="block-summary" xsi:type="array">
                        <item name="config" xsi:type="array">
                            <item name="componentDisabled" xsi:type="boolean">true</item>
                        </item>
                    </item>
                </item>
            </argument>

        </arguments>
    </referenceBlock>

    <referenceBlock name="checkout.cart.coupon" remove="true"/>

Here's my config part enter image description here

in which if user set to yes in discount code then it should be displayed but if one select NO then it should not be displayed.I've created helper data.php for fetching that yes no value but I'm confused in how to use helper function in my XML part.

1 Answer 1

0

Try this way..

<referenceBlock name="your-block-name">
    <action method="setTemplate" ifconfig="section_id/group_id/field_id">
        <argument name="template" xsi:type="string">Meetanshi_Customization::shipping.phtml</argument>
    </action>
    <arguments>
        <argument name="jsLayout" xsi:type="array">
            <item name="components" xsi:type="array">
                <item name="block-summary" xsi:type="array">
                    <item name="config" xsi:type="array">
                        <item name="componentDisabled" xsi:type="boolean">true</item>
                    </item>
                </item>
            </item>
        </argument>

    </arguments>
</referenceBlock>

<referenceBlock name="checkout.cart.coupon">
    <action method="setTemplate" ifconfig="section_id/group_id/field_id">
        <argument name="setTemplate" xsi:type="string">Magento_Checkout::cart/coupon.phtml</argument>
    </action>
</referenceBlock>

Here you can use ifconfig in action element because in referenceBlock you can not use that attribute, or you can use below way...

<block name="your-block-name" ifconfig="section_id/group_id/field_id"></block>
<block name="checkout.cart.coupon" ifconfig="section_id/group_id/field_id"></block>

Hope this will work for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.