Home » Archive

Articles in the Magento Category

Magento, Magento 2 »

[26 Sep 2016 | No Comment]

This article shows how to get custom option values of products/items added to cart or products of any order in Magento 2.
I will simply be using ObjectManager for this example.

Magento, Magento 2 »

[19 Sep 2016 | No Comment]

This article shows how we can get list of all categories from current product or any particular product as well.
Below is a block class of my custom module (Chapagain_HelloWorld). I have injected object of \Magento\Catalog\Model\ResourceModel\Category\CollectionFactory, \Magento\Catalog\Model\ProductRepository and \Magento\Framework\Registry classes in the constructor of my module’s block class.

Magento, Magento 2 »

[14 Sep 2016 | No Comment]

This article shows how you can upgrade/update your Magento 2 version through command line using composer.
In this example, I am upgrading Magento 2 to version 2.1.1.

Magento »

[10 Sep 2016 | One Comment]

This article shows, how you can add a new column at the end of the admin grid or after any column of the admin grid in Magento 1.x.
Suppose, you have a custom module and you need to add a column to product grid or order grid, etc. For this, you need to rewrite that particular grid block with your custom module’s block grid class.

Magento, Magento 2 »

[5 Sep 2016 | One Comment]

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 simply be using ObjectManager for this example.

Magento, Magento 2 »

[29 Aug 2016 | No Comment]

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 to instantiate the resource class.

Magento, Magento 2 »

[15 Aug 2016 | No Comment]

This article shows how to run Magento 2 code in an external file/script. The external file can be inside the Magento root folder or outside of it.
This example considers that the file is present in the Magento 2 root folder. Let us name the file as abc.php. So, we want to execute some code when we open http://our-magento-site.com/abc.php

Magento, Magento 2 »

[8 Aug 2016 | No Comment]

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

Magento, Magento 2 »

[2 Aug 2016 | No Comment]

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 other modules.
Let’s suppose your module is named YourCompany_YourModule.

Magento, Magento 2, Magento Extension »

[25 Jul 2016 | No Comment]

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.

Magento, Magento 2 »

[18 Jul 2016 | No Comment]

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 app/code/YourCompany/YourModule/etc/adminhtml/events.xml.
Remember that, you need to place your Observer class in app/code/YourCompany/YourModule/Observer/ directory.

Magento, Magento 2 »

[14 Jul 2016 | No Comment]

I am getting the following error while adding a new module to my Magento 2 installation and running the command on terminal php bin/magento setup:upgrade.
[InvalidArgumentException] There are no commands defined in the “setup” namespace

Magento »

[7 Jul 2016 | No Comment]

This article provides a solution to the error occurred while accessing Payment methods section in Magento admin panel.
Problem:

Magento, Magento 2 »

[27 Jun 2016 | No Comment]

This article shows how to create and run cronjob in a custom module in Magento 2. To know about general details about setting up and running cron on Magento 2, you may refer to this official documentation. This documentation will show you how you can create cron job on web server as well.
Here, we will focus on creating / setting up / running cron for a custom Magento 2 module.

Magento, Magento 2 »

[23 Jun 2016 | No Comment]

This article shows how get height and width of the media images in Magento 2.
In this example, we will load product by id or sku and then fetch and display height and width of product small image.
To load the product, we will be using Magento 2’s Service Layer for this task. Use of Service Layer is highly encouraged by Magento.