2011-12-15 148 views
0

我想顯示所有類別(包括名稱,說明等詳細信息)及其產品(包含名稱,價格,添加到購物車選項等)。 )在magento的單個頁面上。如何在magento的單個頁面上顯示所有類別及其產品

請建議,如何做到這一點?

在此先感謝!

最好的問候,

+0

這個問題不夠具體。你遇到什麼問題? – 2011-12-15 10:54:33

回答

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>'; 
    } 
} 
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從複製

相關問題