【问题标题】:Magento > Catalog Product List > Want to add orderBy with calculMagento > 目录产品列表 > 想要通过计算添加 orderBy
【发布时间】:2013-01-14 14:30:31
【问题描述】:

我有这个:

$this->_productCollection = $layer->getProductCollection() ->addAttributeToSort('special_price', 'desc');

我想做类似的事情:

$this->_productCollection = $layer->getProductCollection() ->addAttributeToSort('special_price*100/price', 'desc');

实际上,我的促销/销售百分比并未保存在我的数据库中。但我想按这个百分比排序(使用 Mage Core 或 SQL)。我可以这样做还是必须使用php?

我尝试自定义 Select 但没有成功

谢谢

【问题讨论】:

    标签: magento


    【解决方案1】:

    您可以在数据库中创建附加列并将其命名为“my_special_price”。 但更好的方法是使用 PHP。

    【讨论】:

    • 谢谢。有没有办法用 Magento Query(使用集合)来做到这一点?
    【解决方案2】:

    我终于找到了办法。

    ->addExpressionAttributeToSelect("pourcentage", "((100-({{special_price}}/price)*100))","special_price")
                ->addAttributeToSort("pourcentage","desc");
    

    查询后我不需要对集合进行排序!!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多