1
0
mirror of synced 2025-01-18 17:01:41 +03:00

Fix fatal error when using API without api_key

This commit is contained in:
Dima Uryvskiy 2022-05-26 17:13:35 +03:00 committed by GitHub
parent e1e7331f89
commit c9294d62a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 247 additions and 200 deletions

View File

@ -1,3 +1,11 @@
## 2022-05-26 4.4.4
* Add product description to ICML
* Fix fatal error using API without api_key
* Add priceType processing to CRM order by history
* Add method in API V5 and delete use another version
* Fix error with integration payments
* Fix bug with changing order status by history
## 2022-03-24 4.4.3
* Fix bug in updating order number by history
* Add multiple image transfer in ICML

View File

@ -1 +1 @@
4.4.3
4.4.4

View File

@ -67,9 +67,6 @@ msgstr "Introduce la llave API correcta"
msgid "Enter the correct URL of Simla.com"
msgstr "Introduce el enlace del Simla.com correcto"
msgid "The selected API version is unavailable"
msgstr "La versión de API elegida no está disponible"
msgid "This functionality allows to generate ICML products catalog for uploading to Simla.com"
msgstr "Esta función permite generar los catálogos de pedidos ICML para subida al Simla.com"

View File

@ -76,9 +76,6 @@ msgstr "Введите корректный API ключ"
msgid "Enter the correct URL of Simla.com"
msgstr "Введите корректный адрес Simla.com"
msgid "The selected API version is unavailable"
msgstr "Выбранная версия API недоступна"
msgid "This functionality allows to generate ICML products catalog for uploading to Simla.com"
msgstr "Эта функция позволяет сгенерировать ICML каталог товаров для выгрузки в Simla.com"

View File

