2013-03-24 1 views
0

인기도별로 카테고리 페이지 제품을 정렬하고 싶습니다. 그래서 모듈을 만들었습니다.Magento는 리소스 컬렉션 개체를 어떻게 재정의합니까?

class Tal_Popularity_Model_Config extends Mage_Catalog_Model_Config 
{ 
    public function getAttributeUsedForSortByArray() 
    { 
     $options = array(
      'position'  => Mage::helper('catalog')->__('Position'), 
      'popularity' => Mage::helper('catalog')->__('Popularity'), 
      'topsellings' => Mage::helper('catalog')->__('Top Selling') 
     ); 
     foreach ($this->getAttributesUsedForSortBy() as $attribute) 
     { 
      /* @var $attribute Mage_Eav_Model_Entity_Attribute_Abstract */ 
      $options[$attribute->getAttributeCode()] = $attribute->getStoreLabel(); 
     } 

     return $options; 
    } 
} 

config.xml에

.... 
<global> 
    <models> 
     <catalog> 
      <rewrite> 
       <config>Tal_Popularity_Model_Config</config> 
       <category>Tal_Popularity_Model_Category</category> 
       <resourceModel>catalog_resource</resourceModel> 
      </rewrite> 
     </catalog> 
     <catalog_resource> 
      <rewrite> 
       <product_collection>Tal_Popularity_Model_Resource</product_collection> 
      </rewrite> 
     </catalog_resource> 
    </models> 
    <blocks> 
     <catalog> 
      <rewrite> 
       <product_list_toolbar>Tal_Popularity_Block_Product_List_Toolbar</product_list_toolbar> 
      </rewrite> 
      </catalog> 
     </blocks> 
... 

자원 수집

class Tal_Popularity_Model_Resource_Product_Collection extends Mage_Catalog_Model_Resource_Product_Collection 
{ 

    public function sortByReview($dir) 
    { 
     $table = $this->getTable('review/review'); 
     $entity_code_id = Mage::getModel('review/review')->getEntityIdByCode(Mage_Rating_Model_Rating::ENTITY_PRODUCT_CODE); 
     $cond = $this->getConnection()->quoteInto('t2.entity_pk_value = e.entity_id and ','').$this->getConnection()->quoteInto('t2.entity_id = ? ',$entity_code_id); 
     $this->getSelect()->joinLeft(array('t2'=>$table), $cond,array('review' => new Zend_Db_Expr('count(review_id)'))) 
     ->group('e.entity_id')->order("review $dir"); 
} 

} 

분류 모델 클래스

class Tal_Popularity_Model_Category extends Mage_Catalog_Model_Category 
    { 

     public function getProductCollection() 
     { 

     // $collection = Mage::getModel('catalog/config')->getCollection() 
     $collection = Mage::getResourceModel('tal_popularity/product')->getCollection() 
       ->setStoreId($this->getStoreId()) 
       ->addCategoryFilter($this); 
      return $collection; 
     } 
    } 

이러한 코드에 오류가 무엇입니까? 나는 못 찾는다. 이보다 popl = ularity로 카테고리 페이지 제품을 분류하는 더 좋은 방법이 있습니까?

답변

1

귀하의 Tal_Popularity_Model_Category 클래스는 더 같이해야한다 :

public function getProductCollection() 
{ 
    $collection = Mage::getResourceModel('catalog/product_collection') 
     ->setStoreId($this->getStoreId()) 
     ->addCategoryFilter($this) 
     ->sortByReview('ASC') 
    ; 
    return $collection; 
} 
+0

나는 그 모델 'Mage_Catalog_Model_Config'을 드리고 있습니다. 위의 오류를 보여 주지만. 부모 설정 클래스에는 개미 getCollection() 메소드가 없습니다. – Sukeshini

+0

그래서이 재정의 된 리소스 컬렉션 클래스를 어떻게 호출 할 수 있습니까? 'Tal_Popularity_Model_Resource_Product_Collection' – Sukeshini

+0

원본 클래스에서'getCollection()'을 호출 할 수 없습니다 .. 그래서 ..? –

관련 문제