From 782b4781ea8a7d1fe4f073480124e085f951f102 Mon Sep 17 00:00:00 2001 From: Yura Date: Thu, 23 Jul 2020 14:50:09 +0300 Subject: [PATCH] Order creation date --- src/include/class-wc-retailcrm-history.php | 3 ++- tests/test-wc-retailcrm-history.php | 9 ++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/include/class-wc-retailcrm-history.php b/src/include/class-wc-retailcrm-history.php index 4f2aa03..a5a540c 100644 --- a/src/include/class-wc-retailcrm-history.php +++ b/src/include/class-wc-retailcrm-history.php @@ -602,6 +602,7 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) : /** @var WC_Order|WP_Error $wc_order */ $wc_order = wc_create_order($args); + $wc_order->set_date_created($order['createdAt']); $customer = $order['customer']; $contactOrCustomer = array(); $address = isset($order['customer']['address']) ? $order['customer']['address'] : array(); @@ -1181,4 +1182,4 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) : } } -endif; \ No newline at end of file +endif; diff --git a/tests/test-wc-retailcrm-history.php b/tests/test-wc-retailcrm-history.php index f76e8ba..ab00677 100644 --- a/tests/test-wc-retailcrm-history.php +++ b/tests/test-wc-retailcrm-history.php @@ -23,12 +23,13 @@ class WC_Retailcrm_History_Test extends WC_Retailcrm_Test_Case_Helper public function test_history_order_create() { $product = WC_Helper_Product::create_simple_product(); + $order = $this->get_history_data_new_order($product->get_id()); $this->mockHistory( true, true, $this->empty_history(), - $this->get_history_data_new_order($product->get_id()) + $order ); $retailcrm_history = new \WC_Retailcrm_History($this->apiMock); @@ -52,6 +53,8 @@ class WC_Retailcrm_History_Test extends WC_Retailcrm_Test_Case_Helper $this->assertEquals($product->get_id(), $order_added_item->get_product()->get_id()); } + $this->assertNotEmpty($order_added->get_date_created()); + $this->assertEquals($order_added->get_date_created()->date('Y-m-d H:i:s'), $order['history'][0]['createdAt']); $this->assertNotEmpty($shipping_address['first_name']); $this->assertNotEmpty($shipping_address['last_name']); $this->assertNotEmpty($shipping_address['postcode']); @@ -133,7 +136,7 @@ class WC_Retailcrm_History_Test extends WC_Retailcrm_Test_Case_Helper $this->regenerateMocks(); $this->history_order_switch_customer($order_id); - + $this->regenerateMocks(); $this->history_order_switch_customer_to_corporate($order_id); @@ -173,7 +176,7 @@ class WC_Retailcrm_History_Test extends WC_Retailcrm_Test_Case_Helper $this->assertEquals('tester001@example.com', $order_added->get_billing_email()); $this->assertNotEmpty($order_added->get_id()); - + return $order_added->get_id(); }