@ -36,7 +36,7 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration
isset($_GET['page']) && $_GET['page'] == 'wc-settings'
&& isset($_GET['tab']) && $_GET['tab'] == 'integration'
) {
add_action('init', array($this, 'init_settings_fields'), 99);
add_action('init', [$this, 'init_settings_fields'], 99);
}
}
@ -67,24 +67,24 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration
*/
public function init_form_fields()
{
$this->form_fields = array(
array( 'title' => __('Main settings', 'retailcrm'), 'type' => 'title', 'desc' => '', 'id' => 'general_options' ),
$this->form_fields = [
[ 'title' => __('Main settings', 'retailcrm'), 'type' => 'title', 'desc' => '', 'id' => 'general_options' ],
'api_url' => array(
'api_url' => [
'title' => __('API of URL', 'retailcrm'),
'type' => 'text',
'description' => __( 'Enter API of URL (https://yourdomain.simla.com)', 'retailcrm' ),
'desc_tip' => true,
'default' => ''
),
'api_key' => array(
],
'api_key' => [
'title' => __('API key', 'retailcrm'),
'type' => 'text',
'description' => __('Enter your API key. You can find it in the administration section of Simla.com', 'retailcrm'),
'desc_tip' => true,
'default' => ''
)
);
]
];
$post = $this->get_post_data();
$apiUrl = !empty($post[$this->plugin_id . $this->id . '_api_url']) ? $post[$this->plugin_id . $this->id . '_api_url'] : null;
@ -95,37 +95,37 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration
isset($_GET['page']) && $_GET['page'] == 'wc-settings'
&& isset($_GET['tab']) && $_GET['tab'] == 'integration'
) {
add_action('admin_print_footer_scripts', array($this, 'show_blocks'), 99);
add_action('admin_print_footer_scripts', [$this, 'show_blocks'], 99);
$this->form_fields[] = array(
$this->form_fields[] = [
'title' => __('API settings', 'retailcrm'),
'type' => 'title',
'description' => '',
'id' => 'api_options'
);
];
$this->form_fields['corporate_enabled'] = array(
$this->form_fields['corporate_enabled'] = [
'title' => __('Corporate customers support', 'retailcrm'),
'label' => __('Enabled'),
'description' => '',
'class' => 'checkbox',
'type' => 'checkbox',
'desc_tip' => true
);
];
$this->form_fields['online_assistant'] = array(
$this->form_fields['online_assistant'] = [
'title' => __('Online assistant', 'retailcrm'),
'type' => 'textarea',
'id' => 'online_assistant',
'placeholder' => __('Insert the Online consultant code here', 'retailcrm')
);
];
$this->form_fields[] = array(
$this->form_fields[] = [
'title' => __('Catalog settings', 'retailcrm'),
'type' => 'heading',
'description' => '',
'id' => 'catalog_options'
);
];
$this->form_fields['product_description'] = [
'type' => 'select',
@ -143,20 +143,21 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration
];
foreach (get_post_statuses() as $status_key => $status_value) {
$this->form_fields['p_' . $status_key] = array(
$this->form_fields['p_' . $status_key] = [
'title' => $status_value,
'label' => ' ',
'description' => '',
'class' => 'checkbox',
'type' => 'checkbox',
'desc_tip' => true,
);
'desc_tip' => true,
];
}
/**
* Order methods options
*/
$order_methods_option = array();
$order_methods_option = [];
$order_methods_list = $this->apiClient->orderMethodsList();
if (!empty($order_methods_list) && $order_methods_list->isSuccessful()) {
@ -168,23 +169,26 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration
$order_methods_option[$order_method['code']] = $order_method['name'];
}
$this->form_fields[] = array(
$this->form_fields[] = [
'title' => __('Order methods', 'retailcrm'),
'type' => 'heading',
'description' => '',
'id' => 'order_methods_options'
);
];
$this->form_fields['order_methods'] = array(
$this->form_fields['order_methods'] = [
'label' => ' ',
'title' => __('Order methods available for uploading from Simla.com', 'retailcrm'),
'class' => '',
'type' => 'multiselect',
'description' => __('Select order methods which will be uploaded from Simla.com to the website', 'retailcrm'),
'options' => $order_methods_option,
'css' => 'min-height:100px;',
'select_buttons' => true
);
'select_buttons' => true,
'description' => __(
'Select order methods which will be uploaded from Simla.com to the website',
'retailcrm'
),
];
}
/**
@ -213,7 +217,7 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration
foreach ($wc_shipping_list as $shipping_code => $shipping) {
if (isset($shipping['enabled']) && $shipping['enabled'] == static::YES) {
$this->form_fields[$shipping_code] = array(
$this->form_fields[$shipping_code] = [
'title' => __($shipping['title'], 'woocommerce'),
'description' => __($shipping['description'], 'woocommerce'),
'css' => 'min-width:350px;',
@ -221,7 +225,7 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration
'type' => 'select',
'options' => $shipping_option_list,
'desc_tip' => true,
);
];
}
}
}
@ -327,236 +331,242 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration
/**
* Meta data options
*/
$this->form_fields[] = array(
'title' => __('Custom fields', 'retailcrm'),
'type' => 'heading',
'description' => '',
'class' => 'meta-fields'
);
$this->form_fields[] = [
'title' => __('Custom fields', 'retailcrm'),
'type' => 'heading',
'description' => '',
'class' => 'meta-fields'
];
$this->form_fields['order-meta-data-retailcrm'] = array(
$this->form_fields['order-meta-data-retailcrm'] = [
'type' => 'textarea',
'class' => 'order-meta-data-retailcrm',
);
];
$this->form_fields['customer-meta-data-retailcrm'] = array(
$this->form_fields['customer-meta-data-retailcrm'] = [
'type' => 'textarea',
'class' => 'customer-meta-data-retailcrm',
);
];
/**
* Inventories options
*/
$this->form_fields[] = array(
$this->form_fields[] = [
'title' => __('Setting of the stock balance', 'retailcrm'),
'type' => 'heading',
'description' => '',
'id' => 'invent_options'
);
];
$this->form_fields['sync'] = array(
$this->form_fields['sync'] = [
'label' => __('Synchronization of the stock balance', 'retailcrm'),
'title' => __('Stock balance', 'retailcrm'),
'class' => 'checkbox',
'type' => 'checkbox',
'description' => __('Enable this setting if you would like to get information on leftover stocks from Simla.com to the website', 'retailcrm')
);
];
/**
* UA options
*/
$this->form_fields[] = array(
$this->form_fields[] = [
'title' => __('UA settings', 'retailcrm'),
'type' => 'heading',
'description' => '',
'id' => 'ua_options'
);
];
$this->form_fields['ua'] = array(
$this->form_fields['ua'] = [
'label' => __('Activate UA', 'retailcrm'),
'title' => __('UA', 'retailcrm'),
'class' => 'checkbox',
'type' => 'checkbox',
'description' => __('Enable this setting for uploading data to UA', 'retailcrm')
);
];
$this->form_fields['ua_code'] = array(
$this->form_fields['ua_code'] = [
'title' => __('UA tracking code', 'retailcrm'),
'class' => 'input',
'type' => 'input'
);
];
$this->form_fields['ua_custom'] = array(
$this->form_fields['ua_custom'] = [
'title' => __('User parameter', 'retailcrm'),
'class' => 'input',
'type' => 'input'
);
];
/**
* Daemon collector settings
*/
$this->form_fields[] = array(
$this->form_fields[] = [
'title' => __('Daemon Collector settings', 'retailcrm'),
'type' => 'heading',
'description' => '',
'id' => 'invent_options'
);
];
$this->form_fields['daemon_collector'] = array(
$this->form_fields['daemon_collector'] = [
'label' => __('Activate Daemon Collector', 'retailcrm'),
'title' => __('Daemon Collector', 'retailcrm'),
'class' => 'checkbox',
'type' => 'checkbox',
'description' => __('Enable this setting for activate Daemon Collector on site', 'retailcrm')
);
];
$this->form_fields['daemon_collector_key'] = array(
$this->form_fields['daemon_collector_key'] = [
'title' => __('Site key', 'retailcrm'),
'class' => 'input',
'type' => 'input'
);
];
/**
* Uploads options
*/
$this->form_fields[] = array(
$this->form_fields[] = [
'title' => __('Settings of uploading', 'retailcrm'),
'type' => 'heading',
'description' => '',
'id' => 'upload_options'
);
];
$this->form_fields['upload-button'] = array(
$this->form_fields['upload-button'] = [
'label' => __('Upload', 'retailcrm'),
'title' => __('Uploading all customers and orders', 'retailcrm'),
'type' => 'button',
'description' => __('You can export all orders and customers from CMS to Simla.com by clicking the «Upload» button. This process can take much time and before it is completed, you need to keep the tab open', 'retailcrm'),
'desc_tip' => true,
'id' => 'export-orders-submit'
);
];
$this->form_fields['export_selected_orders_ids'] = array(
$this->form_fields['export_selected_orders_ids'] = [
'label' => __('Orders identifiers', 'retailcrm'),
'title' => __('Orders identifiers', 'retailcrm'),
'type' => 'text',
'description' => __('Enter orders identifiers separated by a comma, but no more than 50', 'retailcrm'),
'desc_tip' => true,
'id' => 'export_selected_orders_ids'
);
];
$this->form_fields['export_selected_orders_btn'] = array(
$this->form_fields['export_selected_orders_btn'] = [
'label' => __('Upload', 'retailcrm'),
'title' => __('Uploading orders by identifiers', 'retailcrm'),
'type' => 'button',
'description' => __('This functionality allows to upload orders to Simla.com differentially', 'retailcrm'),
'desc_tip' => true,
'id' => 'export_selected_orders_btn'
);
];
/**
* WhatsApp options
*/
$this->form_fields[] = array(
$this->form_fields[] = [
'title' => __('Settings of WhatsApp', 'retailcrm'),
'type' => 'heading',
'description' => '',
'id' => 'whatsapp_options'
);
];
$this->form_fields['whatsapp_active'] = array(
$this->form_fields['whatsapp_active'] = [
'label' => __('Activate WhatsApp', 'retailcrm'),
'title' => __('WhatsApp', 'retailcrm'),
'class' => 'checkbox',
'type' => 'checkbox',
'description' => __('Activate this setting to activate WhatsApp on the website', 'retailcrm')
);
];
$this->form_fields['whatsapp_location_icon'] = array(
$this->form_fields['whatsapp_location_icon'] = [
'label' => __('Place in the lower right corner of the website', 'retailcrm'),
'title' => __('WhatsApp icon location', 'retailcrm'),
'class' => 'checkbox',
'type' => 'checkbox',
'description' => __('By default, WhatsApp icon is located in the lower left corner of the website', 'retailcrm')
);
'description' => __(
'By default, WhatsApp icon is located in the lower left corner of the website',
'retailcrm'
)
];
$this->form_fields['whatsapp_number'] = array(
$this->form_fields['whatsapp_number'] = [
'title' => __('Enter your phone number', 'retailcrm'),
'class' => '',
'type' => 'text',
'description' => __('WhatsApp chat will be opened with this contact', 'retailcrm')
);
];
/**
* Generate icml file
*/
$this->form_fields[] = array(
$this->form_fields[] = [
'title' => __('Generating ICML catalog', 'retailcrm'),
'type' => 'title',
'description' => '',
'id' => 'icml_options'
);
];
$this->form_fields[] = array(
$this->form_fields[] = [
'label' => __('Generate now', 'retailcrm'),
'title' => __('Generating ICML', 'retailcrm'),
'type' => 'button',
'description' => __('This functionality allows to generate ICML products catalog for uploading to Simla.com', 'retailcrm'),
'desc_tip' => true,
'id' => 'icml-retailcrm'
);
'id' => 'icml-retailcrm',
'description' => __(
'This functionality allows to generate ICML products catalog for uploading to Simla.com',
'retailcrm'
),
];
$this->form_fields['icml'] = array(
$this->form_fields['icml'] = [
'label' => __('Generating ICML', 'retailcrm'),
'title' => __('Generating ICML catalog by wp-cron', 'retailcrm'),
'class' => 'checkbox',
'type' => 'checkbox'
);
];
$this->form_fields['history'] = array(
$this->form_fields['history'] = [
'label' => __('Activate history uploads', 'retailcrm'),
'title' => __('Upload data from Simla.com', 'retailcrm'),
'class' => 'checkbox',
'type' => 'checkbox'
);
];
$this->form_fields['deactivate_update_order'] = array(
'label' => __('Disable data editing in Simla.com', 'retailcrm'),
'title' => __('Data updating in Simla.com', 'retailcrm'),
'class' => 'checkbox',
'type' => 'checkbox'
);
$this->form_fields['deactivate_update_order'] = [
'label' => __('Disable data editing in Simla.com', 'retailcrm'),
'title' => __('Data updating in Simla.com', 'retailcrm'),
'class' => 'checkbox',
'type' => 'checkbox'
];
$this->form_fields['bind_by_sku'] = array(
'label' => __('Activate the binding via sku (xml)', 'retailcrm'),
'title' => __('Stock synchronization and link between products', 'retailcrm'),
'class' => 'checkbox',
'type' => 'checkbox'
);
$this->form_fields['bind_by_sku'] = [
'label' => __('Activate the binding via sku (xml)', 'retailcrm'),
'title' => __('Stock synchronization and link between products', 'retailcrm'),
'class' => 'checkbox',
'type' => 'checkbox'
];
$this->form_fields['update_number'] = array(
'label' => __('Enable transferring the number to Simla.com', 'retailcrm'),
'title' => __('Transferring the order number', 'retailcrm'),
'class' => 'checkbox',
'type' => 'checkbox'
);
$this->form_fields['update_number'] = [
'label' => __('Enable transferring the number to Simla.com', 'retailcrm'),
'title' => __('Transferring the order number', 'retailcrm'),
'class' => 'checkbox',
'type' => 'checkbox'
];
$this->form_fields['debug_mode'] = array(
'label' => __('Enable debug mode in module', 'retailcrm'),
'title' => __('Debug mode', 'retailcrm'),
'description' => __('Is required to enable debug mode for advanced logs', 'retailcrm'),
'class' => 'checkbox',
'type' => 'checkbox'
);
$this->form_fields['debug_mode'] = [
'label' => __('Enable debug mode in module', 'retailcrm'),
'title' => __('Debug mode', 'retailcrm'),
'description' => __('Is required to enable debug mode for advanced logs', 'retailcrm'),
'class' => 'checkbox',
'type' => 'checkbox'
];
/**
* Debug information
*/
$this->form_fields['debug-info'] = array(
$this->form_fields['debug-info'] = [
'title' => __('Debug information', 'retailcrm'),
'type' => 'heading',
'class' => 'debug_info_options'
);
];
}
} elseif (empty($apiUrl) === false && empty($apiKey) === false) {
$api = new WC_Retailcrm_Proxy(
@ -586,14 +596,14 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration
public function generate_button_html($key, $data)
{
$field = $this->plugin_id . $this->id . '_' . $key;
$defaults = array(
$defaults = [
'class' => 'button-secondary',
'css' => '',
'custom_attributes' => array(),
'custom_attributes' => [],
'desc_tip' => false,
'description' => '',
'title' => '',
);
];
$data = wp_parse_args($data, $defaults);
@ -629,12 +639,8 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration
public function generate_heading_html($key, $data)
{
$field_key = $this->get_field_key($key);
$defaults = array(
'title' => '',
'class' => '',
);
$data = wp_parse_args($data, $defaults);
$defaults = ['title' => '', 'class' => ''];
$data = wp_parse_args($data, $defaults);
ob_start();
?>
@ -680,21 +686,14 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration
*/
public function validate_api_url_field($key, $value)
{
$post = $this->get_post_data();
$api = new WC_Retailcrm_Proxy(
$value,
$post[$this->plugin_id . $this->id . '_api_key'],
$this->get_option('corporate_enabled', 'no') === 'yes'
);
$crmUrl = validateUrl($value);
$response = $api->apiVersions();
if ($response == null) {
WC_Admin_Settings::add_error(esc_html__('Enter the correct URL of CRM', 'retailcrm'));
$value = '';
if (validateUrl($crmUrl) == '') {
WC_Admin_Settings::add_error(esc_html__('Enter the correct URL of Simla.com', 'retailcrm'));
header("Refresh:3");
}
return $value;
return $crmUrl;
}
/**
@ -709,9 +708,15 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration
*/
public function validate_api_key_field($key, $value)
{
$post = $this->get_post_data();
$crmUrl = $_POST['woocommerce_integration-retailcrm_api_url'];
// If entered the wrong URL, don't need to validate the API key.
if (validateUrl($crmUrl) == '') {
return $value;
}
$api = new WC_Retailcrm_Proxy(
$post[$this->plugin_id . $this->id . '_api_url'],
$crmUrl,
$value,
$this->get_option('corporate_enabled', 'no') === 'yes'
);
@ -724,6 +729,8 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration
if (empty($response) || !$response->isSuccessful()) {
WC_Admin_Settings::add_error(esc_html__('Enter the correct API key', 'retailcrm'));
header("Refresh:3");
$value = '';
}
@ -800,30 +807,30 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration
}
$wp_admin_bar->add_menu(
array(
[
'id' => 'retailcrm_top_menu',
'title' => __('Simla.com', 'retailcrm')
)
]
);
$wp_admin_bar->add_menu(
array(
[
'id' => 'retailcrm_ajax_generate_icml',
'title' => __('Generating ICML catalog', 'retailcrm'),
'href' => '#',
'parent' => 'retailcrm_top_menu',
'class' => 'retailcrm_ajax_generate_icml'
)
]
);
$wp_admin_bar->add_menu(
array(
[
'id' => 'retailcrm_ajax_generate_setings',
'title' => __('Settings', 'retailcrm'),
'href' => get_site_url() . '/wp-admin/admin.php?page=wc-settings&tab=integration&section=integration-retailcrm',
'parent' => 'retailcrm_top_menu',
'class' => 'retailcrm_ajax_settings'
)
]
);
}
}

View File

@ -69,41 +69,41 @@ if (!class_exists('WC_Retailcrm_Base')) {
$this->uploader = new WC_Retailcrm_Uploader($this->apiClient, $this->orders, $this->customers);
// Actions.
add_action('woocommerce_update_options_integration_' . $this->id, array($this, 'process_admin_options'));
add_filter('woocommerce_settings_api_sanitized_fields_' . $this->id, array($this, 'api_sanitized'));
add_action('admin_bar_menu', array($this, 'add_retailcrm_button'), 100);
add_action('woocommerce_checkout_order_processed', array($this, 'retailcrm_process_order'), 10, 1);
add_action('retailcrm_history', array($this, 'retailcrm_history_get'));
add_action('retailcrm_icml', array($this, 'generate_icml'));
add_action('retailcrm_inventories', array($this, 'load_stocks'));
add_action('wp_ajax_do_upload', array($this, 'upload_to_crm'));
add_action('wp_ajax_cron_info', array($this, 'get_cron_info'), 99);
add_action('wp_ajax_set_meta_fields', array($this, 'set_meta_fields'), 99);
add_action('wp_ajax_content_upload', array($this, 'count_upload_data'), 99);
add_action('wp_ajax_generate_icml', array($this, 'generate_icml'));
add_action('wp_ajax_upload_selected_orders', array($this, 'upload_selected_orders'));
add_action('admin_print_footer_scripts', array($this, 'ajax_generate_icml'), 99);
add_action('woocommerce_update_customer', array($this, 'update_customer'), 10, 1);
add_action('user_register', array($this, 'create_customer'), 10, 2);
add_action('profile_update', array($this, 'update_customer'), 10, 2);
add_action('wp_print_scripts', array($this, 'initialize_analytics'), 98);
add_action('wp_print_scripts', array($this, 'initialize_daemon_collector'), 99);
add_action('wp_print_scripts', array($this, 'initialize_online_assistant'), 101);
add_action('wp_enqueue_scripts', array($this, 'include_whatsapp_icon_style'), 101);
add_action('wp_print_footer_scripts', array($this, 'initialize_whatsapp'), 101);
add_action('wp_print_footer_scripts', array($this, 'send_analytics'), 99);
add_action('admin_enqueue_scripts', array($this, 'include_files_for_admin'), 101);
add_action('woocommerce_new_order', array($this, 'create_order'), 11, 1);
add_action('woocommerce_update_options_integration_' . $this->id, [$this, 'process_admin_options']);
add_filter('woocommerce_settings_api_sanitized_fields_' . $this->id, [$this, 'api_sanitized']);
add_action('admin_bar_menu', [$this, 'add_retailcrm_button'], 100);
add_action('woocommerce_checkout_order_processed', [$this, 'retailcrm_process_order'], 10, 1);
add_action('retailcrm_history', [$this, 'retailcrm_history_get']);
add_action('retailcrm_icml', [$this, 'generate_icml']);
add_action('retailcrm_inventories', [$this, 'load_stocks']);
add_action('wp_ajax_do_upload', [$this, 'upload_to_crm']);
add_action('wp_ajax_cron_info', [$this, 'get_cron_info'], 99);
add_action('wp_ajax_set_meta_fields', [$this, 'set_meta_fields'], 99);
add_action('wp_ajax_content_upload', [$this, 'count_upload_data'], 99);
add_action('wp_ajax_generate_icml', [$this, 'generate_icml']);
add_action('wp_ajax_upload_selected_orders', [$this, 'upload_selected_orders']);
add_action('admin_print_footer_scripts', [$this, 'ajax_generate_icml'], 99);
add_action('woocommerce_update_customer', [$this, 'update_customer'], 10, 1);
add_action('user_register', [$this, 'create_customer'], 10, 2);
add_action('profile_update', [$this, 'update_customer'], 10, 2);
add_action('wp_print_scripts', [$this, 'initialize_analytics'], 98);
add_action('wp_print_scripts', [$this, 'initialize_daemon_collector'], 99);
add_action('wp_print_scripts', [$this, 'initialize_online_assistant'], 101);
add_action('wp_enqueue_scripts', [$this, 'include_whatsapp_icon_style'], 101);
add_action('wp_print_footer_scripts', [$this, 'initialize_whatsapp'], 101);
add_action('wp_print_footer_scripts', [$this, 'send_analytics'], 99);
add_action('admin_enqueue_scripts', [$this, 'include_files_for_admin'], 101);
add_action('woocommerce_new_order', [$this, 'create_order'], 11, 1);
if (
!$this->get_option('deactivate_update_order')
|| $this->get_option('deactivate_update_order') == static::NO
) {
add_action('woocommerce_update_order', array($this, 'update_order'), 11, 1);
add_action('woocommerce_update_order', [$this, 'update_order'], 11, 1);
}
// Deactivate hook
add_action('retailcrm_deactivate', array($this, 'deactivate'));
add_action('retailcrm_deactivate', [$this, 'deactivate']);
}
/**
@ -115,7 +115,7 @@ if (!class_exists('WC_Retailcrm_Base')) {
$this->init_settings();
}
/**
/**
* @param $settings
*
* @return array
@ -166,6 +166,10 @@ if (!class_exists('WC_Retailcrm_Base')) {
* This solution checks the url specified to the ICML file and updates it if necessary.
*/
if (!$this->apiClient instanceof WC_Retailcrm_Proxy) {
return null;
}
$codeSite = '';
$infoApiKey = $this->apiClient->credentials();
@ -498,19 +502,19 @@ if (!class_exists('WC_Retailcrm_Base')) {
*/
public function count_upload_data()
{
$translate = array(
'tr_order' => __('Orders', 'retailcrm'),
'tr_customer' => __('Customers', 'retailcrm'),
'tr_empty_field' => __('The field cannot be empty, enter the order ID', 'retailcrm'),
'tr_successful' => __('Orders were uploaded', 'retailcrm'),
);
$translate = [
'tr_order' => __('Orders', 'retailcrm'),
'tr_customer' => __('Customers', 'retailcrm'),
'tr_empty_field' => __('The field cannot be empty, enter the order ID', 'retailcrm'),
'tr_successful' => __('Orders were uploaded', 'retailcrm'),
];
echo json_encode(
array(
[
'count_orders' => $this->uploader->getCountOrders(),
'count_users' => $this->uploader->getCountUsers(),
'translate' => $translate,
)
]
);
wp_die();
@ -524,12 +528,12 @@ if (!class_exists('WC_Retailcrm_Base')) {
$icml = $defaultValue;
$history = $defaultValue;
$inventories = $defaultValue;
$translate = array(
$translate = [
'tr_td_cron' => __('Cron launches', 'retailcrm'),
'tr_td_icml' => __('Generation ICML', 'retailcrm'),
'tr_td_history' => __('Syncing history', 'retailcrm'),
'tr_td_inventories' => __('Syncing inventories', 'retailcrm'),
);
];
if (isset($this->settings['history']) && $this->settings['history'] == static::YES) {
$history = date( 'H:i:s d-m-Y', wp_next_scheduled('retailcrm_history'));
@ -544,12 +548,12 @@ if (!class_exists('WC_Retailcrm_Base')) {
}
echo json_encode(
array(
[
'history' => $history,
'icml' => $icml,
'inventories' => $inventories,
'translate' => $translate,
)
]
);
wp_die();
@ -560,23 +564,27 @@ if (!class_exists('WC_Retailcrm_Base')) {
*/
public function set_meta_fields()
{
if (!$this->apiClient instanceof WC_Retailcrm_Proxy) {
return null;
}
$orderMetaData = $this->getMetaData('order');
$customerMetaData = $this->getMetaData('user');
$orderCustomFields = $this->getCustomFields('order');
$customerCustomFields = $this->getCustomFields('customer');
$translate = array(
$translate = [
'tr_lb_order' => __('Custom fields for order', 'retailcrm'),
'tr_lb_customer' => __('Custom fields for customer', 'retailcrm'),
'tr_btn' => __('Add new select for order', 'retailcrm'),
);
];
echo json_encode(
array(
'order' => array('custom' => $orderCustomFields, 'meta' => $orderMetaData),
'customer' => array('custom' => $customerCustomFields, 'meta' => $customerMetaData),
[
'order' => ['custom' => $orderCustomFields, 'meta' => $orderMetaData],
'customer' => ['custom' => $customerCustomFields, 'meta' => $customerMetaData],
'translate' => $translate,
)
]
);
wp_die();
@ -589,8 +597,8 @@ if (!class_exists('WC_Retailcrm_Base')) {
*/
private function getCustomFields($entity)
{
$customFields = array('default_retailcrm' => __('Select value', 'retailcrm'));
$getCustomFields = $this->apiClient->customFieldsList(array('entity' => $entity), 100);
$customFields = ['default_retailcrm' => __('Select value', 'retailcrm')];
$getCustomFields = $this->apiClient->customFieldsList(['entity' => $entity], 100);
if (!empty($getCustomFields['customFields']) && $getCustomFields->isSuccessful()) {
foreach ($getCustomFields['customFields'] as $field) {
@ -614,7 +622,7 @@ if (!class_exists('WC_Retailcrm_Base')) {
$table = $entity === 'order' ? $wpdb->postmeta : $wpdb->usermeta;
$metaData = array('default_retailcrm' => __('Select value', 'retailcrm'));
$metaData = ['default_retailcrm' => __('Select value', 'retailcrm')];
$sqlQuery = "SELECT DISTINCT `meta_key` FROM $table ORDER BY `meta_key`";
$defaultMetaFields = file(
__DIR__ . '/../assets/default/default_meta_fields.txt',

View File

@ -91,6 +91,10 @@ if (!class_exists('WC_Retailcrm_History')) :
*/
protected function customersHistory()
{
if (!$this->retailcrm instanceof WC_Retailcrm_Proxy) {
return null;
}
$sinceId = get_option('retailcrm_customers_history_since_id');
$pagination = 1;
@ -193,6 +197,10 @@ if (!class_exists('WC_Retailcrm_History')) :
*/
protected function ordersHistory()
{
if (!$this->retailcrm instanceof WC_Retailcrm_Proxy) {
return null;
}
$options = array_flip(array_filter($this->retailcrmSettings));
$sinceId = get_option('retailcrm_orders_history_since_id');
$pagination = 1;

View File

@ -136,3 +136,17 @@ function is_wplogin()
|| $_SERVER['PHP_SELF'] == '/wp-login.php'
);
}
/**
* Validate API url.
*
* @param string $url URL of Simla.com.
*
* @return string
*/
function validateUrl(string $url)
{
return (preg_match("/https:\/\/(.*).(retailcrm.(pro|ru|es)|simla.com)/", $url)) ? $url : '';
}

View File

@ -5,7 +5,7 @@ Tags: Интеграция, Simla.com, simla
Requires PHP: 5.6
Requires at least: 5.3
Tested up to: 5.9
Stable tag: 4.4.3
Stable tag: 4.4.4
License: GPLv1 or later
License URI: http://www.gnu.org/licenses/gpl-1.0.html
@ -82,6 +82,14 @@ Asegúrate de tener una clave API específica para cada tienda. Las siguientes i
== Changelog ==
= 4.4.4 =
* Add product description to ICML
* Fix fatal error using API without api_key
* Add priceType processing to CRM order by history
* Add method in API V5 and delete use another version
* Fix error with integration payments
* Fix bug with changing order status by history
= 4.4.3 =
* Fix bug in updating order number by history
* Add multiple image transfer in ICML

View File

@ -5,10 +5,10 @@
* Description: Integration plugin for WooCommerce & Simla.com
* Author: RetailDriver LLC
* Author URI: http://retailcrm.pro/
* Version: 4.4.3
* Version: 4.4.4
* Tested up to: 5.9
* WC requires at least: 5.4
* WC tested up to: 6.2
* WC tested up to: 6.5
* Text Domain: retailcrm
*/

View File

@ -16,7 +16,7 @@
*
* @link https://wordpress.org/plugins/woo-retailcrm/
*
* @version 4.4.3
* @version 4.4.4
*
* @package RetailCRM
*/