Question

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>

Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top