Improved Import & Export major update - full Google Sheets & Drive integration. Fixed price Magento 1 > Magento 2 migration service! EXPLORE

"Magento 2"

How to get POST and GET requests in Magento 2

- Magento 2

Magento 2 Development

In a case of a controller that extends Magento\Framework\App\Action\Action, it is possible to get the request with the aid of $this->getRequest()->getPost().

For a custom class, inject the request in the constructor:

More tips from Magento 2 Developer’s Cookbook

Continue Reading

How to replace LESS CSS Preprocessor with SASS or another one in Magento 2

- Magento 2

Magento 2 Development

In Magento 2, the LESS PHP adapter is located in \lib\internal\Magento\Framework\View\Page\Config\Renderer, and you can easily replace it with another one (SASS for instance) by updating the following lines of code in the di.xml configuration:

More tips from Magento 2 Developer’s Cookbook

Continue Reading

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