Skip to content

Commit fd27021

Browse files
committed
Fixed MAJOR bug in Order.update call that was sending up customer and delivery_mode ids with zero values when they were not set. This was due to my not using the magic attributes and instead declaring these two attributes in the class. The attributes declarations were removed, forcing the attribtues to exist within the magic. Also needed to update the update() method on the model to properly understand and deal with customer and delivery mode allowing either the object _or_ the id to be set. Added 'can_pick' attribute support to Order. Updated print methods
1 parent 957a1d5 commit fd27021

File tree

5 files changed

+54
-21
lines changed

5 files changed

+54
-21
lines changed

examples/create_order.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
print " attachmentFilePath is the path to the file on the local computer" . PHP_EOL;
3333
} else {
3434
try {
35-
$products = Product::all();
36-
$customers = Customer::all();
35+
$products = Product::all( array('offset' => 0, 'count' => 10) );
36+
$customers = Customer::all( array('offset' => 0, 'count' => 10) );
3737
$delivery_modes = DeliveryMode::all();
3838

3939
$createOrder = new Order();

examples/printers.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ function print_order( $title, $order ) {
3737
print " Customer Reference: " . $order->customer_reference . PHP_EOL;
3838
print " CreateDate: " . $order->create_date . PHP_EOL;
3939
print " DeliveryDate: " . $order->delivery_date . PHP_EOL;
40+
print " Pickable?: " . ($order->can_pick ? 'Yes' : 'No') . PHP_EOL;
4041
print " Total Price: " . $order->total_price . PHP_EOL;
4142
print " Weight: " . $order->weight . PHP_EOL;
4243
print " Urgent: " . ($order->urgent ? 'Yes' : 'No') . PHP_EOL;
@@ -127,13 +128,16 @@ function print_product( $title, $product ) {
127128
print " Description: " . $product->description . PHP_EOL;
128129
print " PhotoUrl: " . $product->photo_url . PHP_EOL;
129130
print " SupplierRef: " . $product->supplier_reference . PHP_EOL;
130-
print " Physical Inventory: " . $product->physical_inventory . PHP_EOL;
131-
print " Reserved Inventory: " . $product->reserved_inventory . PHP_EOL;
131+
print " Physical Inventory: " . $product->physical_inventory . PHP_EOL;
132+
print " Reserved Inventory: " . $product->reserved_inventory . PHP_EOL;
133+
print " WaitPay Inventory: " . $product->waitpayment_inventory . PHP_EOL;
134+
print " RecvPay Inventory: " . $product->recvpayment_inventory . PHP_EOL;
135+
print " Approved Inventory: " . $product->approved_inventory . PHP_EOL;
132136
print " Available Inventory: " . $product->available_inventory . PHP_EOL;
133-
print " ClientReference[1]: " . $product->getClientReference(0) . PHP_EOL;
134-
print " ClientReference[2]: " . $product->getClientReference(1) . PHP_EOL;
135-
print " ClientReference[3]: " . $product->getClientReference(2) . PHP_EOL;
136-
print " ClientReference[4]: " . $product->getClientReference(3) . PHP_EOL;
137+
print " ClientReference[1]: " . $product->getClientReference(0) . PHP_EOL;
138+
print " ClientReference[2]: " . $product->getClientReference(1) . PHP_EOL;
139+
print " ClientReference[3]: " . $product->getClientReference(2) . PHP_EOL;
140+
print " ClientReference[4]: " . $product->getClientReference(3) . PHP_EOL;
137141
}
138142

139143
function print_shop( $title, $shop ) {

lib/MyCloud/Api/Model/Customer.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,15 @@ public static function all( $params = array(), $apiContext = null )
128128
// ArgumentValidator::validate($params, 'params');
129129
$payLoad = "";
130130
$allowedParams = array(
131-
'page_size' => 1,
132-
'page' => 1,
133-
'start_time' => 1,
134-
'end_time' => 1,
135-
'sort_order' => 1,
136-
'sort_by' => 1,
137-
'total_required' => 1
131+
'offset' => 0,
132+
'count' => 10,
133+
// 'page_size' => 1,
134+
// 'page' => 1,
135+
// 'start_time' => 1,
136+
// 'end_time' => 1,
137+
// 'sort_order' => 1,
138+
// 'sort_by' => 1,
139+
// 'total_required' => 1
138140
);
139141

140142
$json_data = self::executeCall(

lib/MyCloud/Api/Model/Order.php

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ class Order extends MyCloudModel
3434

3535
public $order_items = array();
3636

37-
public $customer = NULL;
38-
39-
public $delivery_mode = NULL;
37+
// public $customer = NULL;
38+
//
39+
// public $delivery_mode = NULL;
4040

4141
public $attachments = array();
4242

@@ -463,10 +463,37 @@ public static function get( $orderId, $apiContext = null )
463463
public function create( $apiContext = null )
464464
{
465465
$order = NULL;
466+
$customer_id = NULL;
467+
$delivery_mode_id = NULL;
468+
469+
// First we need to remove Objects that can never be set.
470+
// We need to get their Id's and unset their fields BEFORE
471+
// the call to toArray() below. Then set their payload values
472+
// after that call, if they are actually set.
473+
//
474+
if ( ! empty($this->customer) ) {
475+
$customer_id = $this->customer->id;
476+
unset($this->customer);
477+
}
478+
if ( ! empty($this->delivery_mode) ) {
479+
$delivery_mode_id = $this->delivery_mode->id;
480+
unset($this->delivery_mode);
481+
}
482+
466483
$payload = $this->toArray();
467484

468-
$payload['customer_id'] = empty($this->customer) ? '0' : $this->customer->id;
469-
$payload['delivery_mode_id'] = empty($this->delivery_mode) ? '0' : $this->delivery_mode->id;
485+
// NOTE These sets will override the ID if it was set explicitly
486+
// In other words, we are ASSUMING that if the client set the Object
487+
// field, they intended to override the ID field. If this assumption
488+
// is wrong, this code needs to be modified.
489+
//
490+
if ( $customer_id !== NULL ) {
491+
$payload['customer_id'] = $customer_id;
492+
}
493+
494+
if ( $delivery_mode_id !== NULL ) {
495+
$payload['delivery_mode_id'] = $delivery_mode_id;
496+
}
470497

471498
$index = 0;
472499
foreach ( $this->order_items as $order_item ) {

lib/MyCloud/Api/Model/Product.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public static function all( $params = array(), $apiContext = null )
136136
$payLoad = "";
137137
$allowedParams = array(
138138
'offset' => 0,
139-
'count' => 100,
139+
'count' => 10,
140140
// 'start_time' => 1,
141141
// 'end_time' => 1,
142142
// 'sort_order' => 1,

0 commit comments

Comments
 (0)