如何在Magento上加载类别选项卡滑块时添加“按日期缩短”?

时间:2015-01-30 13:46:35

标签: magento

我在我的magento主题上使用Bxslider v4.0进行类别标签滑块,但产品已按产品ID显示。

我想要做的是按日期顺序获取物品,以便我有最新的物品。

这是滑块代码,也许你可以帮到你。 应用程序/代码/本地/ magentothem

function getProductCate($id = NULL) {
    $storeId = Mage::app()->getStore()->getId();
    $_category = Mage::getModel('catalog/category')->load($id);
    $product = Mage::getModel('catalog/product');
    $json_products = array();
    //load the category's products as a collection
    $_productCollection = $product->getCollection()
            ->addAttributeToSelect(array('name', 'price', 'small_image', 'special_price'))
            ->addCategoryFilter($_category);
            Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($_productCollection);
            Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($_productCollection);
    $productLimits = $this->getProductsCount();
    if(!$productLimits) $productLimits = 10;
    $_productCollection->setPageSize($productLimits);
    $_productCollection->load();
    return $_productCollection;

1 个答案:

答案 0 :(得分:1)

在第$_productCollection->load();行之前,添加:

$_productCollection ->addAttributeToSort('created_at', 'DESC');

如果您要排序的字段不是created_at,请将其替换为正确的名称(不确定我是否理解该问题)