Home » Archive

Articles tagged with: category

Magento »

[7 Aug 2010 | 2 Comments | 253 views]

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 | One Comment | 281 views]

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 | 7 Comments | 3,192 views]

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 | No Comment | 1,392 views]

You can get current category from the following code:

$currentCategory = Mage::registry(‘current_category’);

You can get the parent category from the following code:

Magento »

[21 Dec 2009 | 3 Comments | 2,251 views]

Here, I will be showing you the code to get sub categories of a particular category and the number of products (product count) present in the sub categories.
Like, I have a category named Furniture. The sub categories under Furniture are Living Room and Bedroom. Now, I want to show the sub categories under Funiture and the products associated with the sub categories (Living Room and Bedroom).

Magento »

[7 Dec 2009 | 2 Comments | 2,129 views]

$product->getCategoryIds() gives array of category ids which the product is associated to. We can loop through this array and load each category to get the category name and url.

<?php
/**
* get categories from a product
*/
$categoryIds = $product->getCategoryIds();
/**
* looping through the array of category ids
*/
foreach($categoryIds as $categoryId) {
$category = Mage::getModel(‘catalog/category’)->load($categoryId);
?>
Category: <a href="<?php echo $category->getCategoryUrl() ?>"><?php echo $category->getName() ?></a><br/>
<?php
}
?>