2017-02-16 5 views
0

私は既によくわかりました、そして、実際には、私のカテゴリリストをstock_statusでソートしました。他の言葉私は底に在庫切れの商品があります。 しかし、私は在庫切れの製品のその部分をソートするために私の前にいくつかのコードを挿入する必要があります。例えばMagento 1.9 - 二重条件で製品を2回ソートする方法は?

:私は在庫品でソートする必要があるため

Product4 
Product5 
Product6 
Product1 
Product2 
Product3 

これは私のために素晴らしいです:

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 

今私は、ソート名前であれば、これは結果持っています名前(または通常はフロントエンドの任意の他の選択肢)でも、同時に私は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) 

今私は2番目の並べ替えレベル(と私のためにこのコードを使用)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()); 

私は私のサイトのいずれに株式フィルタを持っていないので、これは未テストですが、私はデフォルトを強制的に他のフィールド名で、この技術を使用するような何かをやってお勧めしたいです第2および第3レベルのソート。

関連する問題