Magento获取当前Collection的排序方式

 

汤面和namu
汤面和namu

在Magento中,平时获得collection的时候,我们会根据实际情况设置排序,使用setOrder。如果只是静态的,这个好说,直接写上即可。

现在需要使用ajax的加载product list,实现当前页面动态加载后面页面的内容。这个时候页面排序和排序方式用户可以自己选择的,就需要动态的获取,当前的排序方式。

参考代码如下

$_productCollection = Mage::getResourceModel('catalog/product_collection')
                ->addAttributeToSelect('*')
                ->addAttributeToFilter('visibility', $visibility)
                .............
                ->setStoreId($storeId)
                ->addStoreFilter($storeId)
                ->addCategoryFilter($_featcategory) //feature category to list first
                //set order as CurrentOrder
                ->setOrder(Mage::getBlockSingleton('catalog/product_list_toolbar')->getCurrentOrder(), Mage::getBlockSingleton('catalog/product_list_toolbar')->getCurrentDirection())
                .......................

代码中如下两行分别获取order和direction,动态的设置collection

Mage::getBlockSingleton(‘catalog/product_list_toolbar’)->getCurrentOrder();
Mage::getBlockSingleton(‘catalog/product_list_toolbar’)->getCurrentDirection();

转载表明出处:www.hellokeykey.com

 

《Magento获取当前Collection的排序方式》有4个想法

  1. 钥匙兄,我用的仿兰亭的模板,其中有个hot products ,他是怎么生成的呢,我在网上找,有些人说后台有个可以改变产品数量的模块,我这里没有,你能告诉我一下吗?

评论已关闭。