无法确定 magento 过滤器查询中的字段名称

发布于 12-06 10:46 字数 1464 浏览 2 评论 0原文

我在 Magento 查询中使用 OR 过滤器时遇到问题。这就是我使用的:

 $collection = Mage::getModel('sales/order')->getCollection()
         ->addAttributeToSelect('*')
         ->addAttributeToFilter(
                            array(
                               array('attribute'=>'status','eq'=>'pending'), 
                               array('attribute'=>'created_at', 'from'=>$startDate, 'to'=>$finishDate)
                            )
     );

我想要以下 WHERE 语句: WHERE 'status' = 'pending' OR (created_at < $startDate ANDcreated_at > $finishDate) 但我收到以下错误消息

 Fatal error: Uncaught exception 'Mage_Core_Exception' with message 'Cannot determine the field name.' in /home/content/r/o/n/ronakkaria/html/magento/app/Mage.php:563 
 Stack trace: 
 #0 /home/content/r/o/n/ronakkaria/html/magento/app/code/core/Mage/Sales/Model/Resource/Collection/Abstract.php(52): Mage::throwException('Cannot determin...') 
 #1 /home/content/r/o/n/ronakkaria/html/magento/app/code/core/Mage/Sales/Model/Resource/Collection/Abstract.php(80): Mage_Sales_Model_Resource_Collection_Abstract->_attributeToField(Array) 
 #2 /home/content/r/o/n/ronakkaria/html/new/admin/magentoInvoice/getInvocieList.php(43): Mage_Sales_Model_Resource_Collection_Abstract->addAttributeToFilter(Array) 
 #3 {main} thrown in /home/content/r/o/n/ronakkaria/html/magento/app/Mage.php on line 563

我当前使用版本 1.6-2rc。

I'm having trouble with using an OR filter in a Magento query. This is what i used:

 $collection = Mage::getModel('sales/order')->getCollection()
         ->addAttributeToSelect('*')
         ->addAttributeToFilter(
                            array(
                               array('attribute'=>'status','eq'=>'pending'), 
                               array('attribute'=>'created_at', 'from'=>$startDate, 'to'=>$finishDate)
                            )
     );

I want the following WHERE statement: WHERE 'status' = 'pending' OR (created_at < $startDate AND created_at > $finishDate)
but i get the following error message

 Fatal error: Uncaught exception 'Mage_Core_Exception' with message 'Cannot determine the field name.' in /home/content/r/o/n/ronakkaria/html/magento/app/Mage.php:563 
 Stack trace: 
 #0 /home/content/r/o/n/ronakkaria/html/magento/app/code/core/Mage/Sales/Model/Resource/Collection/Abstract.php(52): Mage::throwException('Cannot determin...') 
 #1 /home/content/r/o/n/ronakkaria/html/magento/app/code/core/Mage/Sales/Model/Resource/Collection/Abstract.php(80): Mage_Sales_Model_Resource_Collection_Abstract->_attributeToField(Array) 
 #2 /home/content/r/o/n/ronakkaria/html/new/admin/magentoInvoice/getInvocieList.php(43): Mage_Sales_Model_Resource_Collection_Abstract->addAttributeToFilter(Array) 
 #3 {main} thrown in /home/content/r/o/n/ronakkaria/html/magento/app/Mage.php on line 563

I am currently using version 1.6-2rc.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏至、离别2024-12-13 10:46:09

据我所知,您不能使用 addAttributeToFilter()OR 销售/订单 模型的两个属性。

使用 addAttributeToSearchFilter() 代替:

$startDate = '2011-01-01';
$finishDate = '2011-01-31';

var_dump(
    Mage::getModel('sales/order')->getCollection()
    ->addAttributeToSelect('*')
    ->addAttributeToSearchFilter(
       array(
            array(
                'attribute' => 'status',
                'eq' => 'pending'
            ),
            array(
                'attribute' => 'created_at',
                'from' => $startDate,
                'to' => $finishDate
            )
       )
    )
    ->getSelectSql(true)
);

这将创建一个 WHERE 子句:

WHERE 
    (status = 'pending') OR 
    (created_at >= '2011-01-01' AND created_at <= '2011-01-31')

Afaik you cannot use addAttributeToFilter() to OR two attributes for the sales/order model.

Use addAttributeToSearchFilter() instead:

$startDate = '2011-01-01';
$finishDate = '2011-01-31';

var_dump(
    Mage::getModel('sales/order')->getCollection()
    ->addAttributeToSelect('*')
    ->addAttributeToSearchFilter(
       array(
            array(
                'attribute' => 'status',
                'eq' => 'pending'
            ),
            array(
                'attribute' => 'created_at',
                'from' => $startDate,
                'to' => $finishDate
            )
       )
    )
    ->getSelectSql(true)
);

This will create a WHERE clause of:

WHERE 
    (status = 'pending') OR 
    (created_at >= '2011-01-01' AND created_at <= '2011-01-31')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文