From fec8645764837fc21d6367bd47d1b1677985c91e Mon Sep 17 00:00:00 2001 From: Neur0toxine Date: Thu, 18 Jun 2020 11:15:49 +0300 Subject: [PATCH] State fix --- CHANGELOG.md | 3 +++ VERSION | 2 +- .../class-wc-retailcrm-abstracts-address.php | 22 +++++++++++++++++++ src/include/class-wc-retailcrm-history.php | 3 ++- .../class-wc-retailcrm-customer-address.php | 2 +- .../class-wc-retailcrm-order-address.php | 2 +- src/readme.txt | 3 +++ src/retailcrm.php | 2 +- src/uninstall.php | 2 +- 9 files changed, 35 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d0f090a..1e01c0c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2020-06-18 3.6.4 +* Передача названия региона / штата / провинции вместо кода + ## 2020-06-10 3.6.3 * Улучшено обновление данных заказа по истории diff --git a/VERSION b/VERSION index 4a788a0..0f44168 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.6.3 +3.6.4 diff --git a/src/include/abstracts/class-wc-retailcrm-abstracts-address.php b/src/include/abstracts/class-wc-retailcrm-abstracts-address.php index b27cdc8..f951aec 100644 --- a/src/include/abstracts/class-wc-retailcrm-abstracts-address.php +++ b/src/include/abstracts/class-wc-retailcrm-abstracts-address.php @@ -27,4 +27,26 @@ abstract class WC_Retailcrm_Abstracts_Address extends WC_Retailcrm_Abstracts_Dat 'text' => '', ); } + + /** + * Returns state name by it's code + * + * @param string $countryCode + * @param string $stateCode + * + * @return string + */ + protected function get_state_name($countryCode, $stateCode) + { + if (preg_match('/^[A-Z\-0-9]{0,5}$/', $stateCode) && !is_null($countryCode)) { + $countriesProvider = new WC_Countries(); + $states = $countriesProvider->get_states($countryCode); + + if (!empty($states) && array_key_exists($stateCode, $states)) { + return (string) $states[$stateCode]; + } + } + + return $stateCode; + } } diff --git a/src/include/class-wc-retailcrm-history.php b/src/include/class-wc-retailcrm-history.php index 900329c..3ad26b3 100644 --- a/src/include/class-wc-retailcrm-history.php +++ b/src/include/class-wc-retailcrm-history.php @@ -628,7 +628,8 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) : } if (!empty($arItemsOld)) { - $result = end(array_diff($arItemsNew, $arItemsOld)); + $diff = array_diff($arItemsNew, $arItemsOld); + $result = end($diff); } else { $result = end($arItemsNew); } diff --git a/src/include/customer/class-wc-retailcrm-customer-address.php b/src/include/customer/class-wc-retailcrm-customer-address.php index 621fc72..198f170 100644 --- a/src/include/customer/class-wc-retailcrm-customer-address.php +++ b/src/include/customer/class-wc-retailcrm-customer-address.php @@ -26,7 +26,7 @@ class WC_Retailcrm_Customer_Address extends WC_Retailcrm_Abstracts_Address $data = array( 'index' => $customer->get_billing_postcode(), 'countryIso' => $customer->get_billing_country(), - 'region' => $customer->get_billing_state(), + 'region' => $this->get_state_name($customer->get_billing_country(), $customer->get_billing_state()), 'city' => $customer->get_billing_city(), 'text' => $customer->get_billing_address_1() . ', ' . $customer->get_billing_address_2() ); diff --git a/src/include/order/class-wc-retailcrm-order-address.php b/src/include/order/class-wc-retailcrm-order-address.php index 308d70f..82522d3 100644 --- a/src/include/order/class-wc-retailcrm-order-address.php +++ b/src/include/order/class-wc-retailcrm-order-address.php @@ -26,7 +26,7 @@ class WC_Retailcrm_Order_Address extends WC_Retailcrm_Abstracts_Address $data = array( 'index' => $address['postcode'], 'city' => $address['city'], - 'region' => $address['state'] + 'region' => $this->get_state_name($address['country'], $address['state']) ); $this->set_data_fields($data); diff --git a/src/readme.txt b/src/readme.txt index 3200728..3afba74 100644 --- a/src/readme.txt +++ b/src/readme.txt @@ -45,6 +45,9 @@ API-ключ должен быть для отдельного магазина 2. В появившихся списках справочников настройте соответствие способов доставки и оплаты, а так же статусов заказов. Отметьте галочку "Выгружать остатки", если хотите выгружать остатки из Retailcrm в магазин (подробнее смотрите в описании). == Changelog == += 3.6.4 = +* Передача названия региона / штата / провинции вместо кода + = 3.6.3 = * Улучшено обновление данных заказа по истории diff --git a/src/retailcrm.php b/src/retailcrm.php index 094ae23..fbb44b9 100644 --- a/src/retailcrm.php +++ b/src/retailcrm.php @@ -1,6 +1,6 @@