gpt4 book ai didi

php - 在 EasyPost 中定义运输方式或费率

转载 作者:搜寻专家 更新时间:2023-10-31 20:41:07 25 4
gpt4 key购买 nike

好的,我在一个文件中包含以下代码。这只是来自 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']]); 但是导致费率根本没有发送。

顺便说一句, session 是像“GROUND”这样的实际词,而不是数字。不确定如何实现这一目标,但如果我想让它发挥作用,我必须这么做!

最佳答案

货件上有一个名为 lowest_rate 的费率过滤器。您可以将 args 传递给它,例如运营商名称和服务名称。像这样的东西:

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

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com