2017-02-13 4 views
0

私はこの奇妙な問題を抱えています。誰かが間違っていることを指摘できますか?私は位置に関連するカテゴリの製品を表示したいMagento 2 Product Collectionはクエリを表示します

は、私は\ Magentoの\カタログを拡張し、私のモジュールでは、次の列で、別のテーブルに

id, category_id, product_id, position 

を追加しました\ブロック\製品\ ListProduct と\ ListProductファイルでMagentoの\カタログ\ブロック\製品\ ProductList \ツールバー

、私は_getProductCollectionメソッドをオーバーライドして、次の

$joinConditions = array(); 
      $joinConditions[] = 'e.entity_id = rs.product_id'; 
      $joinConditions[] = 'rs.category_id = ' . $category->getId(); 
      $this->_productCollection->getSelect()->joinLeft(
        ['rs' => 'my_new_table'], implode(' AND ', $joinConditions), ['position'] 
      ); 
を追加

とツールバーに、私はsetCollection方法

switch ($this->getCurrentOrder()) 
     { 
      case 'position': 
       if ($this->getCurrentDirection() == 'desc') 
       { 
        $this->_collection 
          ->getSelect() 
          ->order('rs.position DESC'); 
       } elseif ($this->getCurrentDirection() == 'asc') 
       { 
        $this->_collection 
          ->getSelect() 
          ->order('rs.position ASC'); 
       } 
       break; 

      default: 

       if ($this->getCurrentOrder()) 
       { 
        $this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection()); 
       } 
       break; 
     } 

を上書きするには、私が正しい結果を得るが、FULLクエリは、すべてのカタログページに表示されます。私は自分のコードでどこでもチェックしました。私はどこでもクエリを印刷しません。私は次関数から 'RS' を削除し、ツールバーのクラスでは

case 'position': 
        if ($this->getCurrentDirection() == 'desc') 
        { 
         $this->_collection 
           ->getSelect() 
           ->order('position DESC'); 
        } elseif ($this->getCurrentDirection() == 'asc') 
        { 
         $this->_collection 
           ->getSelect() 
           ->order('position ASC'); 
        } 
        break; 

TO

case 'position': 
        if ($this->getCurrentDirection() == 'desc') 
        { 
         $this->_collection 
           ->getSelect() 
           ->order('rs.position DESC'); 
        } elseif ($this->getCurrentDirection() == 'asc') 
        { 
         $this->_collection 
           ->getSelect() 
           ->order('rs.position ASC'); 
        } 
        break; 

を変更した場合に最良の部分です。注文はmagentoのデフォルトの位置に戻ります。クエリはもう表示されません

すべてのアイデア?

答えて

0

私はそう考えると、あなたはそれからgetSelect()を取り除いて再度チェックするべきだと思います。

関連する問題