From 9ea8818e5b37542711d9d1881332a90da8f42713 Mon Sep 17 00:00:00 2001 From: Uryvskiy Dima Date: Mon, 22 Apr 2024 09:01:59 +0300 Subject: [PATCH] ref #87349 Added automatic catalog generation when changing 'Activate the binding via sku (xml)' (#327) --- CHANGELOG.md | 3 +++ VERSION | 2 +- doc/1.Setup/Generating ICML catalog.md | 4 +++- src/assets/js/retailcrm-module-settings.js | 15 +++++++++++++++ src/include/class-wc-retailcrm-base.php | 16 ++++++++++++++-- src/include/class-wc-retailcrm-icml.php | 19 ++++++++++++++----- src/readme.txt | 5 ++++- src/retailcrm.php | 2 +- src/uninstall.php | 2 +- 9 files changed, 56 insertions(+), 12 deletions(-) create mode 100644 src/assets/js/retailcrm-module-settings.js diff --git a/CHANGELOG.md b/CHANGELOG.md index adb9995..b855efb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2024-04-19 4.7.5 +* Added automatic catalog generation when changing "Activate the binding via sku (xml)" + ## 2024-02-29 4.7.4 * Fixed an error when transferring abandoned carts diff --git a/VERSION b/VERSION index b48b2de..70bc9a9 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.7.4 +4.7.5 diff --git a/doc/1.Setup/Generating ICML catalog.md b/doc/1.Setup/Generating ICML catalog.md index e5dcced..74ace8b 100644 --- a/doc/1.Setup/Generating ICML catalog.md +++ b/doc/1.Setup/Generating ICML catalog.md @@ -23,6 +23,8 @@ После активации опции при генерации каталога в нем появится параметр xmlID *(артикул)*. +С версии 4.7.5 после активации/деактивации опции и сохранении настроек, каталог будет сгенерирован автоматически. + **xmlID** - внешний идентификатор товара, элемент не является обязательным. В случае, если интернет-магазин использует выгрузку номенклатуры товаров из складской системы *(1С, МойСклад)*, то значение этого элемента соответствует идентификатору товара в данной системе. Активируется, когда клиенты используют Woocommerce + MC/1C. ### Недавние обновления: @@ -52,4 +54,4 @@ function changeProductInfo($productData, $wcProduct) return $productData; } -``` \ No newline at end of file +``` diff --git a/src/assets/js/retailcrm-module-settings.js b/src/assets/js/retailcrm-module-settings.js new file mode 100644 index 0000000..4de3649 --- /dev/null +++ b/src/assets/js/retailcrm-module-settings.js @@ -0,0 +1,15 @@ +jQuery(function () { + document.querySelector('#woocommerce_integration-retailcrm_bind_by_sku').onchange = function() { + let useXmlId = this.checked ? 'yes' : 'no'; + + document.querySelector('.submit').onclick = function() { + jQuery.ajax({ + url: AdminUrl.url + '/admin-ajax.php?action=generate_icml', + method: 'POST', + timeout: 0, + data: {useXmlId: useXmlId}, + dataType: 'json' + }) + } + }; +}) diff --git a/src/include/class-wc-retailcrm-base.php b/src/include/class-wc-retailcrm-base.php index 729e8f1..707d1c2 100644 --- a/src/include/class-wc-retailcrm-base.php +++ b/src/include/class-wc-retailcrm-base.php @@ -283,6 +283,12 @@ if (!class_exists('WC_Retailcrm_Base')) { } $retailCrmIcml = new WC_Retailcrm_Icml(); + + // Generate new ICML catalog, because change bind_by_sku + if (isset($_POST['useXmlId'])) { + $retailCrmIcml->changeBindBySku($_POST['useXmlId']); + } + $retailCrmIcml->generate(); $this->uploadCatalog($infoApiKey); @@ -634,8 +640,14 @@ if (!class_exists('WC_Retailcrm_Base')) { */ private function include_js_scripts_for_admin() { - $jsScripts = ['retailcrm-export', 'retailcrm-cron-info','retailcrm-meta-fields']; - $wpAdminUrl = ['url' => get_admin_url()]; + $jsScripts = [ + 'retailcrm-export', + 'retailcrm-cron-info', + 'retailcrm-meta-fields', + 'retailcrm-module-settings', + ]; + + $wpAdminUrl = ['url' => get_admin_url()]; $jsScriptsPath = plugins_url() . '/woo-retailcrm/assets/js/'; foreach ($jsScripts as $scriptName) { diff --git a/src/include/class-wc-retailcrm-icml.php b/src/include/class-wc-retailcrm-icml.php index a48a17e..ee21a86 100644 --- a/src/include/class-wc-retailcrm-icml.php +++ b/src/include/class-wc-retailcrm-icml.php @@ -27,9 +27,13 @@ if (!class_exists('WC_Retailcrm_Icml')) : ]; protected $shop; + protected $file; + protected $tmpFile; + protected $settings; + protected $icmlWriter; /** @@ -45,6 +49,11 @@ if (!class_exists('WC_Retailcrm_Icml')) : $this->icmlWriter = new WC_Retailcrm_Icml_Writer($this->tmpFile); } + public function changeBindBySku($useXmlId) + { + $this->settings['bind_by_sku'] = $useXmlId; + } + /** * Generate ICML catalog. */ @@ -201,21 +210,21 @@ if (!class_exists('WC_Retailcrm_Icml')) : $dimensions = ''; - if ($product->get_length() != '') { + if ($product->get_length() !== '') { $dimensions = wc_get_dimension($product->get_length(), 'cm'); } - if ($product->get_width() != '') { + if ($product->get_width() !== '') { $dimensions .= '/' . wc_get_dimension($product->get_width(), 'cm'); } - if ($product->get_height() != '') { + if ($product->get_height() !== '') { $dimensions .= '/' . wc_get_dimension($product->get_height(), 'cm'); } $weight = ''; - if ($product->get_weight() != '') { + if ($product->get_weight() !== '') { $weight = wc_get_weight($product->get_weight(), 'kg'); } @@ -246,7 +255,7 @@ if (!class_exists('WC_Retailcrm_Icml')) : 'tax' => isset($tax) ? $tax['rate'] : 'none' ]; - if ($product->get_sku() != '') { + if ($product->get_sku() !== '') { $params[] = ['code' => 'article', 'name' => 'Article', 'value' => $product->get_sku()]; if (isset($this->settings['bind_by_sku']) && $this->settings['bind_by_sku'] == WC_Retailcrm_Base::YES) { diff --git a/src/readme.txt b/src/readme.txt index 97a2de8..b061a3b 100644 --- a/src/readme.txt +++ b/src/readme.txt @@ -5,7 +5,7 @@ Tags: Интеграция, Simla.com, simla Requires PHP: 7.0 Requires at least: 5.3 Tested up to: 6.4 -Stable tag: 4.7.4 +Stable tag: 4.7.5 License: GPLv1 or later License URI: http://www.gnu.org/licenses/gpl-1.0.html @@ -82,6 +82,9 @@ Asegúrate de tener una clave API específica para cada tienda. Las siguientes i == Changelog == += 4.7.5 = +* Added automatic catalog generation when changing 'Activate the binding via sku (xml)' + = 4.7.4 = * Fixed an error when transferring abandoned carts diff --git a/src/retailcrm.php b/src/retailcrm.php index c965d97..a41f15a 100644 --- a/src/retailcrm.php +++ b/src/retailcrm.php @@ -5,7 +5,7 @@ * Description: Integration plugin for WooCommerce & Simla.com * Author: RetailDriver LLC * Author URI: http://retailcrm.pro/ - * Version: 4.7.4 + * Version: 4.7.5 * Tested up to: 6.4 * WC requires at least: 5.4 * WC tested up to: 8.5 diff --git a/src/uninstall.php b/src/uninstall.php index f0f9705..c507d05 100644 --- a/src/uninstall.php +++ b/src/uninstall.php @@ -16,7 +16,7 @@ * * @link https://wordpress.org/plugins/woo-retailcrm/ * - * @version 4.7.4 + * @version 4.7.5 * * @package RetailCRM */