Question:Assuming that trees must have categories as parents and products as children, and that there are no sub-categories under main categories, which of the following code samples will get the full catalog tree? 

A $categories = Mage::getModel('catalog/category') ->getCollection(); foreach ($categories as $category) { print $category->getName(); $categoryDetails = Mage::getModel('catalog/category')->load($category->getId()); $products = $categoryDetails->loadChildProducts(); foreach($products as $product){ Print $product->getName(); } } 

B $categories = Mage::getModel('catalog/category') ->getCollection(); foreach ($categories as $category) { print $category->getName(); $products = Mage::getModel('catalog/category') ->load($category->getId()) ->getProductCollection(); foreach($products as $product){ Print $product->getName(); } } 

C $categories = Mage::getModel('catalog/category') ->getCollection() ->setLoadProducts(true); foreach ($categories as $category) { print $category->getName(); foreach($category->getProducts() as $product){ print $product->getName(); } } 

D $products = Mage::getModel('catalog/product') ->getCollection(); foreach ($products as $product) { print $product->getCategory()->getName(); print $product->getName(); } 

+ Answer
+ Report
Total Preview: 721

Copyright © 2024. Powered by Intellect Software Ltd