You can use this code to retrieve any attribute of a Magento category:
|
1 |
$attributeValue = $category->getData('attribute_code'); |
You can use this code to retrieve any attribute of a Magento category:
|
1 |
$attributeValue = $category->getData('attribute_code'); |
If you enable the flat categories in your Magento store, some code that gets children of a given category might stop working. The following code can be used to get all the cildren of a given category with enabled flat…
If flat categories are enabled in your Magento store, you need to load the child categories of a given category differently. The following code shows how:
|
1 2 3 4 5 |
$category = Mage::getModel('catalog/category')->load($id); $childCategories = $category ->getCollection() ->addAttributeToSelect(array('name', 'image', 'description')) ->addIdFilter($category->getChildren()); |
Use this code to retrieve the value (rather than the ID) of a category attribute: $value = $currentCategory->getResource()->getAttribute(‘attribute_identifier’)->getFrontend()->getValue($currentCategory);
The following code returns all products from within a certain category in a collection.
|
1 2 3 |
// category id = 5 // addAttributeToSelect is optional $products = Mage::getModel('catalog/category')->load(5)->getProductCollection()->addAttributeToSelect('*'); |
Use the following code to get a Magento categories parent category.
|
1 |
Mage::getSingleton('catalog/layer')->getCurrentCategory()->getParentCategory(); |
While being on the Magento category page, it might be useful to display the category name. Use the following code to do so.
|
1 |
Mage::getSingleton('catalog/layer')->getCurrentCategory()->getName(); |
To get a categories URL by category id, use the following code:
|
1 2 |
$categoryId = 55; $url = Mage::getModel("catalog/category")->load($categoryId)->getUrl(); |