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

发布于 2024-12-21 19:38:09 字数 116 浏览 0 评论 0原文

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

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

提前致谢!

此致,

I wanted to display all categories ( with detail like name. description etc..) and their products ( with name, price,add to cart option etc..) on a single page in magento.

Please suggest, how this can be done?

Thanks in advance!

Best Regards,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ゞ花落谁相伴 2024-12-28 19:38:09
$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>';
   }
}
$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>';
   }
}
巴黎夜雨 2024-12-28 19:38:09

要获取所有产品:

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

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

链接,从其中复制

并获取所有类别:

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

链接复制自

To get all products :

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

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

link where it is copied from

and to get all the categories :

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

link copied from

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文