的Bigcommerce上传追踪号码(BigCommerce Uploading Tracking

2019-10-18 08:51发布

有目前在PHP中上传一个跟踪号码回订单上的Bigcommerce的方法吗? 我可以看到的Bigcommerce的出货量API文档,有一个参数,以特定的跟踪编号为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());
    }
}

这里也是该链接为把API文档。
https://developer.bigcommerce.com/api/stores/v2/orders/shipments#update-a-shipment

Answer 1:

您可以直接使用出货对象来创建新货,只要你在必填字段通过(如图所示的文档页)。

<?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);


文章来源: BigCommerce Uploading Tracking Numbers