你好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 :(得分: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
}
}