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?

  • $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(); } }

  • $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(); } }

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

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

Просто сам методом исключения нашёл ответ.