2013-03-19 139 views
0

你好Magento的專家組成的非對象的成員函數的getData(),呼叫在Magento的擴展

我開發了一個Magento Extension這是工作的罰款Version 1.6 and 1.7,但是當我把它安裝Version 1.5,它給我一個錯誤:

Fatal error: Call to a member function getData() on a non-object in /home/broadcas/public_html/app/code/community/Gwb/Magecrmsync/controllers/Adminhtml/OrdersController.php on line 18 

以下是我的OrderController.php代碼。

<?php 
class Gwb_Magecrmsync_Adminhtml_OrdersController extends Mage_Adminhtml_Controller_Action 
{ 
public function indexAction() 
{ 
    $model = Mage::getModel('sales/order'); 

    $collection = $model->getCollection() 
    ->addFieldToFilter('status', array("in" => array('complete','closed','pending','holded','payment_review','pending_payment','pending_paypal','processing'))); 

    $data = array(); 
    $orderArr = array(); 

    // getting order details 

    $records = 0; 
    foreach($collection as $order) 
    { 
     $data[$records]['order_data']['shipping_address'] = $order->getShippingAddress()->getData(); // get shipping details 
     $data[$records]['order_data']['billing_address'] = $order->getBillingAddress()->getData(); // get billing details 
     $data[$records]['order_data']['order_total'] = $order->getGrandTotal(); // get total amount 
     $data[$records]['order_data']['shipping_amount'] = $order->getShippingAmount(); 
     $data[$records]['order_data']['order_details'] = $order->toArray(); 
     $records++; 
    } 

    // getting order details 

} 
} 

任何人都可以請指導我什麼我做錯了其不Version 1.5工作。

任何幫助,將不勝感激。

謝謝

+0

這也許是因爲'getBillingAddress()'或'getShippingAddress()'目前正在返回一個空的,所以你想叫的東西的方法'的getData()'這是不是一個對象。嘗試添加一些調試來知道'$ order-> getShippingAddress()'和'$ order-> getBillingAddress()'是什麼,如果你的訂單有這樣的方法。 – MatRt 2013-03-19 05:30:10

+0

@ user1073122,你是對的。 getShippingAddress()返回null。那麼如何在1.5版本中找到送貨地址和賬單地址? – 2013-03-19 05:33:29

+0

你應該參考你的magento擴展。在這一點上,我無法幫助你。嘗試檢查對象$ order的類名是什麼,並查看類定義以瞭解可用的方法。 – MatRt 2013-03-19 05:34:44

回答

1

檢查我的答案。您應該檢查$order->getShippingAddress()是否爲對象。因爲如果產品是虛擬的。送貨地址將被設置。

class Gwb_Magecrmsync_Adminhtml_OrdersController extends Mage_Adminhtml_Controller_Action 
{ 
public function indexAction() 
{ 
    $model = Mage::getModel('sales/order'); 

    $collection = $model->getCollection() 
    ->addFieldToFilter('status', array("in" => array('complete','closed','pending','holded','payment_review','pending_payment','pending_paypal','processing'))); 

    $data = array(); 
    $orderArr = array(); 
    // getting order details 
    $records = 0; 
    foreach($collection as $order) 
    { 

      if(is_object($order->getShippingAddress())) 
      {  
       $data[$records]['order_data']['shipping_address'] = $order->getShippingAddress()->getData(); // get shipping details 
      }  
      else 
      { 
       $data[$records]['order_data']['shipping_address'] = array(); // no shipping details 
      } 

      if(is_object($order->getBillingAddress())) 
      { 
       $data[$records]['order_data']['billing_address'] = $order->getBillingAddress()->getData(); // get billing details 
      } 
      else 
      { 
       $data[$records]['order_data']['billing_address'] = array(); // no billing details  
      } 

      $data[$records]['order_data']['order_total'] = $order->getGrandTotal(); // get total amount 
      $data[$records]['order_data']['shipping_amount'] = $order->getShippingAmount(); 
      $data[$records]['order_data']['order_details'] = $order->toArray(); 
       $records++; 
    } 

    // getting order details 

} 
} 
+0

謝謝!它解決了問題.... – 2013-03-19 07:38:37