Magento: Add Configurable Product Options to Wishlist

This article shows how to add configurable products to wishlist along with their options value. By default, you don’t need to select any configurable product option when you want to add the configurable product to wishlist. But, you will have to select the configurable option while adding the product to cart. So, you might be … Read more

Magento 2: Command Line Tool / Interface (CLI)

Magento 2 uses Symfony’s Console Component for its command-line interface or tool (CLI) where we can execute different commands for different tasks related to installation and configuration. Through the Command Line Interface (CLI) tool in Magento 2, you can perform different tasks like: Installing Magento Clearing the cache Managing indexes, including reindexing Creating translation dictionaries … Read more

Magento: Get all products by attribute id and attribute option

This article shows how to get / filter products based on it’s attribute id, or the attribute’s options id. Get all products by a single attribute option id Suppose, we have an attribute named ‘manufacturer’. Let’s say, this attribute has options like Samsung, Apple, Nokia, HTC, etc. Each option has certain ID. Suppose, we want … Read more

Magento 2: Simple Hello World Module – Step-by-Step Beginner Tutorial

This beginner step-by-step tutorial shows how you can create a simple and basic HelloWorld module / extension in Magento 2. The necessary files are listed with the code. This module just calls a block function in template file to print Hello World text. GitHub Repository of the Module: https://github.com/chapagain/simple-helloworld-magento2 Things to note: In Magento 2, … Read more

Magento: Filter Configurable Product by Child Product’s Attribute

This article shows how you can filter child products associated with a configurable product by the child product’s attribute value. Suppose, we have a configurable product with two attributes (‘size‘ and ‘color‘) and we want to select only those child products with certain size and/or certain color. Let’s say, we want to select only those … Read more

Magento 2: Check if a module is installed, enabled or active

This article shows how we can check if a module is installed / enabled or active in Magento 2. Both Dependency Injection and Object Manager ways are shown below. Using Dependency Injection (DI) Below is a block class of my custom module (Chapagain_HelloWorld). I have injected object of \Magento\Framework\Module\Manager class in the constructor of my … 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