Home » Archive

Articles in the Magento Category

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.

Magento »

[18 Apr 2016 | No Comment]

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 in need to make the “Add to Wishlist” behave exactly like “Add to Cart”. The other benefit of doing so (asking user to choose configurable options while adding to wishlist) is that when you move the …

Magento, Magento 2 »

[14 Apr 2016 | No Comment]

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:

Magento »

[11 Apr 2016 | No Comment]

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