Php Magento 1.9-如何在双重条件下对产品进行两次排序?

Php Magento 1.9-如何在双重条件下对产品进行两次排序?,php,sorting,magento,Php,Sorting,Magento,我已经有很好的和工作的代码排序我的类别清单的股票_状态。换句话说,我在底部有缺货的产品。 但是,我还需要在我的应用程序之前插入一些代码,以便对仅缺货的部分产品进行排序 例如: Product1 have Qty=0 and product_views attribute=97 Product2 have Qty=0 and product_views attribute=902 Product3 have Qty=0 and product_views attribute=75 Product4

我已经有很好的和工作的代码排序我的类别清单的股票_状态。换句话说,我在底部有缺货的产品。 但是,我还需要在我的应用程序之前插入一些代码,以便对仅缺货的部分产品进行排序

例如:

Product1 have Qty=0 and product_views attribute=97
Product2 have Qty=0 and product_views attribute=902
Product3 have Qty=0 and product_views attribute=75
Product4 have Qty=35 and product_views attribute=1500
Product5 have Qty=398 and product_views attribute=5298
Product6 have Qty=275 and product_views attribute=17
Product4
Product5
Product6
Product1
Product2
Product3
Product4
Product5
Product6 (this is in stock products that because it must be sorted as usually based on choice of selectbox in frontend)
Product2
Product1
Product3 (this is out of stock products that because it must be sorted by product_views attrubute - most viewed in top)
现在,如果按名称排序,我会得到以下结果:

Product1 have Qty=0 and product_views attribute=97
Product2 have Qty=0 and product_views attribute=902
Product3 have Qty=0 and product_views attribute=75
Product4 have Qty=35 and product_views attribute=1500
Product5 have Qty=398 and product_views attribute=5298
Product6 have Qty=275 and product_views attribute=17
Product4
Product5
Product6
Product1
Product2
Product3
Product4
Product5
Product6 (this is in stock products that because it must be sorted as usually based on choice of selectbox in frontend)
Product2
Product1
Product3 (this is out of stock products that because it must be sorted by product_views attrubute - most viewed in top)
这对我来说是令人惊讶的,因为我需要按名称(或通常在前端的任何其他选择)对库存产品进行排序,但同时我需要按产品视图属性对库存产品进行排序

我需要对列表进行如下排序(例如,如果我在前端选择按名称排序):

Product1 have Qty=0 and product_views attribute=97
Product2 have Qty=0 and product_views attribute=902
Product3 have Qty=0 and product_views attribute=75
Product4 have Qty=35 and product_views attribute=1500
Product5 have Qty=398 and product_views attribute=5298
Product6 have Qty=275 and product_views attribute=17
Product4
Product5
Product6
Product1
Product2
Product3
Product4
Product5
Product6 (this is in stock products that because it must be sorted as usually based on choice of selectbox in frontend)
Product2
Product1
Product3 (this is out of stock products that because it must be sorted by product_views attrubute - most viewed in top)
现在,我使用此代码进行二级排序(请您帮助我查找按产品视图进行的一级排序。但必须仅对缺货产品进行排序):


我会考虑调整我的app/local/Mage/Catalog/Product/list/toolbar.php。 查找
setCollection
功能。 电话在哪里

$this->_collection->setOrder(
    $this->getCurrentOrder(), 
    $this->getCurrentDirection())
你可以把排序单叠起来。 既然你想先买股票,我建议你

$this->_collection
    ->setOrder('stock_status', 'desc')
    ->setOrder(
        $this->getCurrentOrder(),
        $this->getCurrentDirection());

这是未经测试的,因为我的任何网站上都没有股票过滤器,但我将此技术与其他字段名一起使用,强制进行默认的第二级和第三级排序。

更新标题主要是什么意思?抱歉,这只是我所做的编辑