1

目前有没有办法在 PHP 中将跟踪号上传回 BigCommerce 上的订单?我可以在 BigCommerce 的发货 API 文档中看到,有一个参数可以指定 PUT 命令的跟踪号。我还看到 Shipment.php 文件中有一个更新函数。但是,我不确定如何调用允许我这样做的函数,或者是否可以上传跟踪号。

下面是来自 shipping.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

4

1 回答 1

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);
于 2013-07-17T06:09:29.547 回答