How to change a template for a standard block

- Magento 2

Magento 2 Development

By calling setTemplate method of course!

More tips from Magento 2 Developer’s Cookbook

Continue Reading

How to defer JavaScript execution in Magento 2

- Magento 2

Magento 2 Development

Being a boolean attribute, defer specifies that the script is executed after the page parsing. The attribute is aimed at external scripts only (the src attribute should be present). Find more information about defer here.

Despite Magento 2 supports standard script deferring, it never uses defer in its core. To change the situation, you can use the following code:

More tips from Magento 2 Developer’s Cookbook

Continue Reading

How to programmatically create a configurable Magento 2 product

- Magento 2

Magento 2 Development

If the simple and configurable products are not assigned together like in the folowing example, there is a reliable solution.

You can review on API functional test aimed at creating configurable product. You code should have the following look:

It is also necessary to mention that the API does not generate simple product, so there is the need to create in advance.

More tips from Magento 2 Developer’s Cookbook

Continue Reading

Adding a custom block to specific product type view pages in Magento 2

- Magento 2

Magento 2 Development

To add a custom block to specific product type view pages, use product type dependent layout updates catalog_product_view_type_{prodyct_type}.xml (catalog_product_view_type_ grouped.xml). For instance:

More tips from Magento 2 Developer’s Cookbook

Continue Reading