From f7a069498828851784fe4d2eb84f2a1ae7dfa59f Mon Sep 17 00:00:00 2001 From: Pavel Date: Wed, 4 Dec 2019 11:26:36 +0300 Subject: [PATCH] option to enable or disable corporate customers support --- resources/pot/retailcrm-es_ES.pot | 8 +++- resources/pot/retailcrm-ru_RU.pot | 8 +++- .../class-wc-retailcrm-abstracts-settings.php | 21 +++++++-- src/include/api/class-wc-retailcrm-proxy.php | 14 +++++- src/include/class-wc-retailcrm-base.php | 6 ++- src/include/class-wc-retailcrm-customers.php | 42 +----------------- src/include/class-wc-retailcrm-history.php | 6 ++- src/include/class-wc-retailcrm-orders.php | 4 +- src/languages/retailcrm-es_ES.mo | Bin 6252 -> 6363 bytes src/languages/retailcrm-ru_RU.mo | Bin 7713 -> 7877 bytes 10 files changed, 57 insertions(+), 52 deletions(-) diff --git a/resources/pot/retailcrm-es_ES.pot b/resources/pot/retailcrm-es_ES.pot index 034c141..f871c3d 100644 --- a/resources/pot/retailcrm-es_ES.pot +++ b/resources/pot/retailcrm-es_ES.pot @@ -218,4 +218,10 @@ msgid "Enable transferring the number to retailCRM" msgstr "Activar la transferencia de números en retailCRM" msgid "Transferring the order number" -msgstr "Transferencia de un número de pedido" \ No newline at end of file +msgstr "Transferencia de un número de pedido" + +msgid "Corporate customers support" +msgstr "Soporte a clientes corporativos" + +msgid "Enabled" +msgstr "Habilitado" \ No newline at end of file diff --git a/resources/pot/retailcrm-ru_RU.pot b/resources/pot/retailcrm-ru_RU.pot index 49f83db..8c0a751 100644 --- a/resources/pot/retailcrm-ru_RU.pot +++ b/resources/pot/retailcrm-ru_RU.pot @@ -227,4 +227,10 @@ msgid "Enable transferring the number to retailCRM" msgstr "Активировать передачу номера в retailCRM" msgid "Transferring the order number" -msgstr "Передача номера заказа" \ No newline at end of file +msgstr "Передача номера заказа" + +msgid "Corporate customers support" +msgstr "Поддержка корпоративных клиентов" + +msgid "Enabled" +msgstr "Включено" \ No newline at end of file diff --git a/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php b/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php index 45bde07..46723d1 100644 --- a/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php +++ b/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php @@ -144,6 +144,15 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration 'desc_tip' => true, ); + $this->form_fields['corporate_enabled'] = array( + 'title' => __('Corporate customers support', 'retailcrm'), + 'label' => __('Enabled'), + 'description' => '', + 'class' => 'checkbox', + 'type' => 'checkbox', + 'desc_tip' => true + ); + $this->form_fields[] = array( 'title' => __( 'Catalog settings', 'retailcrm' ), 'type' => 'title', @@ -573,7 +582,9 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration $api = new WC_Retailcrm_Proxy( $post[$this->plugin_id . $this->id . '_api_url'], - $post[$this->plugin_id . $this->id . '_api_key'] + $post[$this->plugin_id . $this->id . '_api_key'], + null, + $this->get_option('corporate_enabled', 'no') === 'yes' ); $response = $api->apiVersions(); @@ -601,7 +612,9 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration $post = $this->get_post_data(); $api = new WC_Retailcrm_Proxy( $value, - $post[$this->plugin_id . $this->id . '_api_key'] + $post[$this->plugin_id . $this->id . '_api_key'], + null, + $this->get_option('corporate_enabled', 'no') === 'yes' ); $response = $api->apiVersions(); @@ -627,7 +640,9 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration $post = $this->get_post_data(); $api = new WC_Retailcrm_Proxy( $post[$this->plugin_id . $this->id . '_api_url'], - $value + $value, + null, + $this->get_option('corporate_enabled', 'no') === 'yes' ); $response = $api->apiVersions(); diff --git a/src/include/api/class-wc-retailcrm-proxy.php b/src/include/api/class-wc-retailcrm-proxy.php index 3b15166..1618717 100644 --- a/src/include/api/class-wc-retailcrm-proxy.php +++ b/src/include/api/class-wc-retailcrm-proxy.php @@ -15,11 +15,13 @@ if ( ! class_exists( 'WC_Retailcrm_Proxy' ) ) : class WC_Retailcrm_Proxy { protected $retailcrm; + protected $corporateEnabled; protected $logger; - public function __construct($api_url, $api_key, $api_vers = null) + public function __construct($api_url, $api_key, $api_vers = null, $corporateEnabled = false) { $this->logger = new WC_Logger(); + $this->corporateEnabled = $corporateEnabled; if ( ! class_exists( 'WC_Retailcrm_Client_V4' ) ) { include_once( __DIR__ . '/class-wc-retailcrm-client-v4.php' ); @@ -42,6 +44,16 @@ if ( ! class_exists( 'WC_Retailcrm_Proxy' ) ) : } } + /** + * getCorporateEnabled + * + * @return bool + */ + public function getCorporateEnabled() + { + return $this->corporateEnabled; + } + public function __call($method, $arguments) { try { diff --git a/src/include/class-wc-retailcrm-base.php b/src/include/class-wc-retailcrm-base.php index 3df57db..7fb8cb5 100644 --- a/src/include/class-wc-retailcrm-base.php +++ b/src/include/class-wc-retailcrm-base.php @@ -329,7 +329,8 @@ if (!class_exists('WC_Retailcrm_Base')) { return new WC_Retailcrm_Proxy( $this->get_option('api_url'), $this->get_option('api_key'), - $this->get_option('api_version') + $this->get_option('api_version'), + $this->get_option('corporate_enabled', 'no') === 'yes' ); } @@ -368,7 +369,8 @@ if (!class_exists('WC_Retailcrm_Base')) { $api_client = new WC_Retailcrm_Proxy( $settings['api_url'], $settings['api_key'], - $settings['api_version'] + $settings['api_version'], + $settings['corporate_enabled'] === 'yes' ); $result = WC_Retailcrm_Plugin::integration_module($api_client, $client_id, $settings['api_version']); diff --git a/src/include/class-wc-retailcrm-customers.php b/src/include/class-wc-retailcrm-customers.php index 134ac25..7b87aa4 100644 --- a/src/include/class-wc-retailcrm-customers.php +++ b/src/include/class-wc-retailcrm-customers.php @@ -70,46 +70,6 @@ if (!class_exists('WC_Retailcrm_Customers')) : return $this; } - /** - * Returns true if corporate customers are enabled and accessible - * - * @param WC_Retailcrm_Client_V5|\WC_Retailcrm_Proxy $apiClient - * - * @return bool - */ - public static function isCorporateEnabledInApi($apiClient) - { - if (is_object($apiClient)) { - $requiredMethods = array( - "/api/customers-corporate", - "/api/customers-corporate/create", - "/api/customers-corporate/fix-external-ids", - "/api/customers-corporate/notes", - "/api/customers-corporate/notes/create", - "/api/customers-corporate/notes/{id}/delete", - "/api/customers-corporate/history", - "/api/customers-corporate/upload", - "/api/customers-corporate/{externalId}", - "/api/customers-corporate/{externalId}/edit" - ); - - $credentials = $apiClient->credentials(); - - if ($credentials && isset($credentials['credentials'])) { - $existingMethods = array_filter( - $credentials['credentials'], - function ($val) use ($requiredMethods) { - return in_array($val, $requiredMethods); - } - ); - - return count($requiredMethods) == count($existingMethods); - } - } - - return false; - } - /** * Is corporate customers enabled in provided API * @@ -121,7 +81,7 @@ if (!class_exists('WC_Retailcrm_Customers')) : return false; } - return static::isCorporateEnabledInApi($this->retailcrm); + return $this->retailcrm->getCorporateEnabled(); } /** diff --git a/src/include/class-wc-retailcrm-history.php b/src/include/class-wc-retailcrm-history.php index 77879bb..960bc55 100644 --- a/src/include/class-wc-retailcrm-history.php +++ b/src/include/class-wc-retailcrm-history.php @@ -79,7 +79,11 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) : } $this->customersHistory($this->startDateCustomers->format('Y-m-d H:i:s'), $customers_since_id); - $this->customersCorporateHistory($this->startDateCustomersCorporate->format('Y-m-d H:i:s'), $customers_corporate_since_id); + + if ($this->retailcrm->getCorporateEnabled()) { + $this->customersCorporateHistory($this->startDateCustomersCorporate->format('Y-m-d H:i:s'), $customers_corporate_since_id); + } + $this->ordersHistory($this->startDateOrders->format('Y-m-d H:i:s'), $orders_since_id); } diff --git a/src/include/class-wc-retailcrm-orders.php b/src/include/class-wc-retailcrm-orders.php index 1d8f8d7..3291c5a 100644 --- a/src/include/class-wc-retailcrm-orders.php +++ b/src/include/class-wc-retailcrm-orders.php @@ -72,7 +72,7 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) : return null; } - $isCorporateEnabled = WC_Retailcrm_Customers::isCorporateEnabledInApi($this->retailcrm); + $isCorporateEnabled = $this->retailcrm->getCorporateEnabled(); $uploader = new WC_Retailcrm_Customers( $this->retailcrm, $this->retailcrm_settings, @@ -212,7 +212,7 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) : return null; } - $isCorporateEnabled = $forceRegularCustomer ? false : WC_Retailcrm_Customers::isCorporateEnabledInApi($this->retailcrm); + $isCorporateEnabled = $forceRegularCustomer ? false : $this->retailcrm->getCorporateEnabled(); $wcOrder = wc_get_order($order_id); $this->processOrder($wcOrder); $wpUser = $wcOrder->get_user(); diff --git a/src/languages/retailcrm-es_ES.mo b/src/languages/retailcrm-es_ES.mo index ab3f8c43638c9d5d739c087002577291c8adf05d..75ffdea63908777151c1c30d3f9a1dd55e053028 100644 GIT binary patch delta 1651 zcmXxkYeM3=w;gAl*P;6k+%_sTUFTBIx_u9uNNaIcLwa^PKZP|HtoDpQ~eEb8KCP zR!__(_DnLyiybyTXxVATq@xoZn2%Gi1T(Q3^Kq>;ZpOKc{g{mxaR%N*7xq}!-zKle z%y&AP;2#!X9#5NwHCT)uT#0_H#5;Ht2eAU{GLj4Q;$p@@)O@#48+w7O@g45K%*n}x z?Z>GmX3Q}PDK~#&<@K`<5gIT4VZ&xaXMbJu0KHC zAGfX#;5MFbM(Ajz#pIJknsum@)m!63mPb$z3gHqwizV2DTG&Tih}uOnl%faE;T-Ho zPS=bgx0*4GX+=Nikp0B$Ga;R)=nMde2P9+1lFR5bZmgmpL{n~*g)sfrco0>*Ur=ZL3sqZMm3BTEncBow)7eaCCoaY=+=~Oa61P{a|yN6 zE2yHqjdpyA{KULM)y^kW27jYo-(t>LM|A*Mi)lyhkD04rZ518Nz1|5Yg3*%BgA1GtFLd1iJ(ZRsYNfM zO%Mr1vn?#50%_wSg2XVWok0=^3PIoB%(a8(e$KgbALso4|La2Ka)tMs$92bOZS*vH z>n5`v9CmS_{SGsWz!lt#YZ#5LaI+|k$5c#r=Czp3yanTM0F&^dbN+^N{snTM*WNPN z#sv$w1y?Z(!+2{w=3@!=;5nSeVqC*A%ykDBa16D95!{Q{u@gU{7Lpuk7K8a1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