Note that there are some explanatory texts on larger screens.

plurals
  1. POMagento how to get overriden resource collection object?
    primarykey
    data
    text
    <p>I want to sort category page products by Popularity. So I created a module. </p> <pre><code>class Tal_Popularity_Model_Config extends Mage_Catalog_Model_Config { public function getAttributeUsedForSortByArray() { $options = array( 'position' =&gt; Mage::helper('catalog')-&gt;__('Position'), 'popularity' =&gt; Mage::helper('catalog')-&gt;__('Popularity'), 'topsellings' =&gt; Mage::helper('catalog')-&gt;__('Top Selling') ); foreach ($this-&gt;getAttributesUsedForSortBy() as $attribute) { /* @var $attribute Mage_Eav_Model_Entity_Attribute_Abstract */ $options[$attribute-&gt;getAttributeCode()] = $attribute-&gt;getStoreLabel(); } return $options; } } </code></pre> <p>config.xml</p> <pre><code>.... &lt;global&gt; &lt;models&gt; &lt;catalog&gt; &lt;rewrite&gt; &lt;config&gt;Tal_Popularity_Model_Config&lt;/config&gt; &lt;category&gt;Tal_Popularity_Model_Category&lt;/category&gt; &lt;resourceModel&gt;catalog_resource&lt;/resourceModel&gt; &lt;/rewrite&gt; &lt;/catalog&gt; &lt;catalog_resource&gt; &lt;rewrite&gt; &lt;product_collection&gt;Tal_Popularity_Model_Resource&lt;/product_collection&gt; &lt;/rewrite&gt; &lt;/catalog_resource&gt; &lt;/models&gt; &lt;blocks&gt; &lt;catalog&gt; &lt;rewrite&gt; &lt;product_list_toolbar&gt;Tal_Popularity_Block_Product_List_Toolbar&lt;/product_list_toolbar&gt; &lt;/rewrite&gt; &lt;/catalog&gt; &lt;/blocks&gt; ... </code></pre> <p>resource collection</p> <pre><code>class Tal_Popularity_Model_Resource_Product_Collection extends Mage_Catalog_Model_Resource_Product_Collection { public function sortByReview($dir) { $table = $this-&gt;getTable('review/review'); $entity_code_id = Mage::getModel('review/review')-&gt;getEntityIdByCode(Mage_Rating_Model_Rating::ENTITY_PRODUCT_CODE); $cond = $this-&gt;getConnection()-&gt;quoteInto('t2.entity_pk_value = e.entity_id and ','').$this-&gt;getConnection()-&gt;quoteInto('t2.entity_id = ? ',$entity_code_id); $this-&gt;getSelect()-&gt;joinLeft(array('t2'=&gt;$table), $cond,array('review' =&gt; new Zend_Db_Expr('count(review_id)'))) -&gt;group('e.entity_id')-&gt;order("review $dir"); } } </code></pre> <p>Category model class</p> <pre><code> class Tal_Popularity_Model_Category extends Mage_Catalog_Model_Category { public function getProductCollection() { // $collection = Mage::getModel('catalog/config')-&gt;getCollection() $collection = Mage::getResourceModel('tal_popularity/product')-&gt;getCollection() -&gt;setStoreId($this-&gt;getStoreId()) -&gt;addCategoryFilter($this); return $collection; } } </code></pre> <p>What is the error with these codes? I can't find. Is there a better way to sort category page products by popl=ularity rather than this?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload