Skip to content

Commit

Permalink
Merge pull request #33 from route4me/order_v4_add_fields
Browse files Browse the repository at this point in the history
Added EXT_FIELDs to class Order V4.
  • Loading branch information
h2rd authored Mar 8, 2024
2 parents e591c74 + e3955db commit ce7ad98
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 17 deletions.
39 changes: 23 additions & 16 deletions UnitTestFiles/Test/OrderTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public function testFromArray()
'name' => 'Bill Soul',
],
],
'EXT_FIELD_cost' => 50
]);

$this->assertEquals('1358 E Luzerne St, Philadelphia, PA 19124, US', $orderParameters->address_1);
Expand All @@ -129,6 +130,7 @@ public function testFromArray()
'name' => 'Bill Soul',
],
], $orderParameters->EXT_FIELD_custom_data);
$this->assertEquals(50, $orderParameters->EXT_FIELD_cost);
}

public function testToArray()
Expand All @@ -152,21 +154,24 @@ public function testToArray()
],
]);

$this->assertEquals($orderParameters->toArray(), [
'address_1' => '1358 E Luzerne St, Philadelphia, PA 19124, US',
'cached_lat' => 48.335991,
'cached_lng' => 31.18287,
'address_alias' => 'Auto test address',
'address_city' => 'Philadelphia',
'day_scheduled_for_YYMMDD' => date('Y-m-d'),
'EXT_FIELD_first_name' => 'Igor',
'EXT_FIELD_last_name' => 'Progman',
'EXT_FIELD_email' => '[email protected]',
'EXT_FIELD_phone' => '380380380380',
'EXT_FIELD_custom_data' => [
0 => [
'order_id' => '10',
'name' => 'Bill Soul',
$this->assertEquals(
$orderParameters->toArray(),
[
'address_1' => '1358 E Luzerne St, Philadelphia, PA 19124, US',
'cached_lat' => 48.335991,
'cached_lng' => 31.18287,
'address_alias' => 'Auto test address',
'address_city' => 'Philadelphia',
'day_scheduled_for_YYMMDD' => date('Y-m-d'),
'EXT_FIELD_first_name' => 'Igor',
'EXT_FIELD_last_name' => 'Progman',
'EXT_FIELD_email' => '[email protected]',
'EXT_FIELD_phone' => '380380380380',
'EXT_FIELD_custom_data' => [
0 => [
'order_id' => '10',
'name' => 'Bill Soul',
],
],
],
]);
Expand Down Expand Up @@ -502,7 +507,9 @@ public function testUpdateOrder()
$this->assertEquals('Lviv', $response['address_2']);
$this->assertEquals('032268593', $response['EXT_FIELD_phone']);
$this->assertEquals(
[0 => '{"order_id":"10","name":"Bill Soul"}'],
[
0 => '{"order_id":"10","name":"Bill Soul"}'
],
$response['EXT_FIELD_custom_data']
);
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "route4me/route4me-php",
"description": "Access Route4Me's logistics-as-a-service API using our PHP SDK",
"minimum-stability": "stable",
"version": "1.3.0",
"version": "1.3.1",
"authors": [
{
"name": "Igor Route4Me",
Expand Down
36 changes: 36 additions & 0 deletions examples/Order/NewOrderWithEXTFields.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Route4Me;

$root = realpath(dirname(__FILE__).'/../../');
require $root.'/vendor/autoload.php';

// Example refers to creating a new Order.

// Set the api key in the Route4me class
// This example not available for demo API key
Route4Me::setApiKey(Constants::API_KEY);

$orderParameters = Order::fromArray([
'address_1' => '1358 E Luzerne St, Philadelphia, PA 19124, US',
'cached_lat' => 48.335991,
'cached_lng' => 31.18287,
'address_alias' => 'Auto test address',
'address_city' => 'Philadelphia',
'day_scheduled_for_YYMMDD' => date('Y-m-d'),
'EXT_FIELD_first_name' => 'Igor',
'EXT_FIELD_last_name' => 'Progman',
'EXT_FIELD_email' => '[email protected]',
'EXT_FIELD_phone' => '380380380380',
'EXT_FIELD_weight' => 100.0,
'EXT_FIELD_cost' => 50,
'EXT_FIELD_revenue' => 150,
'EXT_FIELD_cube' => 5,
'EXT_FIELD_pieces' => 10
]);

$order = new Order();

$response = $order->addOrder($orderParameters);

Route4Me::simplePrint($response);
30 changes: 30 additions & 0 deletions src/Route4Me/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,36 @@ class Order extends Common

public $addresses = [];

/**
* Weight of the order.
* @since 1.2.11
*/
public $EXT_FIELD_weight;

/**
* Cost of the order.
* @since 1.2.11
*/
public $EXT_FIELD_cost;

/**
* The total revenue for the order.
* @since 1.2.11
*/
public $EXT_FIELD_revenue;

/**
* The cubic volume of the cargo.
* @since 1.2.11
*/
public $EXT_FIELD_cube;

/**
*The item quantity of the cargo.
* @since 1.2.11
*/
public $EXT_FIELD_pieces;

public function __construct()
{
Route4Me::setBaseUrl(Endpoint::BASE_URL);
Expand Down

0 comments on commit ce7ad98

Please sign in to comment.