0

カテゴリの問題の下にあるすべての製品を取得しようとすると、コードに問題があります。私が間違っていることについて何か助けていただければ幸いです。これが私のコードです。

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

 $category = Mage::getModel('catalog/category')->load($categoryId);
 $_productCollection = Mage::getModel('catalog/category')
 ->getCollection()
 ->addAttributeToSelect('*')
 ->addAttributeToFilter('category_id',$category)
 ->setOrder('entity_id', 'DESC')
 ->load()
 ;
4

3 に答える 3

2
$category = Mage::registry('current_category'); // object of class Mage_Catalog_Model_Category, not id
$_productCollection = $category->getProductCollection(); // you have this method in the class
于 2013-08-27T07:55:06.077 に答える
0

category/view.phtml ですべての製品を取得しようとしている場合

以下はコードです

$category = $this->getCurrentCategory();

$categoryId = $category->getId();

$_productCollection = Mage::getModel('catalog/category')->load($categoryId)
->getProductCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('status', 1)
->setOrder('entity_id', 'DESC');

foreach($_productCollection as $product)
{
    echo $product->getName();
}
于 2013-08-27T08:45:07.330 に答える