From 4d5b38bb54df35be75ceccaf97eff8135e8ce687 Mon Sep 17 00:00:00 2001 From: Pavel Date: Mon, 3 Feb 2020 12:23:38 +0300 Subject: [PATCH] fixed createdAt crash --- src/include/class-wc-retailcrm-customers.php | 6 ++++++ src/include/class-wc-retailcrm-orders.php | 18 ++++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/include/class-wc-retailcrm-customers.php b/src/include/class-wc-retailcrm-customers.php index 81c33d0..f83ddf0 100644 --- a/src/include/class-wc-retailcrm-customers.php +++ b/src/include/class-wc-retailcrm-customers.php @@ -258,11 +258,17 @@ if (!class_exists('WC_Retailcrm_Customers')) : * @param WC_Customer $customer * * @return void + * @throws \Exception */ protected function processCustomer($customer) { $createdAt = $customer->get_date_created(); $firstName = $customer->get_first_name(); + + if (empty($createdAt)) { + $createdAt = new WC_DateTime(); + } + $data_customer = array( 'createdAt' => $createdAt->date('Y-m-d H:i:s'), 'firstName' => $firstName ? $firstName : $customer->get_username(), diff --git a/src/include/class-wc-retailcrm-orders.php b/src/include/class-wc-retailcrm-orders.php index 05c4673..6a0a5c5 100644 --- a/src/include/class-wc-retailcrm-orders.php +++ b/src/include/class-wc-retailcrm-orders.php @@ -229,15 +229,17 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) : 'contactIds' => array($foundCustomerId) ), true); - foreach ($crmCorporateList as $corporate) { - if (!empty($corporate) - && !empty($corporate['mainCompany']) - && isset($corporate['mainCompany']['name']) - && $corporate['mainCompany']['name'] == $wcOrder->get_billing_company() - ) { - $crmCorporate = $corporate; + if (!empty($crmCorporateList)) { + foreach ($crmCorporateList as $corporate) { + if (!empty($corporate) + && !empty($corporate['mainCompany']) + && isset($corporate['mainCompany']['name']) + && $corporate['mainCompany']['name'] == $wcOrder->get_billing_company() + ) { + $crmCorporate = $corporate; - break; + break; + } } }