首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >magento:致命错误:调用未定义的方法Varien_Data_Collection::addFieldToFilter()

magento:致命错误:调用未定义的方法Varien_Data_Collection::addFieldToFilter()
EN

Stack Overflow用户
提问于 2012-08-13 18:49:24
回答 2查看 4.9K关注 0票数 0
代码语言:javascript
运行
复制
class Nextshopping_Shipment_Model_Mysql4_Shipment_Collection extends     Mage_Core_Model_Mysql4_Collection_Abstract
{
    public function loadProductForShipment(){

    $coll = new  Varien_Data_Collection();

    $shipment = Mage::getModel('shipment/shipment')->getResourceCollection();
    $order_item_id = array();
    if($shipment){
        foreach ($shipment as $item){
            $order_item_id[] = $item->getOrderItemId();
        }
    }
    $collection = Mage::getModel('sales/order_item')->getCollection();

    if($order_item_id){
        $collection = $collection ->addFieldToFilter('item_id',array('nin'=>$order_item_id));
    }
    $collection->addAttributeToSelect('item_id');
    $collection->addAttributeToSelect('product_id');
    $collection->addAttributeToSelect('name');
    $collection->addAttributeToSelect('sku');
    $collection->addAttributeToSelect('qty_ordered');


    $collection->getSelect()
    ->join('sales_flat_order','main_table.order_id = sales_flat_order.entity_id AND sales_flat_order.state = "complete"',
            array('state','status as order_status','increment_id as order_increment_id'))
            ->join('sales_flat_invoice','sales_flat_invoice.order_id = sales_flat_order.entity_id',
                    array('entity_id as invoice_id'))
                    ->join('sales_flat_order_payment','sales_flat_order_payment.entity_id = sales_flat_order.entity_id AND method != "cashondelivery"',
                            array('method'))
                            ->join('sales_flat_shipment','sales_flat_shipment.order_id = sales_flat_order.entity_id',
                                    array('created_at','updated_at'));
    if($collection){
        foreach ($collection as $item){
            $object = new Varien_Object();

            $object->setData($item->getData());

            $object->setData('qty_shipmented',0);

            if(strtotime($item['created_at']) + 3600*24*3 < time()){
                $object->setData('more_than_three',$item['qty_ordered']);
            }else{
                $object->setData('more_than_three',0);
            }

            if(strtotime($item['created_at']) +3600*24*5 < time()){
                $object->setData('more_than_five',$item['qty_ordered']);
            }else{
                $object->setData('more_than_five',0);
            }

            if(strtotime($item['created_at']) +3600*24*7 < time()){
                $object->setData('more_than_seven',$item['qty_ordered']);
            }else{
                $object->setData('more_than_seven',0);
            }
            $coll->addItem($object);
        }
    }
    //$coll = Mage::getModel('sales/order_item')->getResourceCollection();
    return $coll;
}


 protected function _prepareCollection()
{
  $collection = Mage::getModel('shipment/shipment')->getCollection()->loadProductForShipment();
   $this->setCollection($collection);
   return parent::_prepareCollection();
}

在此方法中,more_than_three是不在数据库中的自定义字段。此集合用于网格调用,但当我单击“搜索”时,程序会回显

Fatal error: Call to undefined method Varien_Data_Collection::addFieldToFilter() in E:\Program Files\xampp\htdocs\shopping.nextmedia.com\app\code\core\Mage\Adminhtml\Block\Widget\Grid.php on line 472

谁能告诉我该怎么做?

EN

回答 2

Stack Overflow用户

发布于 2012-08-13 19:28:16

检查错误为什么引用类Varien_Data_Collection;因为在使用Mage::getModel('sales/order_item')->getCollection();时,它应该返回Mage_Sales_Model_Resource_Order_Item_Collection类型的对象!

Varien_Data_Collection是唯一一个被Magento中的任何集合扩展的类。

此外,您可以尝试其他方法来创建集合-我不知道您的版本是否正确:

代码语言:javascript
运行
复制
// instead of
Mage::getModel('sales/order_item')->getCollection();
// try something like:
Mage::getModel('sales/order_item')->getResourceCollection();
// or:
Mage::getResourceModel('sales/order_item')->getCollection();
// or even:
Mage::getResourceModel('sales/order_item_collection');
票数 1
EN

Stack Overflow用户

发布于 2012-08-13 19:16:37

如果您查看官方文档,您会发现该类没有这样的方法:http://docs.magentocommerce.com/Varien/Varien_Data/Varien_Data_Collection.html

我的猜测是,您正在寻找addFilter方法来实现相同的目标;)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11932818

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档