【问题标题】:Magento product sort order using an attribute使用属性的 Magento 产品排序顺序
【发布时间】:2013-08-14 04:58:33
【问题描述】:

我正在用 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”的顺序得到正确的顺序

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

请帮帮我。

提前致谢。

-- 蒂宾·马修

【问题讨论】:

    标签: magento sorting custom-attributes


    【解决方案1】:

    在 Mangeto 中更改产品显示顺序的默认方法是:

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

    2. 点击左侧栏中要编辑的类别。

    3. 单击右侧列中的“类别产品”选项卡。

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

    【讨论】:

    • 这是正确的。但这仅适用于单个类别。如果我的产品属于不同的类别,这将不起作用。
    • @tibinmathew 没有意识到这一点,因为您的问题没有说明。似乎您必须覆盖核心 Magento 功能,以便 addAttributeToSort() 不会按属性集对产品进行分组。在我看来,这可能会导致其他领域的错误。
    • 我以为 Tibin 是在谈论前端,而不是后端......因为我也在寻找添加前端排序选项 :)
    【解决方案2】:

    对于前端使用此代码,这里我创建了自定义属性“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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-06-09
      • 2012-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多