如何按产品名称在家中对新产品进行排序
-
13-12-2019 - |
解决方案
上课 Mage_Catalog_Block_Product_Widget_New
在本地文件夹中或用您自己的文件夹扩展它
找到下面的函数
protected function _getProductCollection()
{
switch ($this->getDisplayType()) {
case self::DISPLAY_TYPE_NEW_PRODUCTS:
$collection = parent::_getProductCollection();
break;
default:
$collection = $this->_getRecentlyAddedProductsCollection();
break;
}
return $collection;
}
并用这个代替
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;
}
其他提示
请更新来自:
protected function _getProductCollection()
{
switch ($this->getDisplayType()) {
case self::DISPLAY_TYPE_NEW_PRODUCTS:
$collection = parent::_getProductCollection();
break;
default:
$collection = $this->_getRecentlyAddedProductsCollection();
break;
}
return $collection;
}
.
到
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;
.