From c4fe1eae726aea968bcdd40e14de7a48dd9c3a60 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 | 6 +++ resources/pot/retailcrm-ru_RU.pot | 6 +++ .../class-wc-retailcrm-abstracts-settings.php | 23 ++++++++-- 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 6334 -> 6445 bytes src/languages/retailcrm-ru_RU.mo | Bin 7802 -> 7966 bytes 10 files changed, 56 insertions(+), 51 deletions(-) diff --git a/resources/pot/retailcrm-es_ES.pot b/resources/pot/retailcrm-es_ES.pot index 0d5e56d..536b254 100644 --- a/resources/pot/retailcrm-es_ES.pot +++ b/resources/pot/retailcrm-es_ES.pot @@ -222,3 +222,9 @@ msgstr "Transferencia de un número de pedido" msgid "Transferring the payment amount" msgstr "Transferencia de un monto de pago" + +msgid "Corporate customers support" +msgstr "Soporte a clientes corporativos" + +msgid "Enabled" +msgstr "Habilitado" diff --git a/resources/pot/retailcrm-ru_RU.pot b/resources/pot/retailcrm-ru_RU.pot index d8164b7..30cf233 100644 --- a/resources/pot/retailcrm-ru_RU.pot +++ b/resources/pot/retailcrm-ru_RU.pot @@ -231,3 +231,9 @@ msgstr "Передача номера заказа" msgid "Transferring the payment amount" msgstr "Передача суммы оплаты" + +msgid "Corporate customers support" +msgstr "Поддержка корпоративных клиентов" + +msgid "Enabled" +msgstr "Включено" diff --git a/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php b/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php index fdb66c3..a221a20 100644 --- a/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php +++ b/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php @@ -150,7 +150,16 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration 'description' => '', 'class' => 'checkbox', 'type' => 'checkbox', - 'desc_tip' => true, + '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( @@ -582,7 +591,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(); @@ -610,7 +621,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(); @@ -636,7 +649,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 d5326fd..3857bd0 100644 --- a/src/include/class-wc-retailcrm-base.php +++ b/src/include/class-wc-retailcrm-base.php @@ -359,7 +359,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' ); } @@ -398,7 +399,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 e5daf26..beb83c3 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 8ddd9c9..f82d936 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 004409f..9a3f844 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 45b2e9e18d69c48731225656990040cde5c2407c..8cc5fc41c4c74d645d23e9293fbb2342c192ec81 100644 GIT binary patch delta 1667 zcmXxkOGs2v9LMov&8U^yjMMuy*V4=^pOdMTWo2oSP(enxneT0}zMpL0C;pU*vW@7#ON|Np-}EAOvJe986P zFpNfG8PPVwm@wY)@WF7>jmf|~oQ*}8g&~}S^|%=K+WApj$vlQWyovL%50~PgJ^v|n zK4JcGpc`cKlqFb*Ik+A3a39uS4A)^lcH#&YV?$4B;Wn#cMbZ@7nW^ zQP;n+=ig%!&o|#W&`Qh6CyO*KsFbzZ`3dV;)PoXOiq|k72T=?AhK1;37p+*0^>`hZ z<2wxE1X5+=<7T>-32>m51(9l)GF*TgQMGJA2Tx-)_Ml4i2DQ);)b$g%4l_7Ol1vEW zX~xtc&ooKW%q8YI>i5HQ$-h!R%EuxcN0MRES&eG%M?Iht)jUn89k^J4mytj7h!35A zipt1GR0$@r2z`FagSA+Sm$4fk`^kSf2Wz-m4?c{W(M3JzKCZ==s3sc6{a6%8^~^=o z&aR?%bPKh^hju=I%FJu5!p~TX0UARaYf0FH4pi#S<00(B6{xH9Rs@mFm|ANys-|t| z;(26K<}31In4fn37uCdBtU{&ENA*}4YU7C-4tSP1jyv%Zmf&kVh`(?bHggxHya!d9 zC#WVGLG5@H)xF0n&njzE=#!#8~gKDBxyv+2F z*+{I`oKR_s3EgmdaJi`?$gpt;jqNGSR;x0jMe4qlM84jC4W&XusZqmdXKIu!#0FwL zp}J|OTBJsZP)b!MWl+0ThBTBR{S%^}r*=!*OpR^UY1SO$sM^lR+|=03r%IsuD)k!b zZZ+6ULa(TrR1K-#P}$VH6@-USLsk)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