Magento集合 - 如何在WHERE条件中添加过程函数

时间:2018-01-31 08:38:03

标签: magento magento-1.9 zend-db

我在数据库中有一个过程: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.'%'))

1 个答案:

答案 0 :(得分:1)

您可以将自定义where语句添加到集合sql

$products->getSelect()->where("soundex_match_all('toys', product_name, ' ') = 1");

在使用字段名时要小心使用表前缀。 使用

确保您的sql正确无误
$products->getSelect()->__toString();

还可以查看方法orWhere()andWhere()来合并过滤器表达式