我在数据库中有一个过程:soundex_match_all
我想在条件中添加Magento代码。
例如。在哪里soundex_match_all('toys', product_name, ' ')=1
代码:
$storeId = Mage::app()->getStore()->getId();
$products = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('*')
->setStoreId($storeId)
->addStoreFilter($storeId)
->addFieldToFilter("status",1)
->addFieldToFilter($attribute,array('like'=> '%'.$keyword.'%'))
答案 0 :(得分:1)
您可以将自定义where语句添加到集合sql
$products->getSelect()->where("soundex_match_all('toys', product_name, ' ') = 1");
在使用字段名时要小心使用表前缀。 使用
确保您的sql正确无误$products->getSelect()->__toString();
还可以查看方法orWhere()
和andWhere()
来合并过滤器表达式