From 4ef67f595e27d0726f10629e9c8747b51b3998b4 Mon Sep 17 00:00:00 2001 From: Dima Uryvskiy Date: Tue, 27 Jul 2021 13:09:30 +0300 Subject: [PATCH] ICML catalog settings updating --- .../class-wc-retailcrm-abstracts-settings.php | 114 ++++++++++-------- 1 file changed, 65 insertions(+), 49 deletions(-) diff --git a/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php b/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php index ac71d42..a28bc8d 100644 --- a/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php +++ b/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php @@ -107,55 +107,9 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration ) ); - $this->form_fields[] = array( - 'title' => __( 'API settings', 'retailcrm' ), - 'type' => 'title', - 'description' => '', - 'id' => 'api_options' - ); - - $this->form_fields['send_delivery_net_cost'] = array( - 'title' => __( 'Do not transmit the cost of delivery', 'retailcrm' ), - 'label' => ' ', - 'description' => '', - 'class' => 'checkbox', - 'type' => 'checkbox', - '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['online_assistant'] = array( - 'title' => __( 'Online assistant', 'retailcrm' ), - 'type' => 'textarea', - 'id' => 'online_assistant', - 'placeholder' => __( 'Insert the Online consultant code here', 'retailcrm' ) - ); - - $this->form_fields[] = array( - 'title' => __( 'Catalog settings', 'retailcrm' ), - 'type' => 'title', - 'description' => '', - 'id' => 'catalog_options' - ); - - foreach (get_post_statuses() as $status_key => $status_value) { - $this->form_fields['p_' . $status_key] = array( - 'title' => $status_value, - 'label' => ' ', - 'description' => '', - 'class' => 'checkbox', - 'type' => 'checkbox', - 'desc_tip' => true, - ); - } + $post = $this->get_post_data(); + $apiUrl = !empty($post[$this->plugin_id . $this->id . '_api_url']) ? $post[$this->plugin_id . $this->id . '_api_url'] : null; + $apiKey = !empty($post[$this->plugin_id . $this->id . '_api_key']) ? $post[$this->plugin_id . $this->id . '_api_key'] : null; if ($this->apiClient) { if (isset($_GET['page']) && $_GET['page'] == 'wc-settings' @@ -163,6 +117,56 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration ) { add_action('admin_print_footer_scripts', array($this, 'show_blocks'), 99); + $this->form_fields[] = array( + 'title' => __( 'API settings', 'retailcrm' ), + 'type' => 'title', + 'description' => '', + 'id' => 'api_options' + ); + + $this->form_fields['send_delivery_net_cost'] = array( + 'title' => __( 'Do not transmit the cost of delivery', 'retailcrm' ), + 'label' => ' ', + 'description' => '', + 'class' => 'checkbox', + 'type' => 'checkbox', + '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['online_assistant'] = array( + 'title' => __( 'Online assistant', 'retailcrm' ), + 'type' => 'textarea', + 'id' => 'online_assistant', + 'placeholder' => __( 'Insert the Online consultant code here', 'retailcrm' ) + ); + + $this->form_fields[] = array( + 'title' => __( 'Catalog settings', 'retailcrm' ), + 'type' => 'heading', + 'description' => '', + 'id' => 'catalog_options' + ); + + foreach (get_post_statuses() as $status_key => $status_value) { + $this->form_fields['p_' . $status_key] = array( + 'title' => $status_value, + 'label' => ' ', + 'description' => '', + 'class' => 'checkbox', + 'type' => 'checkbox', + 'desc_tip' => true, + ); + } + /** * Client roles options */ @@ -550,6 +554,18 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration 'class' => 'debug_info_options' ); } + } elseif (empty($apiUrl) === false && empty($apiKey) === false) { + $api = new WC_Retailcrm_Proxy( + $apiUrl, + $apiKey, + $this->get_option('corporate_enabled', 'no') === 'yes' + ); + + $response = $api->apiVersions(); + + if ($response->isSuccessful()) { + header("Refresh:0"); + } } }