0

我正在构建一个自定义模块,我正在尝试获取具有特定状态的所有订单:

$canceledQuery = Mage::getSingleton('core/resource')->getConnection('core_read')->select()
            ->from('mage_sales_flat_order', 'entity_id')
            ->where('status = ?', 'canceled');

这很好用。但现在我正在尝试在 where 中使用 OR,但没有成功。我一直在尝试这个:

$whereCanceled = array();
foreach ($_status as $statusCode => $value) {
    $whereCanceled[] = sprintf('%s=:%s', 'status', $statusCode);
}

$ordersQuery = Mage::getSingleton('core/resource')->getConnection('core_read')->select()
            ->from('mage_sales_flat_order', 'entity_id')
            ->where(implode(' OR ', $whereCanceled));

所以,我不知道在这种情况下如何正确使用 OR。我发现这对 OR 没有用。任何想法?

4

1 回答 1

1

而不是implode使用join。magento 使用 join 本身。

->where(join(' OR ', $orWhere));//$orWhere array of condition

您可以在下面的函数 magento 中看到where 子句中的OR条件使用join

public function getSystemConfigByPathsAndTemplateId($paths, $templateId)
    {
        $orWhere = array();
        $pathesCounter = 1;
        $bind = array();
        foreach ($paths as $path) {
            $pathAlias = 'path_' . $pathesCounter;
            $orWhere[] = 'path = :' . $pathAlias;
            $bind[$pathAlias] = $path;
            $pathesCounter++;
        }
        $bind['template_id'] = $templateId;
        $select = $this->_getReadAdapter()->select()
            ->from($this->getTable('core/config_data'), array('scope', 'scope_id', 'path'))
            ->where('value LIKE :template_id')
            ->where(join(' OR ', $orWhere));

        return $this->_getReadAdapter()->fetchAll($select, $bind);
    }

有关位于 [magento]/app/code/core/Mage/Core/Model/Resource/Email/Template.php 的更多参考打开文件

希望这对你有帮助

于 2014-04-02T18:47:47.507 回答