0

カスタムモジュールを構築しています。特定のステータスを持つすべての注文を取得しようとしています:

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

これは非常にうまく機能します。しかし今、私はどこで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 に答える