2012-08-13 5 views
0
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에서는 DB에없는 사용자 정의 필드입니다. 이 컬렉션은 그리드 호출입니다,하지만 난 클릭 할 때 무엇을 말해 줄 수 프로그램 에코젠토 : 치명적인 오류 : 정의되지 않은 메서드 Varien_Data_Collection에 전화 : addFieldToFilter()를

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

를 '검색'?)

+0

()가'Varien_Data_Collection''에 방법'addFieldToFilter을 정의합니다. 프레임 워크에 내장되어있는 경우 버전에 버전이 있는지 확인하십시오. 그렇다면 아마 magento 설치가 실패했을 것입니다. – Leri

답변

0

당신은 클래스는 방법이없는 것을 볼 수 있습니다 오류가 클래스 Varien_Data_Collection을 참조하는 이유를 확인하십시오. Mage::getModel('sales/order_item')->getCollection();을 사용할 때 Mage_Sales_Model_Resource_Order_Item_Collection 유형의 객체를 반환해야하기 때문에!

Varien_Data_Collection은 Magento의 모든 컬렉션에서 확장되는 클래스입니다.

추가, 당신은 컬렉션을 만들 수있는 다른 방법을 시도해 볼 수도 있습니다 - 버전이 맞는지 모르겠어요 :

// 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'); 
관련 문제