- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2016
10:17 AM
06-24-2016
10:17 AM
How to display products subcategories in parent categories?
Hello,
I would like show products subcategories in parent category but I don't check a parent category.
Because the parent category is empty.
Do you understand me?
Regards
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2016
10:57 PM
06-26-2016
10:57 PM
Re: How to display products subcategories in parent categories?
Hi Em,
Please check below code:-
<?php $currentCat = Mage::registry('current_category'); if ( $currentCat->getParentId() == Mage::app()->getStore()->getRootCategoryId() ) { // current category is a toplevel category $loadCategory = $currentCat; } else { // current category is a sub-(or subsub-, etc...)category of a toplevel category // load the parent category of the current category $loadCategory = Mage::getModel('catalog/category')->load($currentCat->getParentId()); } $subCategories = explode(',', $loadCategory->getChildren()); foreach ( $subCategories as $subCategoryId ) { $cat = Mage::getModel('catalog/category')->load($subCategoryId); $category_id =$cat->getId(); // if you know static category then enter number $catagory_model = Mage::getModel('catalog/category')->load($subCategoryId); $collection = Mage::getResourceModel('catalog/product_collection'); $collection->addCategoryFilter($catagory_model); //category filter $collection->addAttributeToFilter('status',1); //only enabled product $collection->addAttributeToSelect(array('name','url','small_image')); //add product attribute to be fetched $collection->getSelect()->order('rand()'); //uncomment to get products in random order $collection->addStoreFilter(); if(!empty($collection)){ foreach ($collection as $_product):?> <a href="<?php echo $_product->getProductUrl();?>"><?php echo $_product->getName();?> </a> <?php endforeach; } } ?>
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2016
06:01 AM
06-28-2016
06:01 AM
Re: How to display products subcategories in parent categories?
You can also see this
http://www.blog.plazathemes.com/archives/2429
OpenSource Expert | OpenSource Technologies | www.opensourcetechnologies.com
Magento plugins released: http://www.opensourcetechnologies.com/product/product-category/magento-extensions
Magento plugins released: http://www.opensourcetechnologies.com/product/product-category/magento-extensions
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2016
11:47 PM
07-03-2016
11:47 PM
Re: How to display products subcategories in parent categories?
Thanks you,
I see the code but where should I put to prove it?
Regards,
Juan