【发布时间】:2011-12-15 09:15:54
【问题描述】:
我想在 magento 的单个页面上显示所有类别(带有名称、描述等详细信息)及其产品(带有名称、价格、添加到购物车选项等)。
请建议,如何做到这一点?
提前致谢!
最好的问候,
【问题讨论】:
-
这个问题不够具体。你遇到了什么问题?
标签: magento
我想在 magento 的单个页面上显示所有类别(带有名称、描述等详细信息)及其产品(带有名称、价格、添加到购物车选项等)。
请建议,如何做到这一点?
提前致谢!
最好的问候,
【问题讨论】:
标签: magento
$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>';
}
}
【讨论】:
获取所有产品:
$collection = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('*');
foreach ($collection as $product) {
echo $product->getName() . "<br />";
}
link 复制自哪里
并获取所有类别:
$categories = Mage::getModel('catalog/category')
->getCollection()
->addAttributeToSelect('*');
link 复制自
【讨论】: