Magento 2: Upgrade/Update using Command Line & Composer

This article shows how you can upgrade/update your Magento 2 version through command line using composer. Upgrading to Magento 2.3.x is a bit different than that of Magento 2.2.x or 2.1.x. At first, I will show the commands that need to be run to upgrade Magento2 to version 2.1.x or 2.2.x. Upgrading Magento to 2.2.x … Read more

Magento 2: Get all shopping cart items, subtotal, grand total, billing & shipping address

This article shows how to get shopping cart items/products, subtotal and grand total of cart, and shipping and billing address entered while doing checkout in Magento 2. I will be using both Dependency Injection (DI) and Object Manager in the below example code. Using Object Manager – Get products id, name, price, quantity, etc. present … Read more

Magento 2: Run Custom SQL Query

This article shows how to write/run/execute custom SQL queries in Magento 2. We need to instantiate class Magento\Framework\App\ResourceConnection for this. You have to inject this resource class in your module’s Block/Model/Controller class constructor. After that, you can use that object to run custom sql queries. In this example, I will simply be using object manager … 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: Before & After Method Observer using Plugin

Magento 2 provides a new feature called Plugin or Interceptor that is used to run some code before/after/around any function call of any public class. Hence, with the help of Plugins, we can change the behavior of class method without making any changes in the code of the class itself. This also avoids conflicts with … Read more

Auto Currency Switcher 2: Magento 2 Extension [FREE]

Auto Currency Switcher 2 is a currency switcher extension for Magento 2 which automatically switches store currency based on visitor’s IP address. Auto Currency Switcher 2 extension tracks visitor’s IP address and automatically changes the store currency to the visitor’s location currency. Visitor can switch to his/her desired currency at any time. This extension uses … Read more

Magento 2: Event Observer

This article shows how you can create event observer in a custom module in Magento 2. In Magento 2, there is a separate xml file where you can define your event observer. For frontend events, you need to write your code in app/code/YourCompany/YourModule/etc/frontend/events.xml and for admin events, you need to write event observer code in … Read more