从Zend DB Select中删除过滤器

时间:2015-06-10 15:33:05

标签: magento zend-framework

如何删除Zend_DB_Select上的where条件?我有一个Magento集合,我使用Varien_Data_Collection_Db中的addAttributeToFilter方法添加了where条件。现在我需要删除那个条件。这可能吗?

更多信息

我有一个基于属性加载集合的Magento小部件。小部件执行此操作:

$collection->addAttributeToFilter($attributeCode, array('notnull'->true));

小部件还添加了以下过滤器,以将结果限制为名称以字母开头的产品:

collection->addAttributeToFilter('name', array('like'-> $letter.'%'));

但是,客户端的自定义工具栏需要首字母的所有产品的索引,如[A] [B] [C] [D] ... [Z],所以当您点击链接时,产品将使用以第一个字母开头的产品过滤收集。问题是catalog / product_list_toolbar工具栏块使用与父目录/ product_list块相同的产品集合。因此工具栏的产品集合也按字母过滤。

解决方法

这是我的hacky解决方案。我使用PHP的反射将以下代码添加到窗口小部件:

$letterCollection = clone $this->_productCollection;
$letterSelect = clone $letterCollection->getSelect();
$reflectionClass = new ReflectionClass($letterCollection);
$reflectionProperty = $reflectionClass->getProperty('_select');
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue($letterCollection, $letterSelect);
$letterCollection->addAttributeToSelect('name');
$toolbar = $this->getChild('toolbar');
$toolbar->setLetterCollection($letterCollection);

$this->_productCollection->addFieldToFilter('name', array('like' => "$letter%"));

在扩展工具栏(Namespace_Module_Block_Toolbar扩展Mage_Catalog_Block_Product_List_Toolbar)中,我只获得未经过滤的集合:

$collection = $this->getLetterCollection();// $this->getCollection() would be the filtered collection

应该有办法从Magento集合中删除过滤器。

1 个答案:

答案 0 :(得分:1)

只需致电reset

$select->reset(Zend_Db_Select::WHERE);