目前是否有办法将跟踪号码上传回php中BigCommerce的订单?我可以在BigCommerce的API Doc for Shipments上看到,有一个特定于PUT命令的跟踪号的参数。 我还看到Shipment.php文件中有一个更新功能。但是,我不确定如何调用允许我这样做的功能,或者甚至可以上传跟踪号码。
以下是shipment.php的摘录
namespace Bigcommerce\Api\Resources;
use Bigcommerce\Api\Resource;
use Bigcommerce\Api\Client;
class Shipment extends Resource
{
...
public function create()
{
return Client::createResource('/orders/' . $this->order_id . '/shipments', $this->getCreateFields());
}
public function update()
{
return Client::createResource('/orders/' . $this->order_id . '/shipments' . $this->id, $this->getCreateFields());
}
}
这里也是PUT API Doc的链接 https://developer.bigcommerce.com/api/stores/v2/orders/shipments#update-a-shipment
答案 0 :(得分:2)
只要您传入必填字段(如文档页面所示),您就可以直接使用货件对象创建新货件。
<?php
$shipment = new Bigcommerce\Api\Resources\Shipment();
$shipment->order_address_id = $id; // destination address id
$shipment->items = $items; // a list of order items to send with the shipment
$shipment->tracking_number = $track; // the string of the tracking id
$shipment->create();
您也可以将数据作为数组直接传递给createResource
函数:
<?php
$shipment = array(
'order_address_id' => $id,
'items' => $items,
'tracking_number' => $track
);
Bigcommerce\Api\Client::createResource("/orders/1/shipments", $shipment);
执行PUT
是类似的。您可以从订单对象遍历它:
<?php
$order = Bigcommerce\Api\Client::getOrder($orderId);
foreach($order->shipments as $shipment) {
if ($shipment->id == $idToUpdate) {
$shipment->tracking_number = $track;
$shipment->update();
break;
}
}
或者直接将其作为对象拉回来并重新保存:
<?php
$shipment = Bigcommerce\Api\Client::getResource("/orders/1/shipments/1", "Shipment");
$shipment->tracking_number = $track;
$shipment->update();
或直接更新:
<?php
$shipment = array(
'tracking_number' => $track
);
Bigcommerce\Api\Client::updateResource("/orders/1/shipments/1", $shipment);