Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is surprisingly nasty - I can't see a way to do this simply in the DB, as entity_id isn't a standard attribute (it's really just a key field) and the core code repeats the same logic in three place (urgh). </p> <p>It's also changed a lot since the older versions of Magento, so many of the tutorials and forum posts on this no longer apply.</p> <p>What you can do is add "entity_id" in as a new sorting option, similar to the way "Best Value" exists as a sorting option. In the following example I've labelled it "Newest"</p> <p>The usual caveats apply: You should do this in an extension (or at the least in /local/ overrides) but the three core file methods that need overriding in Community Edition 1.7 are:</p> <p>Mage_Adminhtml_Model_System_Config_Source_Catalog_ListSort</p> <pre><code>public function toOptionArray() { $options = array(); $options[] = array(//benz001 'label' =&gt; Mage::helper('catalog')-&gt;__('Newest'), 'value' =&gt; 'entity_id' ); //end benz001 $options[] = array( 'label' =&gt; Mage::helper('catalog')-&gt;__('Best Value'), 'value' =&gt; 'position' ); foreach ($this-&gt;_getCatalogConfig()-&gt;getAttributesUsedForSortBy() as $attribute) { $options[] = array( 'label' =&gt; Mage::helper('catalog')-&gt;__($attribute['frontend_label']), 'value' =&gt; $attribute['attribute_code'] ); } return $options; } </code></pre> <p>Then Mage_Catalog_Model_Category_Attribute_Source_Sortby</p> <pre><code> /** * Retrieve All options * * @return array */ public function getAllOptions() { if (is_null($this-&gt;_options)) { $this-&gt;_options = array( array(//benz001 'label' =&gt; Mage::helper('catalog')-&gt;__('Newest'), 'value' =&gt; 'entity_id' ), //end benz001 array( 'label' =&gt; Mage::helper('catalog')-&gt;__('Best Value'), 'value' =&gt; 'position' )); foreach ($this-&gt;_getCatalogConfig()-&gt;getAttributesUsedForSortBy() as $attribute) { $this-&gt;_options[] = array( 'label' =&gt; Mage::helper('catalog')-&gt;__($attribute['frontend_label']), 'value' =&gt; $attribute['attribute_code'] ); } } return $this-&gt;_options; } </code></pre> <p>And then Mage_Catalog_Model_Config </p> <pre><code> public function getAttributeUsedForSortByArray() { $options = array( 'entity_id' =&gt; Mage::helper('catalog')-&gt;__('Newest'), //benz001 'position' =&gt; Mage::helper('catalog')-&gt;__('Position'), ); 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>With those in place, flush the cache and refresh and you can then select to sort by Newest/entity_id in the config and on the category page and on the frontend.</p> <p>Note: even if you have caching turned off it's still a good idea to flush the cache - parts of the admin are cached even when caching is disabled.</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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