0

I created a custom module which adds an input in shipping method for all products in the checkout page. I want to hide and show this input as per specific category products and replaced this old to new inputs on the checkout page. Does anyone knows this? Thanks in advanced.

checkout_index_index.xml

<item name="shippingAdditional" xsi:type="array">
 <item name="component" xsi:type="string">uiComponent</item>
  <item name="displayArea" xsi:type="string">shippingAdditional</item>
     <item name="children" xsi:type="array">
        <item name="delivery_date" xsi:type="array">
           <item name="component" xsi:type="string">Module_name/js/view/delivery-date-block</item>
           </item>
        </item>
     </item>
 </item>

1 Answer 1

0

If your extension has a block to render the phtml (I hope it does) you could create a plugin and set a method as follows:

public function afterToHtml($subject, $result) { if (condition to show is true) { return $result; } else { return ""; } }

You can see how to create a plugin in http://devdocs.magento.com/guides/v2.0/extension-dev-guide/plugins.html

[Edit]

To handle this in the javascript you are going to need to do a few steps:

  • Create a configuration for setting which categories you want to hide/show.
  • Create a config provider an set your business logic there
  • Load the data from your custom config provider at Module_name/js/view/delivery-date-block and set if the template should be visible or not.
  • At your template you could use a if binding http://knockoutjs.com/documentation/if-binding.html
6
  • @ Thiago Thanks for reply.. Actually I am showing custom input defining in checkout_index_index layout file and setting html template using knockout js file. Can you give me more details on which class I extends with "after" in plugin or how can I hide custom block. sorry for trouble, i am beginner in magento.
    – Rahul
    Commented Feb 18, 2018 at 18:45
  • Could you update the description and paste the checkout_index_index.xml, please? Commented Feb 18, 2018 at 21:01
  • I updated the description kindly check it and let me know.
    – Rahul
    Commented Feb 19, 2018 at 5:14
  • @Rahul here you go Commented Feb 19, 2018 at 9:38
  • Thanks @Thiago, Its work for me. refer this Link to hide and show template as per config.
    – Rahul
    Commented Feb 21, 2018 at 19:00

Your Answer

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

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