Username or Email
Password:
Forgot Password
This script i made will show the collection of products with in a set of categories. i just have problems with getProductCollection. It seems that it doesnt give me the product collection for the current category in the loop.
$_main_categories=$this->helper('catalog/category')->getStoreCategories();if($_main_categories->count()): foreach ($_main_categories as $_main_category): if($_main_category->getIsActive()): foreach ($_main_category->getChildren() as $_main_category_sub): echo "Category:" . $_main_category_sub->getName() . "<br />"; if($_main_category_sub->getProductCollection()){ foreach ($_main_category_sub->getProductCollection() as $_main_category_sub_products): echo "Product:" . $_main_category_sub_products->getName() . "<br />"; endforeach; } endforeach; endif; endforeach;endif;
you have to call ->load() on the collection to fill it
Thanks roderick but can you give me a script on how to implement the load? tired it a couple of times but i cant seem to get the solution on load.
$products = $category->getProductCollection()->addCategoryFilter($category)->addAttributeToSelect('*'); $products->load(); foreach ( $products->toArray() as $product ) { var_dump($product); }
Hi,
it should be $_category->load();
cheers
mzentrale | eCommerce - eBusiness Agentur für eCommerce Beratung, Entwicklung & Marketing. Magento™ Silver Partner ----
Thanks for the Post. I was seaching for hours on how to do this.
~ Mike D http://www.sharpdotinc.com http://www.sharpdotinc.com/mdost
You could also try this for a specific category…
Thanks to @Lee Saferite.
In your .phtml file, you’ll read a line of code similar to this:
$_productCollection=$this->getLoadedProductCollection();
Go underneath and ADD the following (where $cat_id corresponds to the id of the product category you want to display):
$cat_id = 6; // category_id for "specific category"$_productCollection = Mage::getResourceModel('catalog/product_collection')->addCategoryFilter(Mage::getModel('catalog/category')->load($cat_id));
Thanks, Lee
LeeTaylorDoes Web Consulting & Development leetaylordoes.com Skype: leetaylordoes