Magento获取当前排序&使用getCollection()的方向 [英] Magento Get Current Sort & Direction with getCollection()
问题描述
我必须对Magento的目录页面(list.phtml)进行一些更改,除了排序依据"的名称,位置等之外,其他一切都很好.
I have had to make some changes to the catalog page (list.phtml) in Magento, everything is fine except for the 'Sort By' name, position etc...
这是我的代码:
$_productCollection= Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('*')
->addStoreFilter()
->setPage(Mage::getBlockSingleton('page/html_pager')->getCurrentPage(), $limit)
->setPageSize( $limit )
->setOrder($this->getCurrentOrder(), $this->getCurrentDirection())
->load();
这里显然有问题,因为尝试对结果的名称,位置等进行排序时什么也没有发生!
There is something wrong here clearly as nothing happens when trying to sort the results bu name, position etc!
这行显然有问题:
->setOrder($this->getCurrentOrder(), $this->getCurrentDirection())
我还对设置为不单独显示的简单产品显示问题!我也从那里错过了一些东西.
I am also having a problem with Simple products that are set to not show individually are showing! I have missed something from there also.
如果有人可以引导我迈向正确的功能/语法,那就太好了!
If someone could steer me towards the correct functions/syntax that would be great!
推荐答案
我解决了订购问题!
-> setOrder(Mage :: getBlockSingleton('catalog/product_list_toolbar')-> getCurrentOrder(),法师:: getBlockSingleton('catalog/product_list_toolbar')-> getCurrentDirection())
->setOrder(Mage::getBlockSingleton('catalog/product_list_toolbar')->getCurrentOrder(), Mage::getBlockSingleton('catalog/product_list_toolbar')->getCurrentDirection())
并且产品设置为不单独显示:
And products set to not show individually:
->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds())
所有其他人的完整代码:
So the full code for anyone else:
if( $this->getMode()!='grid' ) {
$limit = Mage::getStoreConfig('catalog/frontend/list_per_page');
}
else {
$limit = Mage::getStoreConfig('catalog/frontend/grid_per_page');
}
$_productCollection= Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
->addAttributeToSelect('sku_base')
->addStoreFilter(Mage::app()->getStore()->getId())
->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds())
->setPage(Mage::getBlockSingleton('page/html_pager')->getCurrentPage(), $limit)
->setPageSize( $limit )
->setOrder(Mage::getBlockSingleton('catalog/product_list_toolbar')->getCurrentOrder(), Mage::getBlockSingleton('catalog/product_list_toolbar')->getCurrentDirection())
->load();
这篇关于Magento获取当前排序&使用getCollection()的方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!