Magento 2: Search Repository using SearchCriteriaBuilder, Filter & FilterGroup

This article shows how we can search Magento Repositories using SearchCriteriaBuilder that implements SearchCriteriaInterface. An example is provided of how we can perform search on Product repository in Magento. Similarly, we can search for other entities like Category, Customer, Order, Invoice, CMS Page, CMS Block, etc. We can add different conditions to build custom search … Read more

Magento 2: Override/Rewrite Block, Model, Controller, Helper using Plugin & Preference

This article shows how you can override / rewrite Block, Controller, Model, and Helper in Magento 2. This can be done by two ways: 1) using Preference 2) using Plugin Preference is similar to class rewrite in Magento 1. There is always possibility of conflict when two or more custom modules try to rewrite/override same … Read more

Magento 2: How to call any template block from phtml file?

In Magento 1.x, you could call/print any module’s template block in any other template (phtml) file with the following code: echo $this->getLayout() ->createBlock('newmodule/newblock') ->setTemplate('newmodule/newblock.phtml') ->toHtml(); In Magento 2.x, it’s slightly different. Below is the code to call/print a custom template block in another template file in Magento 2. Suppose, you want to call a template … Read more

Magento 2: How to call CMS Static Block from template (phtml) file?

In Magento 1.x, you could call/print the CMS Static Block in template file with the following code: echo $this->getLayout() ->createBlock('cms/block') ->setBlockId('your_block_identifier') ->toHTML(); In Magento 2.x, it’s quite similar. Below are the sample codes to show/call template (.phtml) files in Magento 2. Call CMS Static Block in any template (.phtml) file echo $this->getLayout() ->createBlock('Magento\Cms\Block\Block') ->setBlockId('your_block_identifier') ->toHtml(); … Read more

Magento: Rewrite/Override Block Controller Model Helper

This article will show how you can override/rewrite Magento Block, Controller, Model and Helper files. We will be dealing with the config XML files and the class files to override. We override Magento core classes to update/modify the core functionalities according to our need. We can directly makes changes in the core Magento classes but … Read more

Magento: How to call static block from template (.phtml) file?

You can easily call any static block from template (phtml) file. At first, you have to create a static block. Let us suppose, you created a static block with the identifier cool_items. Now, you can call the static block from any phtml file with the help of following code: echo $this->getLayout() ->createBlock('cms/block') ->setBlockId('cool_items') ->toHTML(); Thanks.

Magento: How to call block directly from phtml file without defining in layout?

You can call your block directly from a phtml file with the following code. You can keep this code and call the block from any phtml file. I have assumed my module name as Newmodule and my block name as Newblock.php. The phtml file for the block is assumed to be newmodule/newblock.phtml echo $this->getLayout() ->createBlock('newmodule/newblock') … Read more