Skip to content

Commit b1cdc61

Browse files
committed
Fixed lingering bug in customer_id and delivery_mode_id caused by missing two lines of old code that needed to be removed. Removed debugging output from examples/update_order_pickable.php
1 parent c1448f3 commit b1cdc61

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

examples/update_order_pickable.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
} else {
2020
try {
2121
$updateOrder = new Order();
22-
var_export($updateOrder);
2322
$updateOrder->setId($argv[1]);
2423
$updateOrder->can_pick =
2524
($argv[2] == '1' || strtoupper($argv[2]) == 'TRUE') ? 1 : 0;

lib/MyCloud/Api/Model/Order.php

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -590,10 +590,41 @@ public function update( $apiContext = null )
590590
}
591591

592592
$order = NULL;
593+
$customer_id = NULL;
594+
$delivery_mode_id = NULL;
595+
596+
// REVIEW These special treatments are in create() and update().
597+
// Maybe Order should implement it's own toArray() to
598+
// consolidate this code in one place?
599+
600+
// First we need to remove Objects that can never be set.
601+
// We need to get their Id's and unset their fields BEFORE
602+
// the call to toArray() below. Then set their payload values
603+
// after that call, if they are actually set.
604+
//
605+
if ( ! empty($this->customer) ) {
606+
$customer_id = $this->customer->id;
607+
unset($this->customer);
608+
}
609+
if ( ! empty($this->delivery_mode) ) {
610+
$delivery_mode_id = $this->delivery_mode->id;
611+
unset($this->delivery_mode);
612+
}
613+
593614
$payload = $this->toArray();
594615

595-
$payload['customer_id'] = empty($this->customer) ? '0' : $this->customer->id;
596-
$payload['delivery_mode_id'] = empty($this->delivery_mode) ? '0' : $this->delivery_mode->id;
616+
// NOTE These sets will override the ID if it was set explicitly
617+
// In other words, we are ASSUMING that if the client set the Object
618+
// field, they intended to override the ID field. If this assumption
619+
// is wrong, this code needs to be modified.
620+
//
621+
if ( $customer_id !== NULL ) {
622+
$payload['customer_id'] = $customer_id;
623+
}
624+
625+
if ( $delivery_mode_id !== NULL ) {
626+
$payload['delivery_mode_id'] = $delivery_mode_id;
627+
}
597628

598629
$index = 0;
599630
foreach ( $this->order_items as $order_item ) {

0 commit comments

Comments
 (0)