产品集合过滤/订单方向问题

时间:2013-02-01 12:01:30

标签: magento sorting collections position product

对于我的类别视图。我有一个选择下拉列表,它使用ajax设置带有选项值的会话。

我已覆盖Mage_Catalog_Block_Product_List

从ajax处理的会话值在' protected function _getProductCollection()'覆盖以根据需要过滤产品集合。

我的第一个问题是我想基于这些属性的三个值来过滤属性:

 $collection = parent::_getProductCollection();
 $collection ->addAttributeToFilter('name', array('in' => array('Cat','Adam', 'Paul')));
 $collection->addAttributeToSort('name = Cat', 'DESC');
 $collection->addAttributeToSort('name = Adam', 'DESC');
 $collection->addAttributeToSort('name = Paul', 'DESC');

  return $this->_productCollection; 

问题是我想根据需要定位这些。例如,我首先需要Cat然后是Adam然后是Paul。有没有办法定位这些?

第二个问题是我需要定位' sort by'选项。 ' asc'是默认值,但是我需要将它降为默认值。

到目前为止,我已覆盖'Mage_Catalog_Block_Product_List_Toolbar'并使用此代码:

protected $_direction           = 'desc';

但这并没有改变方向。

排序是否优先于我创建的自定义产品系列?

LOG

