2017-02-16 35 views
0

我已经有很好的工作代码,通过stock_status对我的类别列表进行排序。换句话说,我已经缺货了。 但我还需要在我之前插入一些代码,以便对那些仅缺货的产品进行分类。Magento 1.9 - 如何在两次条件下对产品进行分类?

例如:

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 

这是惊人的我,因为我需要在库存产品进行排序通过名称(或通常在前端的任何其他选择),但同时我需要通过product_views属性来清理缺货产品。

,我需要有排序是这样的(如果我的名字,例如在前端选择排序)名单:

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) 

现在,我使用的第二级排序的代码(和我请你帮我找到product_views 1级排序,但只能进行排序脱销产品):

try { 
      $websiteId = Mage::app()->getStore()->getWebsiteId(); 
      if (Mage::helper('catalog')->isModuleEnabled('Mage_CatalogInventory')) { 


       $stockStatusFieldExisted = Mage::helper('webpiercom_outofstockmastmndmostviewed_catalog')->checkFieldExisted($collection->getSelect(), 'stock_status'); 

       if(!$stockStatusFieldExisted) { 
        $collection->joinTable(
         array('wprdc' => 'cataloginventory/stock_status'), 
         'product_id=entity_id', 
         array('stock_status'), 
         array('website_id' => $websiteId), 
         'left' 
        ); 

       } 
      } 
      $collection->getSelect()->order('stock_status desc'); 
     } 
+0

更新标题主要是 –

+0

你是什么意思? –

+0

对不起,这只是我编辑的 –

回答

0

我会看我调整应用程序/本地/法师/目录/产品/列表/ toolbar.php。 找出setCollection函数。 凡拨打电话是

$this->_collection->setOrder(
    $this->getCurrentOrder(), 
    $this->getCurrentDirection()) 

您可以堆积排列顺序。 既然你想要的股票首先,我建议做一些像

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

这是未经测试,因为我没有任何我的网站的股票过滤器,但我用其他字段名强制默认这种技术第二和第三级排序。

相关问题