0

我正在研究亚马逊到 vtiger 的集成,来自亚马逊 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"]=> array(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"]=> array(2) { ["FieldValue"]=> string(6) "Smyrna " ["FieldType"]=> string(6) "string" } ["County"]=> array(2) { ["FieldValue"]=> NULL ["FieldType"]=> string(6) "string" } ["District"]=> array(2) { ["FieldValue"]=> NULL ["FieldType"]=> string(6) "string" } ["StateOrRegion"]=> array(2) { ["FieldValue"]=> string(2) "TN" ["FieldType"]=> string (6) "string" } ["PostalCode"]=> array(2) { ["FieldValue"]=> string(5) "37167" ["FieldType"]=> string(6) "string" } [" CountryCode"]=> array(2) { ["FieldValue"]=> string(2) "US" ["FieldType"]=> string(6) "string" } ["Phone"]=> array(2) { ["FieldValue"]=> 字符串(10) "6152231070" ["FieldType"]=> 字符串(6) "字符串" } } }

4

2 回答 2

2

You have a syntax error,

bill_city' => $shippingAddress->getAddressLine1(),

Should be

'bill_city' => $shippingAddress->getAddressLine1(),

Get a decent IDE, mine picked it up in a few seconds.

IDE Picking up syntax error

于 2012-07-31T21:35:45.610 回答
0

All this means is that your $shippingAddress var does not have an object in it. It is likely that your call to getShippingAddress() has failed.

Do a var_dump($shippingAddress) to see what's in there.

于 2012-07-31T21:34:20.940 回答