a:5:{i:0; s:126:" SQLSTATE [42000]:语法错误或访问冲突:1582调用本机函数时参数计数不正确' FIND_IN_SET'& #34 ;; i:1; s:6707:"#0 /var/www/vhosts/mydomain.com/httpdocs/mypath/lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo-> _execute(阵列)  /var/www/vhosts/mydomain.com/httpdocs/mypath/lib/Zend/Db/Statement.php(300):Varien_Db_Statement_Pdo_Mysql-> _execute(Array) /var/www/vhosts/mydomain.com/httpdocs/mypath/lib/Zend/Db/Adapter/Abstract.php(479):Zend_Db_Statement-> execute(Array)  /var/www/vhosts/mydomain.com/httpdocs/mypath/lib/Zend/Db/Adapter/Pdo/Abstract.php(238):Zend_Db_Adapter_Abstract->查询(' SELECT COUNT(DI ...& #39;,数组) /var/www/vhosts/mydomain.com/httpdocs/mypath/lib/Varien/Db/Adapter/Pdo/Mysql.php(419):Zend_Db_Adapter_Pdo_Abstract->查询(' SELECT COUNT(DI ...& #39;,数组) /var/www/vhosts/mydomain.com/httpdocs/mypath/lib/Zend/Db/Adapter/Abstract.php(825):Varien_Db_Adapter_Pdo_Mysql-> query(Object(Varien_Db_Select),Array) /var/www/vhosts/mydomain.com/httpdocs/mypath/lib/Varien/Data/Collection/Db.php(225):Zend_Db_Adapter_Abstract-> fetchOne(Object(Varien_Db_Select),Array) /var/www/vhosts/mydomain.com/httpdocs/mypath/lib/Varien/Data/Collection.php(225):Varien_Data_Collection_Db-> getSize() /var/www/vhosts/mydomain.com/httpdocs/mypath/lib/Varien/Data/Collection.php(211):Varien_Data_Collection-> getLastPageNumber() /var/www/vhosts/mydomain.com/httpdocs/mypath/app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php(1036):Varien_Data_Collection-> getCurPage() /var/www/vhosts/mydomain.com/httpdocs/mypath/app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php(871):Mage_Eav_Model_Entity_Collection_Abstract-> _loadEntities(false,false)  /var/www/vhosts/mydomain.com/httpdocs/mypath/app/code/core/Mage/Review/Model/Observer.php(78):Mage_Eav_Model_Entity_Collection_Abstract-> load() /var/www/vhosts/mydomain.com/httpdocs/mypath/app/code/core/Mage/Core/Model/App.php(1334):Mage_Review_Model_Observer-> catalogBlockProductCollectionBeforeToHtml(Object(Varien_Event_Observer)) /var/www/vhosts/mydomain.com/httpdocs/mypath/app/code/core/Mage/Core/Model/App.php(1307):Mage_Core_Model_App-> _callObserverMethod(Object(Mage_Review_Model_Observer),' catalogBlockPro ...',Object(Varien_Event_Observer)) /var/www/vhosts/mydomain.com/httpdocs/mypath/app/Mage.php(447):Mage_Core_Model_App-> dispatchEvent(' catalog_block_p ...',Array) /var/www/vhosts/mydomain.com/httpdocs/mypath/app/code/core/Mage/Catalog/Block/Product/List.php(163):Mage :: dispatchEvent(' catalog_block_p ...& #39;,数组) /var/www/vhosts/mydomain.com/httpdocs/mypath/app/code/core/Mage/Core/Block/Abstract.php(862):Mage_Catalog_Block_Product_List-> _beforeToHtml() /var/www/vhosts/mydomain.com/httpdocs/mypath/app/code/core/Mage/Core/Block/Abstract.php(582):Mage_Core_Block_Abstract-> toHtml() /var/www/vhosts/mydomain.com/httpdocs/mypath/app/code/core/Mage/Core/Block/Abstract.php(526):Mage_Core_Block_Abstract-> _getChildHtml(' product_list',true ) /var/www/vhosts/mydomain.com/httpdocs/mypath/app/code/core/Mage/Catalog/Block/Category/View.php(85):Mage_Core_Block_Abstract-> getChildHtml(' product_list' ) /var/www/vhosts/mydomain.com/httpdocs/mypath/app/design/frontend/default/gomer/template/catalog/category/view.phtml(115):Mage_Catalog_Block_Category_View-> getProductListHtml() /var/www/vhosts/mydomain.com/httpdocs/mypath/app/code/core/Mage/Core/Block/Template.php(241):include(' / var / www / vhosts ...& #39) /var/www/vhosts/mydomain.com/httpdocs/mypath/app/code/core/Mage/Core/Block/Template.php(272):Mage_Core_Block_Template-> fetchView(' frontend / defaul ... ') /var/www/vhosts/mydomain.com/httpdocs/mypath/app/code/core/Mage/Core/Block/Template.php(286):Mage_Core_Block_Template-> renderView() /var/www/vhosts/mydomain.com/httpdocs/mypath/app/code/core/Mage/Core/Block/Abstract.php(863):Mage_Core_Block_Template-> _toHtml() /var/www/vhosts/mydomain.com/httpdocs/mypath/app/code/core/Mage/Core/Block/Text/List.php(43):Mage_Core_Block_Abstract-> toHtml() /var/www/vhosts/mydomain.com/httpdocs/mypath/app/code/core/Mage/Core/Block/Abstract.php(863):Mage_Core_Block_Text_List-> _toHtml() /var/www/vhosts/mydomain.com/httpdocs/mypath/app/code/core/Mage/Core/Block/Abstract.php(582):Mage_Core_Block_Abstract-> toHtml() /var/www/vhosts/mydomain.com/httpdocs/mypath/app/code/core/Mage/Core/Block/Abstract.php(526):Mage_Core_Block_Abstract-> _getChildHtml(' content',true ) /var/www/vhosts/mydomain.com/httpdocs/mypath/app/design/frontend/default/gomer/template/page/2columns-left.phtml(49):Mage_Core_Block_Abstract-> getChildHtml(' content&# 39) /var/www/vhosts/mydomain.com/httpdocs/mypath/app/code/core/Mage/Core/Block/Template.php(241):include(' / var / www / vhosts ...& #39) /var/www/vhosts/mydomain.com/httpdocs/mypath/app/code/core/Mage/Core/Block/Template.php(272):Mage_Core_Block_Template-> fetchView(' frontend / defaul ... ') /var/www/vhosts/mydomain.com/httpdocs/mypath/app/code/core/Mage/Core/Block/Template.php(286):Mage_Core_Block_Template-> renderView() /var/www/vhosts/mydomain.com/httpdocs/mypath/app/code/core/Mage/Core/Block/Abstract.php(863):Mage_Core_Block_Template-> _toHtml() /var/www/vhosts/mydomain.com/httpdocs/mypath/app/code/core/Mage/Core/Model/Layout.php(555):Mage_Core_Block_Abstract-> toHtml() /var/www/vhosts/mydomain.com/httpdocs/mypath/app/code/core/Mage/Core/Controller/Varien/Action.php(390):Mage_Core_Model_Layout-> getOutput() /var/www/vhosts/mydomain.com/httpdocs/mypath/app/code/core/Mage/Catalog/controllers/CategoryController.php(159):Mage_Core_Controller_Varien_Action-> renderLayout() /var/www/vhosts/mydomain.com/httpdocs/mypath/app/code/core/Mage/Core/Controller/Varien/Action.php(419):Mage_Catalog_CategoryController-> viewAction() /var/www/vhosts/mydomain.com/httpdocs/mypath/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(250):Mage_Core_Controller_Varien_Action-> dispatch(' view&# 39) /var/www/vhosts/mydomain.com/httpdocs/mypath/app/code/core/Mage/Core/Controller/Varien/Front.php(176):Mage_Core_Controller_Varien_Router_Standard-> match(Object(Mage_Core_Controller_Request_Http)) /var/www/vhosts/mydomain.com/httpdocs/mypath/app/code/core/Mage/Core/Model/App.php(354):Mage_Core_Controller_Varien_Front-> dispatch() /var/www/vhosts/mydomain.com/httpdocs/mypath/app/Mage.php(683):Mage_Core_Model_App-> run(Array) /var/www/vhosts/mydomain.com/httpdocs/mypath/index.php(87):Mage :: run('',' store') {主要}&#34 ;; S:3:" URL&#34 ;; S:72:" /mypath/index.php/books-for-adults/autobiography-and-biography.html&# 34 ;; S:11:" SCRIPT_NAME&#34 ;; S:22:" /mypath/index.php" ;; S:4:"皮肤&#34 ;; S:7 :"英语&#34 ;;}

1 个答案:

答案 0 :(得分:0)

尝试使用finset:

$collection->addAttributeToFilter('name', array('finset'=>array('Cat','Adam','Paul')));

finset使用MySQL的FIND_IN_SET函数