From e1f98191b5f5c478eca4cb318b82db6eaa723f5e Mon Sep 17 00:00:00 2001 From: Akolzin Dmitry Date: Wed, 17 Jul 2019 15:59:35 +0300 Subject: [PATCH 1/5] Update travis.yml --- .travis.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5567970..68e204c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,8 +3,6 @@ language: php sudo: false php: - - 5.4 - - 5.5 - 5.6 - 7.0 - 7.1 @@ -15,8 +13,6 @@ env: matrix: fast_finish: true include: - - php: 5.3 - dist: precise - php: 7.2 env: WP_VERSION=latest WP_MULTISITE=0 RUN_PHPCS=1 From 3d8eb0cebe3baeb73809034e5ef7e7c62a31c535 Mon Sep 17 00:00:00 2001 From: Akolzin Dmitry Date: Wed, 17 Jul 2019 16:26:20 +0300 Subject: [PATCH 2/5] Update woocommerce installation --- tests/bin/install.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/bin/install.sh b/tests/bin/install.sh index 8e9f602..d3ca88c 100755 --- a/tests/bin/install.sh +++ b/tests/bin/install.sh @@ -73,6 +73,8 @@ install_woocommerce() { git clone https://github.com/woocommerce/woocommerce.git cd woocommerce git checkout master + composer install + npm install cd - } From 228488bec23f28800befe38ffa2230f26aa82c53 Mon Sep 17 00:00:00 2001 From: Akolzin Dmitry Date: Wed, 17 Jul 2019 17:47:11 +0300 Subject: [PATCH 3/5] Add trusty dist --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 68e204c..db239f2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,7 @@ language: php +dist: trusty + sudo: false php: From b8c1305eca0aa24128c8c8519610880f683f6e4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D1=80=D1=83=D0=B3=D0=BB=D0=BE=D0=B2=20=D0=94=D0=BC?= =?UTF-8?q?=D0=B8=D1=82=D1=80=D0=B8=D0=B9?= Date: Thu, 25 Jul 2019 12:07:20 +0300 Subject: [PATCH 4/5] fixed getting sku from product --- src/include/order/class-wc-retailcrm-order-item.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/include/order/class-wc-retailcrm-order-item.php b/src/include/order/class-wc-retailcrm-order-item.php index 96404e2..d5f6334 100644 --- a/src/include/order/class-wc-retailcrm-order-item.php +++ b/src/include/order/class-wc-retailcrm-order-item.php @@ -77,8 +77,13 @@ class WC_Retailcrm_Order_Item extends WC_Retailcrm_Abstracts_Data $uid = ($item['variation_id'] > 0) ? $item['variation_id'] : $item['product_id'] ; $offer = array('externalId' => $uid); - if (isset($this->settings['bind_by_sku']) && $this->settings['bind_by_sku'] == WC_Retailcrm_Base::YES) { - $offer['xmlId'] = $item->get_product()->get_sku(); + $product = $item->get_product(); + + if (!empty($product) && + isset($this->settings['bind_by_sku']) && + $this->settings['bind_by_sku'] == WC_Retailcrm_Base::YES + ) { + $offer['xmlId'] = $product->get_sku(); } $this->set_data_field('offer', $offer); From 1b2f0d053a99c688d8a21fd7721d65879fedf4e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9?= Date: Tue, 27 Aug 2019 15:14:34 +0300 Subject: [PATCH 5/5] fixed customer transmission --- src/include/class-wc-retailcrm-customers.php | 4 +- src/include/class-wc-retailcrm-orders.php | 49 +++++++++++--------- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/src/include/class-wc-retailcrm-customers.php b/src/include/class-wc-retailcrm-customers.php index f1adb1c..a7a180b 100644 --- a/src/include/class-wc-retailcrm-customers.php +++ b/src/include/class-wc-retailcrm-customers.php @@ -172,8 +172,8 @@ if (!class_exists('WC_Retailcrm_Customers')) : */ public function searchCustomer($filter) { - if (isset($filter['id'])) { - $search = $this->retailcrm->customersGet($filter['id']); + if (isset($filter['externalId'])) { + $search = $this->retailcrm->customersGet($filter['externalId']); } elseif (isset($filter['email'])) { $search = $this->retailcrm->customersList(array('email' => $filter['email'])); } diff --git a/src/include/class-wc-retailcrm-orders.php b/src/include/class-wc-retailcrm-orders.php index 44f5daf..992a44d 100644 --- a/src/include/class-wc-retailcrm-orders.php +++ b/src/include/class-wc-retailcrm-orders.php @@ -125,38 +125,45 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) : return null; } - $order = wc_get_order($order_id); - $this->processOrder($order); - $customer = $order->get_user(); + $wcOrder = wc_get_order($order_id); + $this->processOrder($wcOrder); + $wpUser = $wcOrder->get_user(); - if ($customer != false) { - $search = $this->customers->searchCustomer(array('id' => $customer->get('ID'))); + if ($wpUser instanceof WP_User) { + $wpUserId = (int)$wpUser->get('ID'); + $foundCustomer = $this->customers->searchCustomer(array( + 'externalId' => $wpUserId + )); - if (!$search) { - $this->customers->createCustomer($customer); - } else { - $this->order['customer']['externalId'] = $search['externalId']; - } - } else { - $search = $this->customers->searchCustomer(array('email' => $order->get_billing_email())); + if (empty($foundCustomer)) { + $customerId = $this->customers->createCustomer($wpUserId); - if (!$search) { - $new_customer = $this->customers->buildCustomerFromOrderData($order); - $id = $this->customers->createCustomer($new_customer); - - if ($id !== null) { - $this->order['customer']['id'] = $id; + if (!empty($customerId)) { + $this->order['customer']['id'] = $customerId; } } else { - $this->order['customer']['externalId'] = $search['externalId']; + $this->order['customer']['externalId'] = $foundCustomer['externalId']; } + } else { + $foundCustomer = $this->customers->searchCustomer(array( + 'email' => $wcOrder->get_billing_email() + )); - unset($new_customer); + if (empty($foundCustomer)) { + $wcCustomer = $this->customers->buildCustomerFromOrderData($wcOrder); + $customerId = $this->customers->createCustomer($wcCustomer); + + if (!empty($customerId)) { + $this->order['customer']['id'] = $customerId; + } + } else { + $this->order['customer']['externalId'] = $foundCustomer['externalId']; + } } $this->retailcrm->ordersCreate($this->order); - return $order; + return $wcOrder; } /**