Magento - 获取当前类别中的所有产品
Magento - Get all products in the current category
我在这里尝试实现的目标还有另一个问题:
基本上应该发生的是,对于当前类别,如果产品的属性具有三个值之一,那么它应该显示在页面顶部,描述下方。
虽然发生了什么,但它只是循环浏览当前页面上的产品。我认为问题出在 list.phtml 文件中:
foreach ($_productCollection as $_product);
那么有人知道我如何在所有页面上获取和循环浏览当前类别中的所有产品吗?
我自己想出来了。
$category_id = Mage::getModel('catalog/layer')->getCurrentCategory()->getId();
$category = Mage::getModel('catalog/category')->load($category_id);
$products = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('*')
->addCategoryFilter($category)
->setOrder('price', 'ASC')
->load();
作为您的答案,您需要显示您在以下 collection
中获得的产品
$category_id = Mage::getModel('catalog/layer')->getCurrentCategory()->getId();
$category = Mage::getModel('catalog/category')->load($category_id);
$products = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('*')
->addCategoryFilter($category)
->setOrder('price', 'ASC')
->load();
然后您需要根据要求获得第二次产品 collection 才能获得其余产品:
$_testproductCollection = Mage::getResourceModel('catalog/product_collection')
->joinField('category_id','catalog/category_product','category_id','product_id=entity_id',null,'left')
->addAttributeToFilter('category_id', array('nin' => $category_id))
->addAttributeToSelect('*');
$_testproductCollection->load();
我在这里尝试实现的目标还有另一个问题:
基本上应该发生的是,对于当前类别,如果产品的属性具有三个值之一,那么它应该显示在页面顶部,描述下方。
虽然发生了什么,但它只是循环浏览当前页面上的产品。我认为问题出在 list.phtml 文件中:
foreach ($_productCollection as $_product);
那么有人知道我如何在所有页面上获取和循环浏览当前类别中的所有产品吗?
我自己想出来了。
$category_id = Mage::getModel('catalog/layer')->getCurrentCategory()->getId();
$category = Mage::getModel('catalog/category')->load($category_id);
$products = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('*')
->addCategoryFilter($category)
->setOrder('price', 'ASC')
->load();
作为您的答案,您需要显示您在以下 collection
中获得的产品$category_id = Mage::getModel('catalog/layer')->getCurrentCategory()->getId();
$category = Mage::getModel('catalog/category')->load($category_id);
$products = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('*')
->addCategoryFilter($category)
->setOrder('price', 'ASC')
->load();
然后您需要根据要求获得第二次产品 collection 才能获得其余产品:
$_testproductCollection = Mage::getResourceModel('catalog/product_collection')
->joinField('category_id','catalog/category_product','category_id','product_id=entity_id',null,'left')
->addAttributeToFilter('category_id', array('nin' => $category_id))
->addAttributeToSelect('*');
$_testproductCollection->load();