2017-04-03 4 views
0

私は現在、EasyPostで貨物を作成しています。私が貨物を作るとき、それは利用可能なすべてのサービスと料金を私に提供します。特定のサービスの料金を取得する - EasyPost

私はサービスを動的に選択し、そのレートのみを返したいと思います。

私はもともと、インデックス番号(私はそれを記述する方法を推測する)を使用して配列を読み取るでしょう。

この問題は、新しい貨物を作成するたびにレート配列の順序が変わるので、$ shipping-> rates [0] ['rate']は明示され、次に最初にクラス。

"エクスプレス"で貨物を作成し、その料金のみを返送したいとします。

アドバイスをいただければ幸いです。ここで

は私のコードです:EasyPostのGetting Started Guide

$name = $this->thiscustomer->cust_first . ' ' . $this->thiscustomer->cust_first; 
$street_1 = $this->thiscustomer->street_1; 
$street_2 = $this->thiscustomer->street_2; 
$city = $this->thiscustomer->city; 
$state = $this->thiscustomer->state; 
$zip = $this->thiscustomer->zip; 


$weight = $this->weight; 
    $packaging = $this->packaging; 
    $service = $this->service; 
    $caddress = $this->consultant->address; 
    $cstreet_1 = $this->consultant->street_1; 
    $cstreet_2 = $this->consultant->street_2; 
    $ccity = $this->consultant->city; 
    $cstate = $this->consultant->state; 
    $czip = $this->consultant->zip; 
    $cname = $this->consultant->first_name . ' ' . $this->consultant->last_name; 
    $cuser_id = $this->consultant->user_id; 




require_once(dirname(__FILE__) . '/lib/easypost.php'); 
\EasyPost\EasyPost::setApiKey('KUk4fZUI6YaYc1h0FiIXFw'); 


$shipment = \EasyPost\Shipment::create(array(
'to_address' => array(
"name" => $name, 
"street1" => $street_1, 
"street2" => $street_2, 
"city" => $city, 
"state" => $state, 
"zip"  => $zip 
), 
'from_address' => array(
"company" => $cname, 
"street1" => $cstreet_1, 
"street2" => $cstreet_2, 
"city" => $ccity, 
"state" => $cstate, 
"zip"  => $czip 
), 
'parcel' => array(
'weight' => $weight, 
'predefined_package'=> $packaging 
), 
'rates' => array(
    'service' => $service 
) 

)); 

echo $shipment->rates[0]['rate']. '<br>'; 

答えて

0

特定のキャリア+率を購入する例があります:

$shipment->buy($shipment->lowest_rate(array('USPS'), array('Express'))); 
+0

私が知っているまで、私はそれを購入する必要はありません率はです。 – foxtangocharlie

+0

この場合、いくつかの配列フィルタリングをするだけです。キャリア(carrier_accountsフィールドを使用して行うことができます)を選択する以外に、これらの詳細はEasyPostが意図的に便利メソッドから脱却して、必要なものを正確に決定するビジネスロジックです。 http://php.net/manual/en/function.array-filter.phpを参照してください。 – KFunk

関連する問題