2012-02-16 2 views
0

나는 무작위로 코드를 사용하여 magento powered shop의 홈 페이지에있는 다른 카테고리의 제품을 표시합니다. 이것은 완벽하게 작동합니다. 이제 홈 페이지에 자리 표시 자 이미지 만있는 모든 제품을 제외하고 싶습니다.홈 페이지에 자리 표시 자 이미지 (magento)로

class Mage_Catalog_Block_Product_List_Random extends Mage_Catalog_Block_Product_List 
{ 
    protected function _getProductCollection() 
    { 
     if (is_null($this->_productCollection)) { 
      $categoryID = $this->getCategoryId(); 
      if($categoryID) 
      { 
       $category = new Mage_Catalog_Model_Category(); 
       $category->load($categoryID); // this is category id 
       $collection = $category->getProductCollection(); 
      } else 
      { 
       $collection = Mage::getResourceModel('catalog/product_collection'); 
      } 
      Mage::getModel('catalog/layer')->prepareProductCollection($collection); 
      $collection->getSelect()->order('rand()'); 
      $collection->addStoreFilter(); 
      $numProducts = $this->getNumProducts() ? $this->getNumProducts() : 3; 
      $collection->setPage(1, $numProducts)->load(); 

      $collection->addAttributeToFilter(
       array('attribute' => 'small_image', 'eq' => ''), 
       array('attribute' => 'small_image', 'eq' => 'no_selection') 
      ); 

      $this->_productCollection = $collection; 
     } 
     return $this->_productCollection; 
    } 
} 

을하지만이 작동하지 않습니다 만 자리 표시 자 이미지와 제품이 아직 나타나지 않은 : 나는 다음과 같은 코드로했습니다.

도움을 주시면 감사하겠습니다.

덕분에, 다니엘 당신은 이미로드 된 컬렉션 후 'small_image'필터 을 추가하는

답변

3

, 그래서 필터는 더 이상 컬렉션에 영향을주지것입니다.

귀하의 OR 필터가 이상하게 보입니다. 'no_selection'도 일부 자리 표시 자 이미지라고 가정하면 필터는 을 수락합니다. 은으로 표시되고 자리 표시 자 이미지는 이됩니다.

시도는를 사용하는 대신 필터링합니다 :

$collection->addAttributeToFilter(
    array('attribute' => 'small_image', 'neq' => '') 
); 
$collection->addAttributeToFilter(
    array('attribute' => 'small_image', 'neq' => 'no_selection') 
); 
+0

안녕 위르겐, 도와 주셔서 감사합니다 많이. 이제 작동 중입니다. –