在Magento Extension中的非对象上调用成员函数getData()

时间:2013-03-19 05:27:15

标签: php magento

你好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无效。

任何帮助都将不胜感激。

由于

1 个答案:

答案 0 :(得分: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

}
}