is there way upload tracking number order on bigcommerce in php? can see on bigcommerce's api doc shipments there parameter specific tracking number put command. see there update function within shipment.php file. however, unsure how call function allow me that, or if possible upload tracking number.
below snippet 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()); } }
here link api doc put.
https://developer.bigcommerce.com/api/stores/v2/orders/shipments#update-a-shipment
you can use shipment object directly create new shipment, long pass in required fields (as shown on doc page).
<?php $shipment = new bigcommerce\api\resources\shipment(); $shipment->order_address_id = $id; // destination address id $shipment->items = $items; // list of order items send shipment $shipment->tracking_number = $track; // string of tracking id $shipment->create();
you can pass in info directly array createresource
function:
<?php $shipment = array( 'order_address_id' => $id, 'items' => $items, 'tracking_number' => $track ); bigcommerce\api\client::createresource("/orders/1/shipments", $shipment);
doing put
similar. can traverse order object:
<?php $order = bigcommerce\api\client::getorder($orderid); foreach($order->shipments $shipment) { if ($shipment->id == $idtoupdate) { $shipment->tracking_number = $track; $shipment->update(); break; } }
or pull directly object , re-save it:
<?php $shipment = bigcommerce\api\client::getresource("/orders/1/shipments/1", "shipment"); $shipment->tracking_number = $track; $shipment->update();
or update directly:
<?php $shipment = array( 'tracking_number' => $track ); bigcommerce\api\client::updateresource("/orders/1/shipments/1", $shipment);
Comments
Post a Comment