diff --git a/.gitignore b/.gitignore index 6a4befe..5b40963 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /nbproject/ /vendor/ +.idea/ diff --git a/CHANGELOG.md b/CHANGELOG.md index 1564cee..6e9c272 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +## 2019-04-16 3.5.1 +* Исправлен баг при активации плагина + +## 2019-03-06 3.5.0 +* Добавлена настройка деактивации выгрузки изменений заказа в retailCRM +* Добавлена настройка активации выгрузки SKU в xmlId и связь товаров по полю xmlId +* Добавлена настройка передачи номера заказа в retailCRM + ## 2019-03-06 3.4.5 * Исправлен баг с добавлением скидки при уменьшении количества товара * Перенесена инициализация формы настроек после инициализации всех плагинов diff --git a/Makefile b/Makefile index 60c1309..59a6dd0 100644 --- a/Makefile +++ b/Makefile @@ -1,22 +1,22 @@ FILE = $(TRAVIS_BUILD_DIR)/VERSION VERSION = `cat $(FILE)` -all: svn_clone prepare svn_commit remove_dir +all: svn_clone svn_push remove_dir svn_clone: mkdir /tmp/svn_plugin_dir svn co $(SVNREPOURL) /tmp/svn_plugin_dir --username $(USERNAME) --password $(PASSWORD) --no-auth-cache -prepare: /tmp/svn_plugin_dir - svn delete /tmp/svn_plugin_dir/trunk/* - rm -rf /tmp/svn_plugin_dir/trunk/* - cp -R $(TRAVIS_BUILD_DIR)/src/* /tmp/svn_plugin_dir/trunk - svn copy /tmp/svn_plugin_dir/trunk /tmp/svn_plugin_dir/tags/$(VERSION) --username $(USERNAME) --password $(PASSWORD) --no-auth-cache - -svn_commit: /tmp/svn_plugin_dir/tags - svn add /tmp/svn_plugin_dir/trunk/* --force - svn add /tmp/svn_plugin_dir/tags/$(VERSION)/* --force - svn ci /tmp/svn_plugin_dir -m $(VERSION) --username $(USERNAME) --password $(PASSWORD) --no-auth-cache +svn_push: /tmp/svn_plugin_dir + if [ ! -d "/tmp/svn_plugin_dir/tags/$(VERSION)" ]; then \ + svn delete /tmp/svn_plugin_dir/trunk/*; \ + rm -rf /tmp/svn_plugin_dir/trunk/*; \ + cp -R $(TRAVIS_BUILD_DIR)/src/* /tmp/svn_plugin_dir/trunk; \ + svn copy /tmp/svn_plugin_dir/trunk /tmp/svn_plugin_dir/tags/$(VERSION) --username $(USERNAME) --password $(PASSWORD) --no-auth-cache; \ + svn add /tmp/svn_plugin_dir/trunk/* --force; \ + svn add /tmp/svn_plugin_dir/tags/$(VERSION)/* --force; \ + svn ci /tmp/svn_plugin_dir -m $(VERSION) --username $(USERNAME) --password $(PASSWORD) --no-auth-cache; \ + fi remove_dir: rm -rf /tmp/svn_plugin_dir diff --git a/VERSION b/VERSION index 4f5e697..d5c0c99 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.4.5 +3.5.1 diff --git a/resources/pot/retailcrm-es_ES.pot b/resources/pot/retailcrm-es_ES.pot index c99cb16..d8b64b9 100644 --- a/resources/pot/retailcrm-es_ES.pot +++ b/resources/pot/retailcrm-es_ES.pot @@ -200,4 +200,22 @@ msgid "Enable this setting for activate Daemon Collector on site" msgstr "Active esta configuración para activar Daemon Collector en la página web" msgid "Site key" -msgstr "Clave de la página web" \ No newline at end of file +msgstr "Clave de la página web" + +msgid "Enable data editing in retailCRM" +msgstr "Activar edición de datos en retailCRM" + +msgid "Data updating in retailCRM" +msgstr "Actualización de datos en retailCRM" + +msgid "Activate the binding via sku (xml)" +msgstr "Activar conexión por sku (xmlId)" + +msgid "Stock synchronization and link between products" +msgstr "Sincronización de stock y conexión de productos" + +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 diff --git a/resources/pot/retailcrm-ru_RU.pot b/resources/pot/retailcrm-ru_RU.pot index 3690109..5da055c 100644 --- a/resources/pot/retailcrm-ru_RU.pot +++ b/resources/pot/retailcrm-ru_RU.pot @@ -209,4 +209,22 @@ msgid "Enable this setting for activate Daemon Collector on site" msgstr "Активируйте эту настройку для активации Daemon Collector на сайте" msgid "Site key" -msgstr "Ключ сайта" \ No newline at end of file +msgstr "Ключ сайта" + +msgid "Enable data editing in retailCRM" +msgstr "Активировать редактирование данных в retailCRM" + +msgid "Data updating in retailCRM" +msgstr "Обновление данных в retailCRM" + +msgid "Activate the binding via sku (xml)" +msgstr "Активировать связь по sku(xmlId)" + +msgid "Stock synchronization and link between products" +msgstr "Синхронизация остатков и связь товаров" + +msgid "Enable transferring the number to retailCRM" +msgstr "Активировать передачу номера в retailCRM" + +msgid "Transferring the order number" +msgstr "Передача номера заказа" \ No newline at end of file diff --git a/src/include/abstracts/class-wc-retailcrm-abstracts-address.php b/src/include/abstracts/class-wc-retailcrm-abstracts-address.php new file mode 100644 index 0000000..b27cdc8 --- /dev/null +++ b/src/include/abstracts/class-wc-retailcrm-abstracts-address.php @@ -0,0 +1,30 @@ + + * @license http://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see http://help.retailcrm.ru + */ + +abstract class WC_Retailcrm_Abstracts_Address extends WC_Retailcrm_Abstracts_Data +{ + protected $data = array( + 'index' => '', + 'city' => '', + 'region' => '', + 'text' => '', + ); + + public function reset_data() + { + $this->data = array( + 'index' => '', + 'city' => '', + 'region' => '', + 'text' => '', + ); + } +} diff --git a/src/include/abstracts/class-wc-retailcrm-abstracts-data.php b/src/include/abstracts/class-wc-retailcrm-abstracts-data.php new file mode 100644 index 0000000..20ad0b3 --- /dev/null +++ b/src/include/abstracts/class-wc-retailcrm-abstracts-data.php @@ -0,0 +1,63 @@ + + * @license http://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see http://help.retailcrm.ru + */ + +/** + * Class WC_Retailcrm_Abstracts_Data + */ +abstract class WC_Retailcrm_Abstracts_Data +{ + /** @var string */ + protected $filter_name; + + /** @var array */ + protected $data = array(); + + /** + * @return void + */ + abstract public function reset_data(); + + /** + * @param $data + * + * @return self + */ + abstract public function build($data); + + protected function set_data_field($field, $value) + { + if (isset($this->data[$field]) && \gettype($value) !== \gettype($this->data[$field])) { + return false; + } + + $this->data[$field] = $value; + + return true; + } + + /** + * @param $fields + */ + protected function set_data_fields($fields) + { + foreach ($fields as $field => $value) { + $this->set_data_field($field, $value); + } + } + + /** + * @return array + */ + public function get_data() + { + return apply_filters('retailcrm_before_send_' . $this->filter_name, $this->data); + } +} diff --git a/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php b/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php new file mode 100644 index 0000000..9737e0a --- /dev/null +++ b/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php @@ -0,0 +1,705 @@ + + * @license http://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see http://help.retailcrm.ru + */ + +abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration +{ + /** @var string */ + const YES = 'yes'; + + /** @var string */ + const NO = 'no'; + + /** @var string */ + public static $option_key; + + /** + * WC_Retailcrm_Abstracts_Settings constructor. + */ + public function __construct() { + $this->id = 'integration-retailcrm'; + $this->method_title = __('retailCRM', 'retailcrm'); + $this->method_description = __('Integration with retailCRM management system.', 'retailcrm'); + + static::$option_key = $this->get_option_key(); + + if (isset($_GET['page']) && $_GET['page'] == 'wc-settings' + && isset($_GET['tab']) && $_GET['tab'] == 'integration' + ) { + add_action('init', array($this, 'init_settings_fields'), 99); + } + } + + public function ajax_upload() + { + $ajax_url = admin_url('admin-ajax.php'); + ?> + + + + plugin_id . $this->id . '_single_order'; + ?> + + form_fields = array( + array( 'title' => __( 'Main settings', 'retailcrm' ), 'type' => 'title', 'desc' => '', 'id' => 'general_options' ), + + 'api_url' => array( + 'title' => __( 'API of URL', 'retailcrm' ), + 'type' => 'text', + 'description' => __( 'Enter API of URL (https://yourdomain.retailcrm.pro).', 'retailcrm' ), + 'desc_tip' => true, + 'default' => '' + ), + 'api_key' => array( + 'title' => __( 'API key', 'retailcrm' ), + 'type' => 'text', + 'description' => __( 'Enter your API key. You can find it in the administration section of retailCRM', 'retailcrm' ), + 'desc_tip' => true, + 'default' => '' + ) + ); + + $api_version_list = array( + 'v4' => 'v4', + 'v5' => 'v5' + ); + + $this->form_fields[] = array( + 'title' => __( 'API settings', 'retailcrm' ), + 'type' => 'title', + 'description' => '', + 'id' => 'api_options' + ); + + $this->form_fields['api_version'] = array( + 'title' => __( 'API version', 'retailcrm' ), + 'description' => __( 'Select API version', 'retailcrm' ), + 'css' => 'min-width:50px;', + 'class' => 'select', + 'type' => 'select', + 'options' => $api_version_list, + 'desc_tip' => true, + ); + + $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, + ); + } + + if ($this->apiClient) { + if (isset($_GET['page']) && $_GET['page'] == 'wc-settings' + && isset($_GET['tab']) && $_GET['tab'] == 'integration' + ) { + add_action('admin_print_footer_scripts', array($this, 'show_blocks'), 99); + + /** + * Order methods options + */ + $order_methods_option = array(); + $order_methods_list = $this->apiClient->orderMethodsList(); + + if ($order_methods_list->isSuccessful()) { + foreach ($order_methods_list['orderMethods'] as $order_method) { + if ($order_method['active'] == false) { + continue; + } + + $order_methods_option[$order_method['code']] = $order_method['name']; + } + + $this->form_fields[] = array( + 'title' => __('Order methods', 'retailcrm'), + 'type' => 'heading', + 'description' => '', + 'id' => 'order_methods_options' + ); + + $this->form_fields['order_methods'] = array( + 'label' => ' ', + 'title' => __('Order methods available for uploading from retailCRM', 'retailcrm'), + 'class' => '', + 'type' => 'multiselect', + 'description' => __('Select order methods which will be uploaded from retailCRM to the website', 'retailcrm'), + 'options' => $order_methods_option, + 'css' => 'min-height:100px;', + 'select_buttons' => true + ); + } + + /** + * Shipping options + */ + $shipping_option_list = array(); + $retailcrm_shipping_list = $this->apiClient->deliveryTypesList(); + + if ($retailcrm_shipping_list->isSuccessful()) { + foreach ($retailcrm_shipping_list['deliveryTypes'] as $retailcrm_shipping_type) { + $shipping_option_list[$retailcrm_shipping_type['code']] = $retailcrm_shipping_type['name']; + } + + $wc_shipping_list = get_wc_shipping_methods(); + + $this->form_fields[] = array( + 'title' => __('Delivery types', 'retailcrm'), + 'type' => 'heading', + 'description' => '', + 'id' => 'shipping_options' + ); + + foreach ($wc_shipping_list as $shipping_code => $shipping) { + if (isset($shipping['enabled']) && $shipping['enabled'] == static::YES) { + $this->form_fields[$shipping_code] = array( + 'title' => __($shipping['title'], 'woocommerce'), + 'description' => __($shipping['description'], 'woocommerce'), + 'css' => 'min-width:350px;', + 'class' => 'select', + 'type' => 'select', + 'options' => $shipping_option_list, + 'desc_tip' => true, + ); + } + } + } + + /** + * Payment options + */ + $payment_option_list = array(); + $retailcrm_payment_list = $this->apiClient->paymentTypesList(); + + if ($retailcrm_payment_list->isSuccessful()) { + foreach ($retailcrm_payment_list['paymentTypes'] as $retailcrm_payment_type) { + $payment_option_list[$retailcrm_payment_type['code']] = $retailcrm_payment_type['name']; + } + + $wc_payment = WC_Payment_Gateways::instance(); + + $this->form_fields[] = array( + 'title' => __('Payment types', 'retailcrm'), + 'type' => 'heading', + 'description' => '', + 'id' => 'payment_options' + ); + + foreach ($wc_payment->payment_gateways() as $payment) { + $this->form_fields[$payment->id] = array( + 'title' => __($payment->method_title, 'woocommerce'), + 'description' => __($payment->method_description, 'woocommerce'), + 'css' => 'min-width:350px;', + 'class' => 'select', + 'type' => 'select', + 'options' => $payment_option_list, + 'desc_tip' => true, + ); + } + } + + /** + * Statuses options + */ + $statuses_option_list = array(); + $retailcrm_statuses_list = $this->apiClient->statusesList(); + + if ($retailcrm_statuses_list->isSuccessful()) { + foreach ($retailcrm_statuses_list['statuses'] as $retailcrm_status) { + $statuses_option_list[$retailcrm_status['code']] = $retailcrm_status['name']; + } + + $wc_statuses = wc_get_order_statuses(); + + $this->form_fields[] = array( + 'title' => __('Statuses', 'retailcrm'), + 'type' => 'heading', + 'description' => '', + 'id' => 'statuses_options' + ); + + foreach ($wc_statuses as $idx => $name) { + $uid = str_replace('wc-', '', $idx); + $this->form_fields[$uid] = array( + 'title' => __($name, 'woocommerce'), + 'css' => 'min-width:350px;', + 'class' => 'select', + 'type' => 'select', + 'options' => $statuses_option_list, + 'desc_tip' => true, + ); + } + } + + /** + * Inventories options + */ + $this->form_fields[] = array( + 'title' => __('Setting of the stock balance', 'retailcrm'), + 'type' => 'heading', + 'description' => '', + 'id' => 'invent_options' + ); + + $this->form_fields['sync'] = array( + '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 retailCRM to the website.', 'retailcrm') + ); + + /** + * UA options + */ + $this->form_fields[] = array( + 'title' => __('UA settings', 'retailcrm'), + 'type' => 'heading', + 'description' => '', + 'id' => 'ua_options' + ); + + $this->form_fields['ua'] = array( + '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( + 'title' => __('UA tracking code', 'retailcrm'), + 'class' => 'input', + 'type' => 'input' + ); + + $this->form_fields['ua_custom'] = array( + 'title' => __('User parameter', 'retailcrm'), + 'class' => 'input', + 'type' => 'input' + ); + + /** + * Daemon collector settings + */ + $this->form_fields[] = array( + 'title' => __('Daemon Collector settings', 'retailcrm'), + 'type' => 'heading', + 'description' => '', + 'id' => 'invent_options' + ); + + $this->form_fields['daemon_collector'] = array( + '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( + 'title' => __('Site key', 'retailcrm'), + 'class' => 'input', + 'type' => 'input' + ); + + /** + * Uploads options + */ + $options = array_filter(get_option(static::$option_key)); + + if (!isset($options['uploads'])) { + $this->form_fields[] = array( + 'title' => __('Settings of uploading', 'retailcrm'), + 'type' => 'heading', + 'description' => '', + 'id' => 'upload_options' + ); + + $this->form_fields['upload-button'] = array( + 'label' => __('Upload', 'retailcrm'), + 'title' => __('Uploading all customers and orders', 'retailcrm' ), + 'type' => 'button', + 'description' => __('Uploading the existing customers and orders to retailCRM', 'retailcrm' ), + 'desc_tip' => true, + 'id' => 'uploads-retailcrm' + ); + } + + /* + * Generate icml file + */ + $this->form_fields[] = array( + 'title' => __('Generating ICML catalog', 'retailcrm'), + 'type' => 'title', + 'description' => '', + 'id' => 'icml_options' + ); + + $this->form_fields[] = array( + 'label' => __('Generate now', 'retailcrm'), + 'title' => __('Generating ICML', 'retailcrm'), + 'type' => 'button', + 'description' => __('This functionality allows to generate ICML products catalog for uploading to retailCRM.', 'retailcrm'), + 'desc_tip' => true, + 'id' => 'icml-retailcrm' + ); + + $this->form_fields['icml'] = array( + 'label' => __('Generating ICML', 'retailcrm'), + 'title' => __('Generating ICML catalog by wp-cron', 'retailcrm'), + 'class' => 'checkbox', + 'type' => 'checkbox' + ); + + /* + * Upload single order + */ + $this->form_field[] = array( + 'title' => __('Upload the order by ID', 'retailcrm'), + 'type' => 'title', + 'description' => '', + 'id' => 'order_options' + ); + + $this->form_fields['single_order'] = array( + 'label' => __('Order identifier', 'retailcrm'), + 'title' => __('Orders identifiers', 'retailcrm'), + 'type' => 'input', + 'description' => __('Enter orders identifiers separated by a comma.', 'retailcrm'), + 'desc_tip' => true + ); + + $this->form_fields[] = array( + 'label' => __('Upload', 'retailcrm'), + 'title' => __('Uploading orders by identifiers.', 'retailcrm'), + 'type' => 'button', + 'description' => __('This functionality allows to upload orders to CRM differentially.', 'retailcrm'), + 'desc_tip' => true, + 'id' => 'single_order_btn' + ); + + $this->form_fields['history'] = array( + 'label' => __('Activate history uploads', 'retailcrm'), + 'title' => __('Upload data from retailCRM', 'retailcrm'), + 'class' => 'checkbox', + 'type' => 'checkbox' + ); + + $this->form_fields['deactivate_update_order'] = array( + 'label' => __('Enable data editing in retailCRM', 'retailcrm'), + 'title' => __('Data updating in retailCRM', '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['update_number'] = array( + 'label' => __('Enable transferring the number to retailCRM', 'retailcrm'), + 'title' => __('Transferring the order number', 'retailcrm'), + 'class' => 'checkbox', + 'type' => 'checkbox' + ); + } + } + } + + /** + * Generate html button + * + * @param string $key + * @param array $data + * + * @return string + */ + public function generate_button_html($key, $data) + { + $field = $this->plugin_id . $this->id . '_' . $key; + $defaults = array( + 'class' => 'button-secondary', + 'css' => '', + 'custom_attributes' => array(), + 'desc_tip' => false, + 'description' => '', + 'title' => '', + ); + + $data = wp_parse_args( $data, $defaults ); + + ob_start(); + ?> +