
在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();