"magento 2"

Flushing the Magento 2 Cache Storage

- Magento 2

Magento 2 Development

You can easily flush the cache storage of Magento 2 from the command line. Note that the following script must be executed from the Magento 2 root folder:

It deletes all content from the var subfolder excluding the.htaccess file and the var/session subfolder. Besides, the script also deletes all content from the pub/static subfolder excluding the.htaccess file.

More tips from Magento 2 Developer’s Cookbook

Continue Reading

Writing a message to a system log in Magento 2

- Magento 2

Magento 2 Development

To create a message to a system log in Magento 2.0, use the code listed below:

In Magento 1, for instance, this code was more simple:

but you can also utilize another approach in case of Magento 2. Since there is a  _logger property related to many objects, you can perform the same task by calling inside such objects. Just use the following code:

Please note that not every object has the _logger property. Thus, this method will not work with all your objects.

More tips from Magento 2 Developer’s Cookbook

Continue Reading

Adding a new product type in Magento 2

- Magento 2

Magento 2 Development

Create etc/product_types.xml in your module to add a new product type in Magento 2:

The second step requires creating the modelInstance:

More tips from Magento 2 Developer’s Cookbook

Continue Reading

How to remove block from a Magento 2 layout

- Magento 2

Magento 2 Development

Remove instruction is available in Magento 2. Please note that the layout merges in order shown in a module.xml/sequence section. Here is the instruction:

More tips from Magento 2 Developer’s Cookbook

Continue Reading

How to clean LESS/CSS Theme cache in Magento 2

- Magento 2

Magento 2 Development

Right in refresh .less files, since it “collects, processes and publishes source LESS files”:

You can also use dev mode during development. According to documentation “Static view files are not cached; they are written to the Magento pub/static directory every time they’re called.”

More tips from Magento 2 Developer’s Cookbook

Continue Reading

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