好的,我在一个文件中有下面的代码。这只是easypost中easy shipping api的部分代码

$created_rates = \EasyPost\Rate::create($shipment);

$availableRates = array();

foreach($created_rates as $rate){

    $fedexR = str_replace("FEDEX_", " ", $rate->service);

    $displayS = str_replace("_", " ", $fedexR);

    $displayP = $rate->rate;

    $availableRates[] = $displayS;

}

$_SESSION['displayRates'] = $availableRates;

然后,这会将用户发送到选择装运方法的下一步,显示方式如下:
<?php foreach($_SESSION['displayRates'] as $rate): ?>
     <option value="<?php echo $rate; ?>"><?php echo $rate; ?></option>
<?php endforeach; ?>

提交到以下页面:
$_SESSION['shipping_method'] = $_POST['shippingRate'];

$shipment = \EasyPost\Shipment::retrieve(array('id' => $_SESSION['shipment_id']));

$shipment->buy($shipment->rates[1]);

$_SESSION['shipment_label_url'] = $shipment->postage_label->label_url;

echo $_SESSION['shipment_label_url'];

如何使用easypost api发送所选的运费,以告知它购买该运输方法的邮资?我懂了
$shipment->buy($shipment->rates[1]);
我试着这么做:
$shipment->buy($shipment->rates[$_SESSION['shipping_method']]);但导致根本不发送速率。
顺便说一句,会话是“ground”这样的实际单词,而不是数字。我不知道我怎么能做到这一点,但我必须如果我想它的工作!

最佳答案

这批货上有一个价格过滤器,叫做最低价格。您可以向它传递参数,如承运人名称和服务名称。类似于:

$shipment->buy($shipment->lowest_rate(array('Fedex'), array($_SESSION['shipping_method'])));

关于php - 在EasyPost中定义送货方式或费率,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21365043/

10-11 11:41