Magento 2: Get Controller, Module, Action & Route Name

This article shows how we can get name of the current module, controller name, action name and route name in Magento 2. Using Dependency Injection (DI) Below is a block class of my custom module (Chapagain_HelloWorld). I have injected object of \Magento\Framework\App\Request\Http class in the constructor of my module’s block class. app/code/Chapagain/HelloWorld/Block/HelloWorld.php <?php namespace Chapagain\HelloWorld\Block; … Read more

Magento 2: Check if Current URL is Homepage

This article shows how we can check if the current page URL is homepage URL in Magento 2. Below is a block class of my custom module (Chapagain_HelloWorld). I have injected object of Logo block class in the constructor of my module’s block class. app/code/Chapagain/HelloWorld/Block/HelloWorld.php <?php namespace Chapagain\HelloWorld\Block; class HelloWorld extends \Magento\Framework\View\Element\Template { protected $_logo; … Read more

Magento 2: Check if Current URL & Frontend URL are Secure (https)

This article shows how we can check if current URL and frontend URl are secure (https) or not in Magento 2. Below is a block class of my custom module (Chapagain_HelloWorld). I have injected object of StoreManagerInterface in the constructor of my module’s block class. app/code/Chapagain/HelloWorld/Block/HelloWorld.php <?php namespace Chapagain\HelloWorld\Block; class HelloWorld extends \Magento\Framework\View\Element\Template { protected … Read more

Magento 2: Get Store Information (Store ID, Code, Name, URL, Website ID)

This article shows how we can get store information in Magento 2. We will be fetching store id, store code, store name, store url, and store’s website id. We also write a function which checks if the store is active or not. Below is a block class of my custom module (Chapagain_HelloWorld). I have injected … Read more

Magento 2: Get Currency Code, Currency Symbol & Currency Rate

This article shows how we can get our store’s currency code, currency symbol, and currency rate in Magento 2. We will be fetching all base, default and current currency code. We will also be fetching available currency codes and allowed currency codes. Using Dependency Injection (DI) Below is a block class of my custom module … Read more

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