如何在magento的单个页面上显示所有类别及其产品

时间:2011-12-15 09:15:54

标签: magento

我希望在magento的单个页面上显示所有类别(包括名称,描述等等详细信息)及其产品(包括名称,价格,添加到购物车选项等)。

请建议,如何做到这一点?

提前致谢!

最诚挚的问候,

2 个答案:

答案 0 :(得分:0)

获取所有产品:

$collection = Mage::getModel('catalog/product')
                        ->getCollection()
                        ->addAttributeToSelect('*');

foreach ($collection as $product) {
    echo $product->getName() . "<br />";
}

link

复制的地方

并获取所有类别:

$categories = Mage::getModel('catalog/category')
                    ->getCollection()
                    ->addAttributeToSelect('*');

复制的

link

答案 1 :(得分:0)

$rootCategoryId = Mage::app()->getStore()->getRootCategoryId();
$category = Mage::getModel('catalog/category')->load($rootCategoryId);

// get all sub categories of the root category
$subCategory = $category->getChildrenCategories();

// display parent category of the current category
$currentCategory = Mage::registry('current_category');
echo $this->getCurrentCategory()->getParentCategory()->getName() ;

/* another sample */

$currentCategory = Mage::registry('current_category');

// display sub-category of current category
if ($currentCategory->getParentId() == Mage::app()->getStore()->getRootCategoryId())
{
   // current category top-level category
   $rootCategory = $currentCategory;
}

else {  
// current category sub category of top-level category
$rootCategory = Mage::getModel('catalog/category')->load($currentCategory->getParentId());
}  

$subCategory = explode(',', $rootCategory->getChildren());
foreach ( $subCategories as $subCategoryId )
{
   $categories = Mage::getModel('catalog/category')->load($subCategoryId);

   // get status of category
   if($categories ->getIsActive())
   {
      echo '<a href="'.$categories->getURL().'">'.$categories->getName().'</a>';
   }
}