Home » Archive

Articles tagged with: category

Magento, Magento 2 »

[19 Sep 2016 | 3 Comments]

This article shows how we can get list of all categories from current product or any particular product as well.
Both ways (Dependency Injection & Object Manager way) are shown below:

Magento, Magento 2 »

[27 May 2016 | One 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 »

[4 Mar 2016 | 4 Comments]

This article shows how we can get parent category, children categories and total number of products in a category in Magento 2.
Below is a block class of my custom module (Chapagain_HelloWorld). I have injected object of \Magento\Catalog\Model\CategoryFactory class in the constructor of my module’s block class.

Magento, Magento 2 »

[1 Mar 2016 | 5 Comments]

This article shows how we can get all products of a particular category in Magento 2.
Both Dependency Injection and Object Manager way of coding is shown below.
Using Dependency Injection (DI)

Magento, Magento 2 »

[12 Feb 2016 | 4 Comments]

This article shows how we can get current category and current product data in Magento 2.
Below is a block class of my custom module (Chapagain_HelloWorld). I have injected object of \Magento\Framework\Registry class in the constructor of my module’s block class.
app/code/Chapagain/HelloWorld/Block/HelloWorld.php

Magento »

[23 Jun 2015 | No Comment]

Here is a quick code to get all products from a particular/specified category in Magento.
First of all, you need to load the category (whose products you want to display) and get it’s ID. You can load a category by it’s ID or if you are in a category page then you can get category information from Magento registry. I have included code to load category in both ways.
You can fetch all enabled or disabled and visible or not visible products. We create ‘not visible’ products while creating configurable type …

Magento »

[23 Dec 2013 | No Comment]

Here is a quick and complete code to load parent category from current category page and to get sub categories of parent category along with their product count.

Hope it helps. Thanks.

Magento »

[4 Oct 2010 | 15 Comments]

Here, I will show you how you can get list of all categories of your Magento Shop.
You might want to display all categories in homepage or any CMS page. There are different ways to get the category listing. Here are some:-
Get all categories

Magento »

[7 Aug 2010 | 32 Comments]

Here, I will be showing you how you can add attributes for your categories in Magento.
From the admin panel, you can only add attributes to product. To add attributes to category, you need to write sql query in your phpmyadmin or a better way would be creating a new custom module and adding attributes to category from the mysql setup file of the module.
By mysql setup file, I mean the file inside the directory YourNamespace/YourModule/sql/yourmodule_setup/

Magento »

[22 Jul 2010 | 11 Comments]

Scenario:
I have a fresh installation of Magento 1.4. I already have installed the sample data for Magento.
Now, when I go to the category listing page, no products are displayed. It says “There are no products matching the selection.“.

Magento, MySQL »

[31 Dec 2009 | 20 Comments]

Suppose, you have a product collection and you want to filter it by category. Suppose, you want to filter it by more than one category. You can use addCategoryFilter if you have only one category. But, what if you want to filter by more than one category?
Category ids are stored for product in a comma separated way. So, to filter product collection by more than one category, you have to use:
addAttributeToFilter(‘category_ids’,array(‘finset’=>$categoryIds));

Magento »

[22 Dec 2009 | 2 Comments]

This article shows how to get category information (category name, id, description, url, etc.) of the category page you are in. Along with the information of the parent category of the currently viewed category.
Get current category

Magento »

[21 Dec 2009 | 17 Comments]

This article shows how to get sub categories of a particular category and the number of products (product count) present in the sub categories.
Suppose, you have a category named Furniture. The sub categories under Furniture are Living Room and Bedroom. Now, you want to show the sub categories under Funiture and the products associated with the sub categories (Living Room and Bedroom).

Magento »

[7 Dec 2009 | 14 Comments]

This article shows how you can fetch all the categories related/associated with a particular product.
$product->getCategoryIds() function gives array of category ids with which the product is associated to. We can loop through this array and load each category to get the category name and url.