diff --git a/modules/order/commerce_order.module b/modules/order/commerce_order.module index 0b0672b..de3524e 100644 --- a/modules/order/commerce_order.module +++ b/modules/order/commerce_order.module @@ -746,9 +746,17 @@ function commerce_order_save($order) { /** * Loads an order by ID. + * + * @param $order_id + * The order ID to load. + * @param $reset + * Whether to reset the internal order loading cache. Useful if checking + * if order has been updated and you cannot rely on static cache. + * + * @return bool|stdClass */ -function commerce_order_load($order_id) { - $orders = commerce_order_load_multiple(array($order_id), array()); +function commerce_order_load($order_id, $reset = FALSE) { + $orders = commerce_order_load_multiple(array($order_id), array(), $reset); return $orders ? reset($orders) : FALSE; } diff --git a/modules/order/includes/commerce_order.controller.inc b/modules/order/includes/commerce_order.controller.inc index ba345a8..8a04837 100644 --- a/modules/order/includes/commerce_order.controller.inc +++ b/modules/order/includes/commerce_order.controller.inc @@ -90,9 +90,14 @@ class CommerceOrderEntityController extends DrupalCommerceEntityController { } } - $order->changed = REQUEST_TIME; + // We have to use time() here as the REQUEST_TIME constant will remain + // the same value throughout a single request. That means each save + // operation in a single request will have same timestamp. + $time = time(); - $order->revision_timestamp = REQUEST_TIME; + $order->changed = $time; + + $order->revision_timestamp = $time; $order->revision_hostname = ip_address(); $order->revision_uid = $user->uid; diff --git a/modules/order/tests/commerce_order.test b/modules/order/tests/commerce_order.test index 0933067..6dca05f 100644 --- a/modules/order/tests/commerce_order.test +++ b/modules/order/tests/commerce_order.test @@ -126,10 +126,6 @@ class CommerceOrderCRUDTestCase extends CommerceBaseTestCase { * in the database outside of a load function. */ function testCommerceOrderHasChanged() { - // Log in as normal user. - $this->store_customer = $this->createStoreCustomer(); - $this->drupalLogin($this->store_customer); - // Order creation, in complete status. $order = commerce_order_new(1); $order->order_number = $order_number = $this->randomName(10); @@ -141,9 +137,9 @@ class CommerceOrderCRUDTestCase extends CommerceBaseTestCase { $this->assertIdentical($saved, SAVED_NEW, 'commerce_order_save() successfully saved a new order for updating.'); // Load a new copy of the order so we can update it as if it's out of scope. - $loaded = commerce_order_load($order->order_id); + $loaded = commerce_order_load($order->order_id, TRUE); - // Sleep for 3 seconds to make sure REQUEST_TIME in commerce_order_save() is different. + // Sleep for 3 seconds to make sure time() in commerce_order_save() is different. sleep(3); // Update the order and save it again.