Skip to content

Commit

Permalink
Support for filtering orders list
Browse files Browse the repository at this point in the history
  • Loading branch information
troelskn committed Jun 14, 2016
1 parent 16f620b commit ca8928e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
7 changes: 6 additions & 1 deletion examples.php
Expand Up @@ -22,9 +22,14 @@
$products = $sendworks->products->select();
var_dump($sendworks->service_points->select($products[0], $recipient));

// List orders
// List all orders
var_dump($sendworks->orders->select());

// Find order by shop system and reference (shop system id)
foreach ($sendworks->orders->select(['shop_system' => 'magento', 'order_reference' => '100000001']) as $order) {
var_dump($order);
}

// Get shipment from order
$shipment = $sendworks->orders->select()[0]->shipments[0]->resolve();
var_dump($shipment);
Expand Down
2 changes: 1 addition & 1 deletion lib/Sendworks/Order.php
Expand Up @@ -20,7 +20,7 @@ class Order
public function __construct($data = [], $connection = null)
{
$this->connection = $connection;
foreach (['id', 'order_reference', 'customer_number', 'service_point_reference'] as $prop) {
foreach (['id', 'order_reference', 'shop_system', 'customer_number', 'service_point_reference'] as $prop) {
if (isset($data[$prop])) {
$this->$prop = $data[$prop];
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Sendworks/OrdersCollection.php
Expand Up @@ -10,9 +10,9 @@ public function __construct($connection)
$this->connection = $connection;
}

public function select()
public function select($filters = [])
{
$response = $this->client()->get('orders');
$response = $this->client()->get('orders', ['query' => $filters]);
$result = array();
foreach (json_decode($response->getBody(), true) as $struct) {
$result[] = Order::import($struct, $this->connection);
Expand Down

0 comments on commit ca8928e

Please sign in to comment.