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 ab3f8c4..75ffdea 100644 Binary files a/src/languages/retailcrm-es_ES.mo and b/src/languages/retailcrm-es_ES.mo differ diff --git a/src/languages/retailcrm-ru_RU.mo b/src/languages/retailcrm-ru_RU.mo index 8c3749c..9028ce8 100644 Binary files a/src/languages/retailcrm-ru_RU.mo and b/src/languages/retailcrm-ru_RU.mo differ