我正在开发amazon到vtiger集成,而amazon MWS客户端库的代码片段似乎是
if ($order->isSetShippingAddress()) {
echo(" ShippingAddress\n");
$shippingAddress = $order->getShippingAddress();
if ($shippingAddress->isSetName()) {
echo(" Name\n");
echo(" " . $shippingAddress->getName() . "\n");
}
if ($shippingAddress->isSetAddressLine1()) {
echo(" AddressLine1\n");
echo(" " . $shippingAddress->getAddressLine1() . "\n");
}
我想访问$shippingAddress->AddressLine1()
我的代码看起来像
$module = 'Invoice';
$shippingAddress = $order->getShippingAddress();
$orderTotal = $order->getOrderTotal();
$record = $client->doCreate($module,Array(
'subject' => $order->getAmazonOrderId(),
'customerno'=> $order->getAmazonOrderId(),
bill_city' => $shippingAddress->getAddressLine1(),
'bill_state'=> $shippingAddress->getStateOrRegion(),
'bill_code' => $shippingAddress->getPostalCode(),
当我尝试这个时,我收到错误
致命错误:在非对象
上调用成员函数getAddressLine1()这是范围错误吗?我该如何使用$ shippingAddress的子功能?
请帮助我完整代码
function invokeListOrders(MarketplaceWebServiceOrders_Interface $service, $request)
{
try {
$response = $service->listOrders($request);
if ($response->isSetListOrdersResult()) {
echo(" ListOrdersResult\n");
$listOrdersResult = $response->getListOrdersResult();
if ($listOrdersResult->isSetOrders()) {
echo(" Orders\n");
$orders = $listOrdersResult->getOrders();
$orderList = $orders->getOrder();
foreach ($orderList as $order) {
$shippingAddress = $order->getShippingAddress();
include_once('vtwsclib/Vtiger/WSClient.php');
$url = 'http://vijayholdings.com/admin';
$client = new Vtiger_WSClient($url);
$login = $client->doLogin('admin', 'MYSECRETKEY');
if(!$login) echo 'Login Failed';
else{
$module = 'Invoice';
$shippingAddress = $order->getShippingAddress();
$orderTotal = $order->getOrderTotal();
$record = $client->doCreate($module,Array(
'subject'=>$order->getAmazonOrderId(),
'customerno'=>$order->getAmazonOrderId(),
'invoicestatus'=>'Credit Invoice',/*
'assigned_user_id'=>'spatel',
'currency_id'=>'1',
'conversion_rate'=>'1', not working*/
'bill_street'=>$order->getShippingAddress(),/*
'bill_city'=>$shippingAddress->getCity(),
'bill_state'=>$shippingAddress->getStateOrRegion(),
'bill_code'=>$shippingAddress->getPostalCode(),
'bill_country'=>$order->$shippingAddress->getCounty(), */
'cf_652'=>'Deepdiscounts.co Amazon FBA',/*
'cf_653'=>$shippingAddress->getPhone(),
'cf_656'=>$shippingAddress->getAddressLine2(), */
'cf_660'=>$order->getShipServiceLevel(),
'cf_658'=>$order->getSalesChannel(),
'cf_661'=>$order->getFulfillmentChannel(),
'cf_663'=>$order->getBuyerName(),
'cf_659'=>$order->getBuyerEmail(),
'cf_662'=>$order->getPaymentMethod()
));
}
if($record) {
$recordid = $client->getRecordId($record['id']);
echo "The id is ".$recordid;
}
}
}
}
} catch (MarketplaceWebServiceOrders_Exception $ex) {
echo("Caught Exception: " . $ex->getMessage() . "\n");
echo("Response Status Code: " . $ex->getStatusCode() . "\n");
echo("Error Code: " . $ex->getErrorCode() . "\n");
echo("Error Type: " . $ex->getErrorType() . "\n");
echo("Request ID: " . $ex->getRequestId() . "\n");
echo("XML: " . $ex->getXML() . "\n");
echo("ResponseHeaderMetadata: " . $ex->getResponseHeaderMetadata() . "\n");
}
输出RAW_DUMP 这是一个销售订单,形成我正在工作的清单
(1){[“_ fields:protected”] => array(11){[“Name”] =>数组(2){ [ “fieldValue方法”] => string(16)“Jason A. Stewart”[“FieldType”] => string(6)“string”} [“AddressLine1”] => array(2){[“FieldValue”] => string(15)“101 Young Drive”[“FieldType”] => string(6)“string”} [ “AddressLine2”] => array(2){[“FieldValue”] => NULL [“FieldType”] => string(6)“string”} [“AddressLine3”] => array(2){[“FieldValue”] => NULL [“FieldType”] => string(6)“string”} [“City”] =>数组(2){ [ “fieldValue方法”] => string(6)“Smyrna”[“FieldType”] => string(6)“string” } [“郡”] => array(2){[“FieldValue”] => NULL [“FieldType”] => string(6)“string”} [“District”] => array(2){[“FieldValue”] =>空值 [ “的FieldType”] => string(6)“string”} [“StateOrRegion”] =>数组(2){ [ “fieldValue方法”] => string(2)“TN”[“FieldType”] => string(6)“string”} [ “邮编”] => array(2){[“FieldValue”] => string(5)“37167” [ “的FieldType”] => string(6)“string”} [“CountryCode”] =>数组(2){ [ “fieldValue方法”] => string(2)“US”[“FieldType”] => string(6)“string”} [ “电话”] => array(2){[“FieldValue”] => string(10)“6152231070” [ “的FieldType”] => string(6)“string”}}}
答案 0 :(得分:2)
您遇到语法错误,
bill_city' => $shippingAddress->getAddressLine1(),
应该是
'bill_city' => $shippingAddress->getAddressLine1(),
获得一个不错的IDE,我几秒钟就把它拿起来了。
答案 1 :(得分:0)
所有这些意味着您的$shippingAddress
var中没有对象。您对getShippingAddress()
的调用可能失败了。
执行var_dump($shippingAddress)
以查看其中的内容。