2012-07-31 81 views
0

我在亞馬遜工作,好vtiger整合子功能,從亞馬遜MWS客戶端庫的代碼片段看起來像如何讓PHP

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的子功能?作者RAW_DUMP 這裏

幫我請

完整代碼

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"); 
    } 

輸出爲一次銷售訂單的名單,從中我工作

(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"]=> string(10) "6152231070" ["FieldType"]=> string(6) "string" } } }

+0

嗯,我不知道,但我覺得你在這裏缺少報價:[點擊這裏] bill_city」 – 2012-07-31 21:33:55

+0

我評論這是不工作 – 2012-07-31 21:48:41

回答

0

這一切意思是說你的$shippingAddress var沒有一個物體在裏面。您很可能撥打getShippingAddress()失敗。

做一個var_dump($shippingAddress)看看裏面有什麼。

+0

的var_dump部分顯示的地址是有 – 2012-07-31 21:56:49

+0

@NewBee,你確定它是一個對象,而不是數組呢?我無法分辨,因爲你在一些評論中格式化了這一點。在你的問題中發佈'var_dump()'的原始輸出。 – Brad 2012-07-31 21:57:48

+0

粘貼var_dump導致問題 – 2012-08-01 18:50:36

2

你有一個語法錯誤,

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

應該

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

獲得一個體面的IDE,礦山在幾秒鐘內把它撿起來。

IDE Picking up syntax error

+0

抱歉,發佈代碼時發生錯誤 – 2012-07-31 21:41:56

+0

是這個phpstorm? – joschua011 2012-07-31 21:43:28

+0

@ joschua011:是的。 – 2012-08-01 09:34:11