如何按产品名称在家中对新产品进行排序?

enter image description here

因为我看到把它通过Cms页面在管理:

管理-CMS网页-主页-内容 :

{{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"}}
有帮助吗?

解决方案

上课 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;
.

许可以下: CC-BY-SA归因
scroll top