使用属性的Magento产品排序顺序

时间:2013-08-14 04:58:33

标签: magento sorting custom-attributes

我正在开发一个magento网站。

现在我正在尝试按特定顺序显示我的产品。

为此我添加了一个名为'display_order'的属性并链接到属性集(常规)。然后我手动在每个产品中添加了订单。

这些是我使用的代码。我的产品具有不同的属性集。

第一个

$_productCollection = Mage::getModel('catalog/product')->getCollection();
$_productCollection->addAttributeToSelect('*');
$_productCollection->addAttributeToFilter('display_order', array('gt' => 0));
$_helper = $this->helper('catalog/output');

第二个

$_productCollection = Mage::getModel('catalog/product')->getCollection();
$_productCollection->addAttributeToSelect('*');
$_productCollection->addAttributeToSort('display_order', 'ASC');
$_helper = $this->helper('catalog/output'); 

我按照排序顺序获取产品,但是存在一个小问题,它只根据类似的属性集进行排序。

即;具有相同类型属性的产品首先按排序设置,然后它将对具有相同属性集的其他产品进行排序等等。

所以我没有按照'display_order'

的顺序得到正确的订单

有没有办法按照我给出的顺序准确地得到它而不考虑产品所在的属性集。

请帮帮我。

提前致谢。

- Tibin Mathew

2 个答案:

答案 0 :(得分:4)

Mangeto更改产品显示顺序的默认方式是转到:

  1. 目录>分类>管理类别

  2. 在左侧列中单击要编辑的类别。

  3. 点击右侧栏中的“类别产品”标签。

  4. 在此处更改排序顺序。

  5. Reference

答案 1 :(得分:0)

对于前端使用此代码,我在这里创建了自定义属性" product_sort_order"。

$website_id = Mage::app()->getWebsite()->getId();
$storeId =  Mage::app()->getStore()->getId();            
$collection = Mage::getModel('catalog/product')
   ->setStoreId($storeId)
   ->getCollection() 
   ->addAttributeToSelect('*') 
   ->addWebsiteFilter($website_id)
   ->addAttributeToFilter('type_id', array('eq' => 'simple'));
$collection->getSelect()->limit(6);
$collection->addAttributeToSort('product_sort_order', Varien_Data_Collection::SORT_ORDER_DESC);