How to Sort New Products at Home by Product Name
-
13-12-2019 - |
Question
how to sort New Products at Home by Product Name ?
because I see to put it through CMS page in the Admin:
Admin - CMS Pages - home - Content :
{{widget type="catalog/product_widget_new" display_type="new_products" products_count="4" column_count="4" template="catalog/product/widget/new/content/new_grid.phtml"}}
Solution
Take class Mage_Catalog_Block_Product_Widget_New
in local folder or extend it with your own
Find the below function
protected function _getProductCollection()
{
switch ($this->getDisplayType()) {
case self::DISPLAY_TYPE_NEW_PRODUCTS:
$collection = parent::_getProductCollection();
break;
default:
$collection = $this->_getRecentlyAddedProductsCollection();
break;
}
return $collection;
}
and replace with this
protected function _getProductCollection()
{
switch ($this->getDisplayType()) {
case self::DISPLAY_TYPE_NEW_PRODUCTS:
$collection = parent::_getProductCollection();
break;
default:
$collection = $this->_getRecentlyAddedProductsCollection();
break;
}
$collection->addAttributeToSort('name');
return $collection;
}
OTHER TIPS
Please update bellow function from:
protected function _getProductCollection()
{
switch ($this->getDisplayType()) {
case self::DISPLAY_TYPE_NEW_PRODUCTS:
$collection = parent::_getProductCollection();
break;
default:
$collection = $this->_getRecentlyAddedProductsCollection();
break;
}
return $collection;
}
To
protected function _getProductCollection()
{
switch ($this->getDisplayType()) {
case self::DISPLAY_TYPE_NEW_PRODUCTS:
$collection = parent::_getProductCollection();
$collection->addAttributeToSort('name', 'ASC');
//or $collection->addAttributeToSort('name', 'desc');
break;
default:
$collection = $this->_getRecentlyAddedProductsCollection();
break;
}
return $collection;
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange