From 277d1924b43a0f010c13ce6ff0e8a16c0ff6243f Mon Sep 17 00:00:00 2001 From: dima-uryvskiy Date: Thu, 19 Nov 2020 18:02:04 +0300 Subject: [PATCH] Update filling field createAt customer --- src/include/class-wc-retailcrm-customers.php | 6 +++--- tests/test-wc-retailcrm-customers.php | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/include/class-wc-retailcrm-customers.php b/src/include/class-wc-retailcrm-customers.php index 1248af4..5aaa7e7 100644 --- a/src/include/class-wc-retailcrm-customers.php +++ b/src/include/class-wc-retailcrm-customers.php @@ -374,9 +374,9 @@ if (!class_exists('WC_Retailcrm_Customers')) : } } - if (empty($createdAt)) { - $createdAt = new WC_DateTime(); - } + // If a customer has placed an order as a guest, then $customer->get_date_created() == null, + // then we take $order->get_date_created() order + $createdAt = empty($createdAt) ? $order->get_date_created() : $createdAt; $data_customer = array( 'createdAt' => $createdAt->date('Y-m-d H:i:s'), diff --git a/tests/test-wc-retailcrm-customers.php b/tests/test-wc-retailcrm-customers.php index 3dd49ed..d655d0b 100644 --- a/tests/test-wc-retailcrm-customers.php +++ b/tests/test-wc-retailcrm-customers.php @@ -44,6 +44,7 @@ class WC_Retailcrm_Customers_Test extends WC_Retailcrm_Test_Case_Helper $this->customer->set_billing_email($this->customer->get_email()); $this->customer->set_password('password'); $this->customer->set_billing_phone('89000000000'); + $this->customer->set_date_created(date('Y-m-d H:i:s')); $this->customer->save(); } @@ -91,6 +92,7 @@ class WC_Retailcrm_Customers_Test extends WC_Retailcrm_Test_Case_Helper $this->assertArrayHasKey('createdAt', $customer_send); $this->assertArrayHasKey('email', $customer_send); $this->assertNotEmpty($customer_send['externalId']); + $this->assertNotEmpty($customer_send['createdAt']); $this->assertNotEmpty($customer_send['firstName']); $this->assertNotEmpty($customer_send['email']); } else { @@ -115,6 +117,7 @@ class WC_Retailcrm_Customers_Test extends WC_Retailcrm_Test_Case_Helper $this->assertArrayHasKey('createdAt', $customer_send); $this->assertArrayHasKey('email', $customer_send); $this->assertNotEmpty($customer_send['externalId']); + $this->assertNotEmpty($customer_send['createdAt']); $this->assertNotEmpty($customer_send['firstName']); $this->assertNotEmpty($customer_send['email']); $this->assertInstanceOf('WC_Customer', $customer);