2011-11-10 17 views
0

Magentoの商品リストに「提案」を表示したいと思います。私はYes/Noとグローバルなアクティブな "Suggestion"という属性を作った。ここでは、最初に提案を表示してから、テキストと素材、残りの製品を表示したいと考えています。Magentoの属性に基づく商品リスト

は、私はこのようにそれを試してみました:

$_productCollection=$this->getLoadedProductCollection() 
/* .... */ 
$_productCollection->clear()->addAttributeToFilter('suggestion', 1)->load(); 

しかし、これは例外で終わる:

あなたは今回以上

'_price_rule' 相関名を定義することはできません質問は、これを解決する方法ですか?

答えて

0

私にとっての解決策は、リスト機能を拡張するカスタムモジュールでした。その後

protected function _getProductCollectionSuggestion() 
{ 
    $layer = Mage::getSingleton('catalog/layer'); 
    /* @var $layer Mage_Catalog_Model_Layer */ 
    if ($this->getShowRootCategory()) { 
     $this->setCategoryId(Mage::app()->getStore()->getRootCategoryId()); 
    } 

    // if this is a product view page 
    if (Mage::registry('product')) { 
     // get collection of categories this product is associated with 
     $categories = Mage::registry('product')->getCategoryCollection() 
      ->setPage(1, 1) 
      ->load(); 
     // if the product is associated with any category 
     if ($categories->count()) { 
      // show products from this category 
      $this->setCategoryId(current($categories->getIterator())); 
     } 
    } 

    $origCategory = null; 
    if ($this->getCategoryId()) { 
     $category = Mage::getModel('catalog/category')->load($this->getCategoryId()); 
     if ($category->getId()) { 
      $origCategory = $layer->getCurrentCategory(); 
      $layer->setCurrentCategory($category); 
     } 
    } 
    $this->_productCollection = $layer->getProductCollection(); 
    $this->_productCollection->addAttributeToFilter('suggestion', 1); 
    if($this->_productCollection->count()) { 
     foreach($this->_productCollection as $_productKey => $_product) { 
      if($_product->getSuggestion() == 0 || !$_product->getSuggestion()) { 

      } 
     } 
    } 

    $this->prepareSortableFieldsByCategory($layer->getCurrentCategory()); 

    if ($origCategory) { 
     $layer->setCurrentCategory($origCategory); 
    } 
    return $this->_productCollection; 
} 

/app/code/local/Mage/Catalog/Block/Product/List.php以下の拡張コードで

:私は、次のファイルを追加しました私はこのメソッドをList.phtmlにロードし、それは働いた:) とにかく読んでいただきありがとうございます!多分このコードは誰かを助けます!

関連する問題