Home » Archive

Articles in the Magento Category

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.

Magento, Magento 2 »

[16 Jun 2016 | No Comment]

This article shows how to resize product image in Magento 2. In this example, we will be loading a product by id or sku and then resizing its image. We will also be injecting the object of Catalog Helper Image class for image resize purpose.
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.

Magento, Magento 2 »

[6 Jun 2016 | No Comment]

This article shows how to get stock quantity (qty) of a product in Magento 2. We can also fetch other stock information like minimum quantity (min_qty), minimum sale quantity (min_sale_qty), maximum sale quantity (max_sale_qty), see if a product is in stock (is_in_stock), etc.
We will be using Magento 2’s Service Layer for this task. Use of Service Layer is highly encouraged by Magento.

Magento, Magento 2 »

[1 Jun 2016 | No Comment]

This article shows how to load product by id and sku in Magento 2.
We will be using Magento 2’s Service Layer for this task. Use of Service Layer is highly encouraged by Magento.
Below is a block class of my custom module (Chapagain_HelloWorld). I have injected object of \Magento\Catalog\Model\ProductRepository class in the constructor of my module’s block class.

Magento, Magento 2 »

[27 May 2016 | No Comment]

This article shows how we can get list of all categories and all category of current store in Magento 2.
Below is a block class of my custom module (Chapagain_HelloWorld). I have injected object of \Magento\Catalog\Model\ResourceModel\Category\CollectionFactory and \Magento\Catalog\Helper\Category classes in the constructor of my module’s block class.

Magento, Magento 2 »

[19 May 2016 | No Comment]

This article shows how we can get the URL and ALT text of a Logo of the Magento 2 website. The article also include code to fetch Logo Height and Width.
Logo Image Width and Logo Image Height is fetched from Configuration Settings (Stores -> Settings -> Configuartion -> General -> Design -> Header).

Magento, Magento 2 »

[16 May 2016 | No Comment]

This article shows how we can get name of the current module, controller name, action name and route name in Magento 2.
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.

Magento, Magento 2 »

[12 May 2016 | No Comment]

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

Magento, Magento 2 »

[9 May 2016 | No Comment]

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.

Magento, Magento 2 »

[5 May 2016 | No Comment]

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 object of StoreManagerInterface in the constructor of my module’s block class.

Magento, Magento 2 »

[28 Apr 2016 | One Comment]

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.
Below is a block class of my custom module (Chapagain_HelloWorld). I have injected object of StoreManagerInterface & Currency in the constructor of my module’s block class.