问题描述
有目前在PHP中上传一个跟踪号码回订单上的Bigcommerce的方法吗?我可以看到的Bigcommerce的出货量API文档,有一个参数,具体的跟踪编号为PUT命令。
我还看到有所述Shipment.php文件内的更新的功能。不过,我不能确定如何调用,让我做到这一点的功能,或者如果它甚至可以上传一个跟踪号码。
Is there currently a way to upload a tracking number back to an order on BigCommerce in php? I can see on BigCommerce's API Doc for Shipments that there is a parameter to specific a tracking number for a PUT command.I also see that there is an update function within the Shipment.php file. However, I am unsure how to call the function that would allow me to do that, or if it is even possible upload a tracking number.
下面是shipment.php片段
Below is a snippet from 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文档。结果
的
推荐答案
您可以直接使用出货对象来创建新货,只要你在必填字段通过(如图所示的文档页)。
You can use the shipment object directly to create a new shipment, as long as you pass in required fields (as shown on the doc page).
<?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
功能:
You can also pass in the info directly as an array to the createResource
function:
<?php
$shipment = array(
'order_address_id' => $id,
'items' => $items,
'tracking_number' => $track
);
Bigcommerce\Api\Client::createResource("/orders/1/shipments", $shipment);
做一个 PUT
是相似的。您可以从订单对象遍历它:
Doing a PUT
is similar. You can traverse to it from an order object:
<?php
$order = Bigcommerce\Api\Client::getOrder($orderId);
foreach($order->shipments as $shipment) {
if ($shipment->id == $idToUpdate) {
$shipment->tracking_number = $track;
$shipment->update();
break;
}
}
或者直接拉回来,作为一个对象,并重新保存:
Or pull it back directly as an object and re-save it:
<?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追踪号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!