Как отобразить все категории и их продукты на одной странице в magento - PullRequest
0 голосов
/ 15 декабря 2011

Я хотел отобразить все категории (с подробностями, такими как имя, описание и т. Д.) И их продукты (с названием, ценой, возможностью добавления в корзину и т. Д.) На одной странице в magento.Подскажите пожалуйста, как это можно сделать?

Заранее спасибо!

С наилучшими пожеланиями,

Ответы [ 2 ]

0 голосов
/ 16 декабря 2011
$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 голосов
/ 15 декабря 2011

Чтобы получить все продукты:

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

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

ссылка , куда она скопирована с

и получить все категории:

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

ссылка скопирована с

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...