From 799b2f048d8ef0bdabbaaa08cf71c05747b3d088 Mon Sep 17 00:00:00 2001
From: Oleg <109225168+frescoref@users.noreply.github.com>
Date: Thu, 2 Mar 2023 19:03:07 +0300
Subject: [PATCH 01/17] Fix: more
---
Admin.php | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/Admin.php b/Admin.php
index 7d6ff9f..a84f04c 100644
--- a/Admin.php
+++ b/Admin.php
@@ -869,7 +869,7 @@ public function configurationsFieldsProductsSku(array $fields): array
[
'title' => __('Products (goods): SKU', 'wc1c-main'),
'type' => 'title',
- 'description' => __('Sources and algorithms for filling out product SKU.', 'wc1c-main'),
+ 'description' => __('Sources and algorithms for filling out products SKU.', 'wc1c-main'),
];
$fields['products_create_adding_sku'] =
@@ -896,7 +896,7 @@ public function configurationsFieldsProductsSku(array $fields): array
$fields['products_update_sku'] =
[
- 'title' => __('Product SKU update when requesting product updates', 'wc1c-main'),
+ 'title' => __('Product SKU update when products updates', 'wc1c-main'),
'default' => 'no',
'type' => 'select',
'description' => sprintf
@@ -926,7 +926,7 @@ public function configurationsFieldsProductsSku(array $fields): array
$fields['products_sku_by_cml'] =
[
- 'title' => __('SKU based on CommerceML data', 'wc1c-main'),
+ 'title' => __('Source for SKUs', 'wc1c-main'),
'type' => 'select',
'description' => sprintf
(
@@ -949,9 +949,9 @@ public function configurationsFieldsProductsSku(array $fields): array
$fields['products_sku_from_requisites_name'] =
[
- 'title' => __('SKU based on CommerceML data: name for requisite', 'wc1c-main'),
+ 'title' => __('Source for SKUs: name for requisite', 'wc1c-main'),
'type' => 'text',
- 'description' => __('The name of the requisite of the product (goods) which contains a SKU of the product.', 'wc1c-main'),
+ 'description' => __('The name of the requisite of the products (goods) which contains a SKU of the product.', 'wc1c-main'),
'default' => '',
'css' => 'min-width: 370px;',
];
From 71a0ad3ed50ade4d519b8c82ef077efc28b62df4 Mon Sep 17 00:00:00 2001
From: Oleg <109225168+frescoref@users.noreply.github.com>
Date: Thu, 2 Mar 2023 20:44:53 +0300
Subject: [PATCH 02/17] Fix: more
---
Admin.php | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/Admin.php b/Admin.php
index a84f04c..437187a 100644
--- a/Admin.php
+++ b/Admin.php
@@ -972,15 +972,15 @@ public function configurationsFieldsProductsNames(array $fields): array
[
'title' => __('Products (goods): names', 'wc1c-main'),
'type' => 'title',
- 'description' => __('Sources and algorithms for filling out product names.', 'wc1c-main'),
+ 'description' => __('Sources and algorithms for filling out products name.', 'wc1c-main'),
];
$fields['products_update_name'] =
[
- 'title' => __('Product name update when requesting product updates', 'wc1c-main'),
+ 'title' => __('Product name update when update products', 'wc1c-main'),
'type' => 'checkbox',
'label' => __('Check the box if you want to enable this feature. Disabled by default.', 'wc1c-main'),
- 'description' => __('When changing the product name in 1C, the data will be changed on the site.', 'wc1c-main'),
+ 'description' => __('When changing the products names in 1C, the data will be changed on the site.', 'wc1c-main'),
'default' => 'no'
];
@@ -994,7 +994,7 @@ public function configurationsFieldsProductsNames(array $fields): array
$fields['products_names_by_cml'] =
[
- 'title' => __('Names based on CommerceML data', 'wc1c-main'),
+ 'title' => __('Source for product names', 'wc1c-main'),
'type' => 'select',
'description' => sprintf
(
@@ -1015,9 +1015,9 @@ public function configurationsFieldsProductsNames(array $fields): array
$fields['products_names_from_requisites_name'] =
[
- 'title' => __('Names based on CommerceML data: name for requisite', 'wc1c-main'),
+ 'title' => __('Source for product names: name for requisite', 'wc1c-main'),
'type' => 'text',
- 'description' => __('The name of the requisite of the product (goods) which contains a name of the product.', 'wc1c-main'),
+ 'description' => __('The name of the requisite of the products (goods) which contains a name of the product.', 'wc1c-main'),
'default' => '',
'css' => 'min-width: 370px;',
];
@@ -1043,7 +1043,7 @@ public function configurationsFieldsProductsDescriptions(array $fields): array
$fields['products_create_adding_description'] =
[
- 'title' => __('Filling the description of the created product', 'wc1c-main'),
+ 'title' => __('Filling the description of the created products', 'wc1c-main'),
'type' => 'checkbox',
'label' => __('Check the box to enable this feature. Disabled by default.', 'wc1c-main'),
'description' => sprintf
@@ -1066,7 +1066,7 @@ public function configurationsFieldsProductsDescriptions(array $fields): array
$fields['products_update_description'] =
[
- 'title' => __('Description update when requesting product updates', 'wc1c-main'),
+ 'title' => __('Description update when update products', 'wc1c-main'),
'default' => 'no',
'type' => 'select',
'description' => sprintf
@@ -1096,7 +1096,7 @@ public function configurationsFieldsProductsDescriptions(array $fields): array
$fields['products_descriptions_short_by_cml'] =
[
- 'title' => __('Descriptions based on CommerceML data: short', 'wc1c-main'),
+ 'title' => __('Source for descriptions', 'wc1c-main'),
'type' => 'select',
'description' => sprintf
(
@@ -1119,7 +1119,7 @@ public function configurationsFieldsProductsDescriptions(array $fields): array
$fields['products_descriptions_short_from_requisites_name'] =
[
- 'title' => __('Descriptions based on CommerceML data: short - name for requisite', 'wc1c-main'),
+ 'title' => __('Source for descriptions: name for requisite', 'wc1c-main'),
'type' => 'text',
'description' => __('The name of the requisite of the product (goods) which contains a short description of the product.', 'wc1c-main'),
'default' => '',
@@ -1128,7 +1128,7 @@ public function configurationsFieldsProductsDescriptions(array $fields): array
$fields['products_create_adding_description_full'] =
[
- 'title' => __('Filling a full description of the created product', 'wc1c-main'),
+ 'title' => __('Filling a full description of the created products', 'wc1c-main'),
'type' => 'checkbox',
'label' => __('Check the box to enable this feature. Disabled by default.', 'wc1c-main'),
'description' => sprintf
@@ -1143,7 +1143,7 @@ public function configurationsFieldsProductsDescriptions(array $fields): array
$fields['products_update_description_full'] =
[
- 'title' => __('Full description update when requesting product updates', 'wc1c-main'),
+ 'title' => __('Full description update when update products', 'wc1c-main'),
'default' => 'no',
'type' => 'select',
'description' => sprintf
@@ -1164,7 +1164,7 @@ public function configurationsFieldsProductsDescriptions(array $fields): array
$fields['products_descriptions_by_cml'] =
[
- 'title' => __('Descriptions based on CommerceML data: full', 'wc1c-main'),
+ 'title' => __('Source for full descriptions', 'wc1c-main'),
'type' => 'select',
'description' => sprintf
(
@@ -1187,7 +1187,7 @@ public function configurationsFieldsProductsDescriptions(array $fields): array
$fields['products_descriptions_from_requisites_name'] =
[
- 'title' => __('Descriptions based on CommerceML data: full - name for requisite', 'wc1c-main'),
+ 'title' => __('Source for full descriptions: name for requisite', 'wc1c-main'),
'type' => 'text',
'description' => __('The name of the requisite of the product (goods) which contains a full description of the product.', 'wc1c-main'),
'default' => '',
From 4e4e2898e16102f2618491cc520cc8404e04cd54 Mon Sep 17 00:00:00 2001
From: Oleg <109225168+frescoref@users.noreply.github.com>
Date: Thu, 2 Mar 2023 21:45:01 +0300
Subject: [PATCH 03/17] Fix: more
---
Admin.php | 41 ++++++++++++++++++++++++++++-------------
1 file changed, 28 insertions(+), 13 deletions(-)
diff --git a/Admin.php b/Admin.php
index 437187a..1e7d3f4 100644
--- a/Admin.php
+++ b/Admin.php
@@ -1358,7 +1358,7 @@ public function configurationsFieldsProductsImages(array $fields): array
$fields['products_create_adding_images'] =
[
- 'title' => __('Adding the images of the created product', 'wc1c-main'),
+ 'title' => __('Adding the images of the created products', 'wc1c-main'),
'type' => 'checkbox',
'label' => __('Check the box to enable this feature. Enabled by default.', 'wc1c-main'),
'description' => sprintf
@@ -1369,38 +1369,53 @@ public function configurationsFieldsProductsImages(array $fields): array
'default' => 'yes'
];
+ $products_update_images_options =
+ [
+ 'no' => __('Do not update', 'wc1c-main'),
+ 'yes' => __('Update in any case', 'wc1c-main'),
+ 'add' => __('Add if not on the site, but available in 1C', 'wc1c-main'),
+ 'yes_yes' => __('Update if present on the site and in 1C', 'wc1c-main'),
+ ];
+
$fields['products_update_images'] =
[
- 'title' => __('Product images update when requesting product updates', 'wc1c-main'),
- 'type' => 'checkbox',
- 'label' => __('Check the box if you want to enable this feature. Disabled by default.', 'wc1c-main'),
+ 'title' => __('Update images when update products', 'wc1c-main'),
+ 'default' => 'no',
+ 'type' => 'select',
'description' => sprintf
(
- '%s
%s',
- __('If the setting is disabled, new images will not be assigned to old products and the old ones will not be deleted either. In this case, you can edit images from WooCommerce.', 'wc1c-main'),
- __('The choice of a source for a brief images from 1C is in a separate settings block - Products (goods): images.', 'wc1c-main')
+ '%s - %s
%s - %s
%s - %s
%s - %s
%s',
+ __('Do not update', 'wc1c-main'),
+ __('Update images will be skipped in any case.', 'wc1c-main'),
+ __('Update in any case', 'wc1c-main'),
+ __('Images will be updated in any case. The same value will always be on the site and in 1C.', 'wc1c-main'),
+ __('Add if not on the site, but available in 1C', 'wc1c-main'),
+ __('Existing images will not be affected. There will be a filling of those missing on the site if they are available in 1C.', 'wc1c-main'),
+ __('Update if present on the site and in 1C', 'wc1c-main'),
+ __('Images will be updated only if they are filled in 1C and on the site at the same time.', 'wc1c-main'),
+ __('The setting works when updating products (goods).', 'wc1c-main')
),
- 'default' => 'no'
+ 'options' => $products_update_images_options
];
$fields['products_images_by_cml'] =
[
- 'title' => __('Images based on CommerceML files', 'wc1c-main'),
+ 'title' => __('Images based on CommerceML data', 'wc1c-main'),
'type' => 'checkbox',
- 'label' => __('Check the box to enable this feature. Disabled by default.', 'wc1c-main'),
+ 'label' => __('Check the box to enable this feature. Enabled by default.', 'wc1c-main'),
'description' => sprintf
(
'%s
%s %s',
__('When enabled, work with images based on CommerceML files will be allowed.', 'wc1c-main'),
- __('Available images in CommerceML files for products will be populated for future use.', 'wc1c-main'),
+ __('Available images in CommerceML data for products will be populated for future use.', 'wc1c-main'),
__('In this case, the image files themselves must first be added to the WordPress media library. If they are not included, their use will be skipped.', 'wc1c-main')
),
- 'default' => 'no'
+ 'default' => 'yes'
];
$fields['products_images_by_cml_max'] =
[
- 'title' => __('Images based on CommerceML files: maximum quantity', 'wc1c-main'),
+ 'title' => __('Images based on CommerceML data: maximum quantity', 'wc1c-main'),
'type' => 'text',
'description' => sprintf
(
From d12466b870eb99d2aa2636a5cecce3a67d678010 Mon Sep 17 00:00:00 2001
From: Oleg <109225168+frescoref@users.noreply.github.com>
Date: Thu, 2 Mar 2023 23:47:15 +0300
Subject: [PATCH 04/17] Fix: more
---
Admin.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Admin.php b/Admin.php
index 1e7d3f4..8f33888 100644
--- a/Admin.php
+++ b/Admin.php
@@ -896,7 +896,7 @@ public function configurationsFieldsProductsSku(array $fields): array
$fields['products_update_sku'] =
[
- 'title' => __('Product SKU update when products updates', 'wc1c-main'),
+ 'title' => __('SKU update when products updates', 'wc1c-main'),
'default' => 'no',
'type' => 'select',
'description' => sprintf
From 8422f6e85d6a546057b473bd14048ec4c5140b74 Mon Sep 17 00:00:00 2001
From: Oleg <109225168+frescoref@users.noreply.github.com>
Date: Fri, 3 Mar 2023 00:45:04 +0300
Subject: [PATCH 05/17] Fix: more
---
Admin.php | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 64 insertions(+), 4 deletions(-)
diff --git a/Admin.php b/Admin.php
index 8f33888..a9a450d 100644
--- a/Admin.php
+++ b/Admin.php
@@ -1702,15 +1702,75 @@ public function configurationsFieldsProductsDimensions(array $fields): array
'description' => __('The main settings for filling in the dimensions of products (goods) according to data from 1C. Dimensions include: weight, length, width, height.', 'wc1c-main'),
];
- $fields['products_dimensions_by_requisites'] =
+ $fields['products_create_adding_dimensions'] =
[
- 'title' => __('Filling dimensions based on requisites', 'wc1c-main'),
+ 'title' => __('Filling the dimensions of the created product', 'wc1c-main'),
'type' => 'checkbox',
- 'label' => __('Check the box to enable this feature. Disabled by default.', 'wc1c-main'),
- 'description' => __('Filling in the dimensions will be performed from the given details of the products. For the setting to work, you must specify the correspondence of the details in the fields below.', 'wc1c-main'),
+ 'label' => __('Check the box to enable this feature. Enabled by default.', 'wc1c-main'),
+ 'description' => sprintf
+ (
+ '%s
%s',
+ __('The product dimensions will be added according to data from 1C. It is recommended to enable this feature.', 'wc1c-main'),
+ __('The setting works when creating products (goods).', 'wc1c-main')
+ ),
'default' => 'yes'
];
+ $products_update_dimensions_options =
+ [
+ 'no' => __('Do not update', 'wc1c-main'),
+ 'yes' => __('Update in any case', 'wc1c-main'),
+ 'add' => __('Add if not on the site and available in 1C', 'wc1c-main'),
+ 'yes_yes' => __('Update if present on the site and in 1C', 'wc1c-main'),
+ ];
+
+ $fields['products_update_dimensions'] =
+ [
+ 'title' => __('Dimensions update when products updates', 'wc1c-main'),
+ 'default' => 'no',
+ 'type' => 'select',
+ 'description' => sprintf
+ (
+ '%s - %s
%s - %s
%s - %s
%s - %s
%s',
+ __('Do not update', 'wc1c-main'),
+ __('Dimensions updates will be skipped in any case.', 'wc1c-main'),
+ __('Update in any case', 'wc1c-main'),
+ __('Dimensions will be updated in any case. The same value will always be on the site and in 1C.', 'wc1c-main'),
+ __('Add if not on the site, but available in 1C', 'wc1c-main'),
+ __('Existing dimensions will not be affected. There will be a filling of those missing on the site if they are available in 1C.', 'wc1c-main'),
+ __('Update if present on the site and in 1C', 'wc1c-main'),
+ __('Dimensions will be updated only if they are filled in 1C and on the site at the same time.', 'wc1c-main'),
+ __('The setting works when updating products (goods).', 'wc1c-main')
+ ),
+ 'options' => $products_update_dimensions_options
+ ];
+
+ $products_dimensions_source_options =
+ [
+ 'no' => __('Do not use', 'wc1c-main'),
+ 'yes' => __('From the standard fields', 'wc1c-main'),
+ 'yes_requisites' => __('From requisite with the specified name', 'wc1c-main'),
+ ];
+
+ $fields['products_dimensions_source'] =
+ [
+ 'title' => __('Source for dimensions', 'wc1c-main'),
+ 'type' => 'select',
+ 'description' => sprintf
+ (
+ '%s
%s - %s
%s - %s
%s - %s',
+ __('The setting works when creating and updating products (goods).', 'wc1c-main'),
+ __('Do not use', 'wc1c-main'),
+ __('Populating the dimensions data from CommerceML data will be skipped. If a product is updating, then its current dimensions will not be updated.', 'wc1c-main'),
+ __('From the standard fields', 'wc1c-main'),
+ __('This dimensions is contained in the standard fields of 1C products. It is located in the conditional tags.', 'wc1c-main'),
+ __('From requisite with the specified name', 'wc1c-main'),
+ __('The dimensions data will be filled in based on the completed name of the requisite of the products (goods).', 'wc1c-main')
+ ),
+ 'default' => 'yes_requisites',
+ 'options' => $products_dimensions_source_options
+ ];
+
$fields['products_dimensions_by_requisites_weight_from_name'] =
[
'title' => __('Dimensions based on requisites: weight', 'wc1c-main'),
From 951d0aa9f4048f83de446572d54d592c8ae47f2d Mon Sep 17 00:00:00 2001
From: Oleg <109225168+frescoref@users.noreply.github.com>
Date: Fri, 3 Mar 2023 01:10:06 +0300
Subject: [PATCH 06/17] Fix: more
---
Admin.php | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/Admin.php b/Admin.php
index a9a450d..93805c1 100644
--- a/Admin.php
+++ b/Admin.php
@@ -1748,7 +1748,6 @@ public function configurationsFieldsProductsDimensions(array $fields): array
$products_dimensions_source_options =
[
'no' => __('Do not use', 'wc1c-main'),
- 'yes' => __('From the standard fields', 'wc1c-main'),
'yes_requisites' => __('From requisite with the specified name', 'wc1c-main'),
];
@@ -1758,12 +1757,10 @@ public function configurationsFieldsProductsDimensions(array $fields): array
'type' => 'select',
'description' => sprintf
(
- '%s
%s - %s
%s - %s
%s - %s',
+ '%s
%s - %s
%s - %s',
__('The setting works when creating and updating products (goods).', 'wc1c-main'),
__('Do not use', 'wc1c-main'),
__('Populating the dimensions data from CommerceML data will be skipped. If a product is updating, then its current dimensions will not be updated.', 'wc1c-main'),
- __('From the standard fields', 'wc1c-main'),
- __('This dimensions is contained in the standard fields of 1C products. It is located in the conditional tags.', 'wc1c-main'),
__('From requisite with the specified name', 'wc1c-main'),
__('The dimensions data will be filled in based on the completed name of the requisite of the products (goods).', 'wc1c-main')
),
From e4f09d368d7fdfc41497ffab65d149a4528134a8 Mon Sep 17 00:00:00 2001
From: Oleg <109225168+frescoref@users.noreply.github.com>
Date: Fri, 3 Mar 2023 01:20:23 +0300
Subject: [PATCH 07/17] Fix: more
---
Admin.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Admin.php b/Admin.php
index 93805c1..4abd390 100644
--- a/Admin.php
+++ b/Admin.php
@@ -1844,7 +1844,7 @@ public function configurationsFieldsLogs(array $fields): array
[
'title' => __('Maximum files', 'wc1c-main'),
'type' => 'text',
- 'description' => __('Log files created daily. This option on the maximum number of stored files. By default saved of the logs are for the last 30 days.', 'wc1c-main'),
+ 'description' => __('Log files created daily. This option on the maximum number of stored files. By default saved of the logs are for the last 10 days.', 'wc1c-main'),
'default' => 10,
'css' => 'min-width: 20px;',
];
From 80f55bd566d2a24cc7ebf847e7c4f6d8a3d005c7 Mon Sep 17 00:00:00 2001
From: Oleg <109225168+frescoref@users.noreply.github.com>
Date: Sat, 4 Mar 2023 00:51:10 +0300
Subject: [PATCH 08/17] Fix: more
---
Core.php | 215 +++++++++++++++++++++++++++++++++++--------------------
1 file changed, 138 insertions(+), 77 deletions(-)
diff --git a/Core.php b/Core.php
index e95160c..46a902b 100644
--- a/Core.php
+++ b/Core.php
@@ -51,23 +51,13 @@ class Core extends SchemaAbstract
*/
public $receiver;
- /**
- * @var string[]
- */
- public $offers_types =
- [
- 'offers',
- 'rests',
- 'prices',
- ];
-
/**
* Core constructor.
*/
public function __construct()
{
$this->setId('productscml');
- $this->setVersion('0.9.0');
+ $this->setVersion('0.10.0');
$this->setName(__('Products data exchange via CommerceML', 'wc1c-main'));
$this->setDescription(__('Creation and updating of products (goods) in WooCommerce according to data from 1C using the CommerceML protocol of various versions.', 'wc1c-main'));
@@ -172,22 +162,6 @@ public function getUploadDirectory(): string
return $this->upload_directory;
}
- /**
- * @return array string[]
- */
- public function getOffersTypes(): array
- {
- return $this->offers_types;
- }
-
- /**
- * @param string[] $offers_types
- */
- public function setOffersTypes(array $offers_types)
- {
- $this->offers_types = $offers_types;
- }
-
/**
* @param mixed $upload_directory
*/
@@ -402,11 +376,6 @@ public function processingClassifier(Reader $reader)
*/
public function processingClassifierGroups(ClassifierDataContract $classifier, Reader $reader)
{
- if($reader->getFiletype() !== 'import')
- {
- return;
- }
-
if(!$classifier->hasGroups())
{
$this->log()->info(__('Classifier groups is empty.', 'wc1c-main'));
@@ -720,11 +689,6 @@ public function processingClassifierGroups(ClassifierDataContract $classifier, R
*/
public function processingClassifierProperties(ClassifierDataContract $classifier, Reader $reader)
{
- if($reader->getFiletype() !== 'import' && $reader->getFiletype() !== 'offers')
- {
- return;
- }
-
if(!$classifier->hasProperties())
{
$this->log()->info(__('Classifier properties is empty.', 'wc1c-main'), ['filetype' => $reader->getFiletype()]);
@@ -958,18 +922,18 @@ public function processingClassifierItem(ClassifierDataContract $classifier, Rea
*/
public function processingCatalog(Reader $reader)
{
- if($reader->getFiletype() !== 'import')
+ if(false === $reader->isElement())
{
return;
}
- if(is_null($reader->catalog))
+ if($reader->nodeName === 'Каталог')
{
- $reader->catalog = new Catalog();
- }
+ if(is_null($reader->catalog))
+ {
+ $reader->catalog = new Catalog();
+ }
- if($reader->nodeName === 'Каталог' && $reader->isElement())
- {
$only_changes = $reader->xml_reader->getAttribute('СодержитТолькоИзменения') ?: true;
if($only_changes === 'false')
{
@@ -978,7 +942,7 @@ public function processingCatalog(Reader $reader)
$reader->catalog->setOnlyChanges($only_changes);
}
- if($reader->parentNodeName === 'Каталог' && $reader->isElement())
+ if($reader->parentNodeName === 'Каталог')
{
switch($reader->nodeName)
{
@@ -1009,7 +973,7 @@ public function processingCatalog(Reader $reader)
/*
* Пропуск создания и обновления продуктов
*/
- if($reader->nodeName === 'Товары' && $reader->isElement()
+ if($reader->nodeName === 'Товары'
&& 'yes' !== $this->getOptions('products_update', 'no')
&& 'yes' !== $this->getOptions('products_create', 'no')
)
@@ -1018,7 +982,7 @@ public function processingCatalog(Reader $reader)
$reader->next();
}
- if($reader->parentNodeName === 'Товары' && $reader->nodeName === 'Товар' && $reader->isElement())
+ if($reader->parentNodeName === 'Товары' && $reader->nodeName === 'Товар')
{
$product_xml = new SimpleXMLElement($reader->xml_reader->readOuterXml());
@@ -1827,6 +1791,11 @@ public function assignProductsItemTaxesClass(ProductContract $internal_product,
*/
public function assignProductsItemImages(ProductContract $internal_product, ProductDataContract $external_product, string $mode, Reader $reader): ProductContract
{
+ if('yes' !== $this->getOptions('products_images_by_cml', 'no'))
+ {
+ return $internal_product;
+ }
+
if('create' === $mode && false === $external_product->hasImages())
{
return $internal_product;
@@ -1842,29 +1811,35 @@ public function assignProductsItemImages(ProductContract $internal_product, Prod
return $internal_product;
}
- if('update' === $mode && 'yes' !== $this->getOptions('products_update_images', 'no'))
+ if('update' === $mode && 'no' === $this->getOptions('products_update_images', 'no'))
{
return $internal_product;
}
- if('yes' !== $this->getOptions('products_images_by_cml', 'no'))
+ $images_mode = $this->getOptions('products_update_images', 'no');
+ $images_max = $this->getOptions('products_images_by_cml_max', 10);
+ $external_images = $external_product->getImages();
+
+ if('update' === $mode && 'add' === $images_mode && !empty($internal_product->get_image_id()))
{
return $internal_product;
}
- $max_images = $this->getOptions('products_images_by_cml_max', 10);
+ if('update' === $mode && empty($external_images) && 'yes_yes' === $images_mode && empty($internal_product->get_image_id()))
+ {
+ return $internal_product;
+ }
/** @var ImagesStorageContract $images_storage */
$images_storage = Storage::load('image');
- $images = $external_product->getImages();
$gallery_image_ids = [];
- if(is_array($images))
+ if(is_array($external_images))
{
- foreach($images as $index => $image)
+ foreach($external_images as $index => $image)
{
- if($index >= $max_images)
+ if($index >= $images_max)
{
$this->log()->notice(__('The maximum possible number of images has been processed. The rest of the images are skip.', 'wc1c-main'));
break;
@@ -1923,7 +1898,19 @@ public function assignProductsItemImages(ProductContract $internal_product, Prod
*/
public function assignProductsItemDimensions(ProductContract $internal_product, ProductDataContract $external_product, string $mode, Reader $reader): ProductContract
{
- if('yes' !== $this->getOptions('products_dimensions_by_requisites', 'no'))
+ if('create' === $mode && 'no' === $this->getOptions('products_create_adding_dimensions', 'yes'))
+ {
+ return $internal_product;
+ }
+
+ if('update' === $mode && 'no' === $this->getOptions('products_update_dimensions', 'no'))
+ {
+ return $internal_product;
+ }
+
+ $dimensions_source = $this->getOptions('products_dimensions_source', 'yes_requisites');
+
+ if($dimensions_source === 'no')
{
return $internal_product;
}
@@ -1934,7 +1921,7 @@ public function assignProductsItemDimensions(ProductContract $internal_product,
$weight = '';
$weight_name = trim($this->getOptions('products_dimensions_by_requisites_weight_from_name', 'Вес'));
- if($weight_name !== '' && $external_product->hasRequisites($weight_name))
+ if($weight_name !== '' && $dimensions_source === 'yes_requisites' && $external_product->hasRequisites($weight_name))
{
$requisite_data = $external_product->getRequisites($weight_name);
if(!empty($requisite_data['value']))
@@ -1943,12 +1930,30 @@ public function assignProductsItemDimensions(ProductContract $internal_product,
}
}
- if(has_filter('wc1c_products_dimensions_by_requisites_weight'))
+ if(has_filter('wc1c_schema_productscml_products_dimensions_weight'))
{
- $weight = apply_filters('wc1c_products_dimensions_by_requisites_weight', $weight, $internal_product, $external_product, $mode, $reader, $this);
+ $weight = apply_filters('wc1c_schema_productscml_products_dimensions_weight', $weight, $internal_product, $external_product, $mode, $reader, $this);
}
- $internal_product->set_weight($weight);
+ if('update' === $mode && 'add' === $this->getOptions('products_update_dimensions', 'no') && empty($internal_product->get_weight()))
+ {
+ $internal_product->set_weight($weight);
+ }
+
+ if('update' === $mode && !empty($weight) && 'yes_yes' === $this->getOptions('products_update_dimensions', 'no') && !empty($internal_product->get_weight()))
+ {
+ $internal_product->set_weight($weight);
+ }
+
+ if('update' === $mode && 'yes' === $this->getOptions('products_update_dimensions', 'no'))
+ {
+ $internal_product->set_weight($weight);
+ }
+
+ if('create' === $mode)
+ {
+ $internal_product->set_weight($weight);
+ }
/**
* Длина
@@ -1956,7 +1961,7 @@ public function assignProductsItemDimensions(ProductContract $internal_product,
$length = '';
$length_name = trim($this->getOptions('products_dimensions_by_requisites_length_from_name', 'Длина'));
- if($length_name !== '' && $external_product->hasRequisites($length_name))
+ if($length_name !== '' && $dimensions_source === 'yes_requisites' && $external_product->hasRequisites($length_name))
{
$requisite_data = $external_product->getRequisites($length_name);
if(!empty($requisite_data['value']))
@@ -1965,12 +1970,30 @@ public function assignProductsItemDimensions(ProductContract $internal_product,
}
}
- if(has_filter('wc1c_products_dimensions_by_requisites_length'))
+ if(has_filter('wc1c_schema_productscml_products_dimensions_length'))
+ {
+ $length = apply_filters('wc1c_schema_productscml_products_dimensions_length', $length, $internal_product, $external_product, $mode, $reader, $this);
+ }
+
+ if('update' === $mode && 'add' === $this->getOptions('products_update_dimensions', 'no') && empty($internal_product->get_length()))
+ {
+ $internal_product->set_length($length);
+ }
+
+ if('update' === $mode && !empty($length) && 'yes_yes' === $this->getOptions('products_update_dimensions', 'no') && !empty($internal_product->get_length()))
+ {
+ $internal_product->set_length($length);
+ }
+
+ if('update' === $mode && 'yes' === $this->getOptions('products_update_dimensions', 'no'))
{
- $length = apply_filters('wc1c_products_dimensions_by_requisites_length', $length, $internal_product, $external_product, $mode, $reader, $this);
+ $internal_product->set_length($length);
}
- $internal_product->set_length($length);
+ if('create' === $mode)
+ {
+ $internal_product->set_length($length);
+ }
/**
* Ширина
@@ -1978,7 +2001,7 @@ public function assignProductsItemDimensions(ProductContract $internal_product,
$width = '';
$width_name = trim($this->getOptions('products_dimensions_by_requisites_width_from_name', 'Ширина'));
- if($width_name !== '' && $external_product->hasRequisites($width_name))
+ if($width_name !== '' && $dimensions_source === 'yes_requisites' && $external_product->hasRequisites($width_name))
{
$requisite_data = $external_product->getRequisites($width_name);
if(!empty($requisite_data['value']))
@@ -1987,12 +2010,30 @@ public function assignProductsItemDimensions(ProductContract $internal_product,
}
}
- if(has_filter('wc1c_products_dimensions_by_requisites_width'))
+ if(has_filter('wc1c_schema_productscml_products_dimensions_width'))
{
- $width = apply_filters('wc1c_products_dimensions_by_requisites_width', $width, $internal_product, $external_product, $mode, $reader, $this);
+ $width = apply_filters('wc1c_schema_productscml_products_dimensions_width', $width, $internal_product, $external_product, $mode, $reader, $this);
}
- $internal_product->set_width($width);
+ if('update' === $mode && 'add' === $this->getOptions('products_update_dimensions', 'no') && empty($internal_product->get_width()))
+ {
+ $internal_product->set_width($width);
+ }
+
+ if('update' === $mode && !empty($width) && 'yes_yes' === $this->getOptions('products_update_dimensions', 'no') && !empty($internal_product->get_width()))
+ {
+ $internal_product->set_width($width);
+ }
+
+ if('update' === $mode && 'yes' === $this->getOptions('products_update_dimensions', 'no'))
+ {
+ $internal_product->set_width($width);
+ }
+
+ if('create' === $mode)
+ {
+ $internal_product->set_width($width);
+ }
/**
* Высота
@@ -2000,7 +2041,7 @@ public function assignProductsItemDimensions(ProductContract $internal_product,
$height = '';
$height_name = trim($this->getOptions('products_dimensions_by_requisites_height_from_name', 'Высота'));
- if($height_name !== '' && $external_product->hasRequisites($height_name))
+ if($height_name !== '' && $dimensions_source === 'yes_requisites' && $external_product->hasRequisites($height_name))
{
$requisite_data = $external_product->getRequisites($height_name);
if(!empty($requisite_data['value']))
@@ -2009,12 +2050,30 @@ public function assignProductsItemDimensions(ProductContract $internal_product,
}
}
- if(has_filter('wc1c_products_dimensions_by_requisites_height'))
+ if(has_filter('wc1c_schema_productscml_products_dimensions_height'))
{
- $height = apply_filters('wc1c_products_dimensions_by_requisites_height', $height, $internal_product, $external_product, $mode, $reader, $this);
+ $height = apply_filters('wc1c_schema_productscml_products_dimensions_height', $height, $internal_product, $external_product, $mode, $reader, $this);
}
- $internal_product->set_height($height);
+ if('update' === $mode && 'add' === $this->getOptions('products_update_dimensions', 'no') && empty($internal_product->get_height()))
+ {
+ $internal_product->set_height($height);
+ }
+
+ if('update' === $mode && !empty($height) && 'yes_yes' === $this->getOptions('products_update_dimensions', 'no') && !empty($internal_product->get_height()))
+ {
+ $internal_product->set_height($height);
+ }
+
+ if('update' === $mode && 'yes' === $this->getOptions('products_update_dimensions', 'no'))
+ {
+ $internal_product->set_height($height);
+ }
+
+ if('create' === $mode)
+ {
+ $internal_product->set_height($height);
+ }
return $internal_product;
}
@@ -3157,6 +3216,8 @@ public function processingProductsItem(ProductDataContract $external_product, Re
return;
}
+ $this->log()->info(__('Product is found. Updating.', 'wc1c-main'));
+
/**
* Обновление существующих продуктов отключено
*/
@@ -3306,7 +3367,7 @@ public function processingOffersItem(ProductDataContract $external_offer, Reader
if(empty($internal_offer_id) && empty($external_offer->getCharacteristicId()))
{
- $this->log()->notice(__('Product not found. Offer update skipped.', 'wc1c-main'), ['offer' => $external_offer]);
+ $this->log()->notice(__('Product not found. Offer update skipped.', 'wc1c-main'), ['offer' => $external_offer->getData()]);
return;
}
@@ -3430,7 +3491,7 @@ public function processingOffersItem(ProductDataContract $external_offer, Reader
*/
public function processingOffers(Reader $reader)
{
- if(!in_array($reader->getFiletype(), $this->getOffersTypes(), true))
+ if(false === $reader->isElement())
{
return;
}
@@ -3440,7 +3501,7 @@ public function processingOffers(Reader $reader)
$reader->offers_package = new OffersPackage();
}
- if($reader->nodeName === 'ПакетПредложений' && $reader->isElement())
+ if($reader->nodeName === 'ПакетПредложений')
{
$only_changes = $reader->xml_reader->getAttribute('СодержитТолькоИзменения') ?: true;
if($only_changes === 'false')
@@ -3454,13 +3515,13 @@ public function processingOffers(Reader $reader)
$this->log()->debug(__('The offer package object contains only the changes.', 'wc1c-main'));
}
}
- elseif($reader->nodeName === 'ИзмененияПакетаПредложений' && $reader->isElement())
+ elseif($reader->nodeName === 'ИзмененияПакетаПредложений')
{
$this->log()->debug(__('The offer package object contains only the changes.', 'wc1c-main'));
$reader->offers_package->setOnlyChanges(true);
}
- if(($reader->parentNodeName === 'ПакетПредложений' || $reader->parentNodeName === 'ИзмененияПакетаПредложений') && $reader->isElement())
+ if(($reader->parentNodeName === 'ПакетПредложений' || $reader->parentNodeName === 'ИзмененияПакетаПредложений'))
{
switch($reader->nodeName)
{
@@ -3497,7 +3558,7 @@ public function processingOffers(Reader $reader)
}
}
- if($reader->nodeName === 'Предложения' && $reader->isElement())
+ if($reader->nodeName === 'Предложения')
{
if(false === $reader->offers_package->isOnlyChanges())
{
@@ -3522,7 +3583,7 @@ public function processingOffers(Reader $reader)
}
}
- if($reader->parentNodeName === 'Предложения' && $reader->nodeName === 'Предложение' && $reader->isElement())
+ if($reader->parentNodeName === 'Предложения' && $reader->nodeName === 'Предложение')
{
$offer_xml = new SimpleXMLElement($reader->xml_reader->readOuterXml());
From fa77c0838dcd7906ea1b491d24fdb05bea38a0a2 Mon Sep 17 00:00:00 2001
From: Oleg <109225168+frescoref@users.noreply.github.com>
Date: Sat, 4 Mar 2023 00:51:16 +0300
Subject: [PATCH 09/17] Fix: more
---
Admin.php | 69 ++++++++++++++++++-------------------------------------
1 file changed, 22 insertions(+), 47 deletions(-)
diff --git a/Admin.php b/Admin.php
index 4abd390..f5013d3 100644
--- a/Admin.php
+++ b/Admin.php
@@ -52,7 +52,6 @@ public function initConfigurationsFields()
add_filter('wc1c_configurations-update_form_load_fields', [$this, 'configurationsFieldsCategoriesClassifierGroups'], 85, 1);
add_filter('wc1c_configurations-update_form_load_fields', [$this, 'configurationsFieldsAttributes'], 90, 1);
- add_filter('wc1c_configurations-update_form_load_fields', [$this, 'configurationsFieldsAttributesClassifierProperties'], 90, 1);
add_filter('wc1c_configurations-update_form_load_fields', [$this, 'configurationsFieldsMediaLibrary'], 100, 1);
@@ -477,68 +476,59 @@ public function configurationsFieldsAttributes(array $fields): array
'default' => 'no'
];
- $fields['attributes_update'] =
+ $fields['attributes_create_by_classifier_properties'] =
[
- 'title' => __('Updating attributes', 'wc1c-main'),
+ 'title' => __('Creating attributes from classifier properties', 'wc1c-main'),
'type' => 'checkbox',
'label' => __('Check the box if you want to enable this feature. Disabled by default.', 'wc1c-main'),
'description' => sprintf
(
'%s
%s',
- __('It will be allowed to update common attributes for products based on characteristics, properties and other data according to the other setting sections.', 'wc1c-main'),
- __('Attribute updating refers to adding product attribute values based on product characteristics, classifier properties, and other data specified in the settings. If you disable this feature, work will only occur with existing attribute values without updating attribute data. In some cases, updating refers to sorting and renaming the attributes themselves.', 'wc1c-main')
+ __('The creation will occur when processing the properties of the classifier. Creation occurs only if there is no attribute with the specified name or associated identifier.', 'wc1c-main'),
+ __('If disable the creation of attributes and create some attributes manually, it is possible to adding values to them.', 'wc1c-main')
),
'default' => 'no'
];
- return $fields;
- }
-
- /**
- * Configuration fields: attributes
- *
- * @param array $fields
- *
- * @return array
- */
- public function configurationsFieldsAttributesClassifierProperties(array $fields): array
- {
- $fields['attributes_classifier_properties'] =
+ $fields['attributes_update'] =
[
- 'title' => __('Attributes: classifier properties', 'wc1c-main'),
- 'type' => 'title',
+ 'title' => __('Updating attributes', 'wc1c-main'),
+ 'type' => 'checkbox',
+ 'label' => __('Check the box if you want to enable this feature. Disabled by default.', 'wc1c-main'),
'description' => sprintf
(
- '%s %s',
- __('Adding and updating global attributes for products from classifier properties.', 'wc1c-main'),
- __('The properties are contained both in the classifier of the offer package and the product catalog.', 'wc1c-main')
+ '%s
%s',
+ __('It will be allowed to update common attributes for products based on characteristics, properties and other data according to the other setting sections.', 'wc1c-main'),
+ __('Attribute updating refers to adding product attribute values based on product characteristics, classifier properties, and other data specified in the settings. If you disable this feature, work will only occur with existing attribute values without updating attribute data. In some cases, updating refers to sorting and renaming the attributes themselves.', 'wc1c-main')
),
+ 'default' => 'no'
];
- $fields['attributes_create_by_classifier_properties'] =
+ $fields['attributes_values_by_classifier_properties'] =
[
- 'title' => __('Creating attributes from classifier properties', 'wc1c-main'),
+ 'title' => __('Updating attributes values from classifier properties', 'wc1c-main'),
'type' => 'checkbox',
'label' => __('Check the box if you want to enable this feature. Disabled by default.', 'wc1c-main'),
'description' => sprintf
(
'%s
%s',
- __('The creation will occur when processing the properties of the classifier. Creation occurs only if there is no attribute with the specified name or associated identifier.', 'wc1c-main'),
- __('If disable the creation of attributes and create some attributes manually, it is possible to adding values to them.', 'wc1c-main')
+ __('Adding product attribute values based on classifier property values.', 'wc1c-main'),
+ __('The value is added only if it is absent: by name.', 'wc1c-main')
),
'default' => 'no'
];
- $fields['attributes_values_by_classifier_properties'] =
+ $fields['attributes_values_by_product_properties'] =
[
- 'title' => __('Adding values to attributes from classifier properties', 'wc1c-main'),
+ 'title' => __('Adding values to attributes from product properties', 'wc1c-main'),
'type' => 'checkbox',
'label' => __('Check the box if you want to enable this feature. Disabled by default.', 'wc1c-main'),
'description' => sprintf
(
- '%s
%s',
- __('Adding product attribute values based on classifier property values.', 'wc1c-main'),
- __('The value is added only if it is absent: by name.', 'wc1c-main')
+ '%s
%s %s',
+ __('Classifier properties do not always contain values in the reference. When the setting is enabled, values will be added based on the values of the product properties.', 'wc1c-main'),
+ __('The value is added only if it is absent: by name.', 'wc1c-main'),
+ __('The value is added only if it is missing. If do not add a value, the attribute will be skipped.', 'wc1c-main')
),
'default' => 'no'
];
@@ -1231,21 +1221,6 @@ public function configurationsFieldsProductsAttributes(array $fields): array
'default' => 'no'
];
- $fields['attributes_values_by_product_properties'] =
- [
- 'title' => __('Adding values to attributes from product properties', 'wc1c-main'),
- 'type' => 'checkbox',
- 'label' => __('Check the box if you want to enable this feature. Disabled by default.', 'wc1c-main'),
- 'description' => sprintf
- (
- '%s
%s %s',
- __('Classifier properties do not always contain values in the reference. When the setting is enabled, values will be added based on the values of the product properties.', 'wc1c-main'),
- __('The value is added only if it is absent: by name.', 'wc1c-main'),
- __('The value is added only if it is missing. If do not add a value, the attribute will be skipped.', 'wc1c-main')
- ),
- 'default' => 'no'
- ];
-
return $fields;
}
From 54aa38f53627e4c727280291a54532d8d32a99ef Mon Sep 17 00:00:00 2001
From: Oleg <109225168+frescoref@users.noreply.github.com>
Date: Sat, 4 Mar 2023 10:13:40 +0300
Subject: [PATCH 10/17] Fix: more
---
Admin.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Admin.php b/Admin.php
index f5013d3..d5e4671 100644
--- a/Admin.php
+++ b/Admin.php
@@ -33,6 +33,7 @@ public function initConfigurationsFields()
add_filter('wc1c_configurations-update_form_load_fields', [$this, 'configurationsFieldsProductsSync'], 30, 1);
add_filter('wc1c_configurations-update_form_load_fields', [$this, 'configurationsFieldsProductsSku'], 60, 1);
+ add_filter('wc1c_configurations-update_form_load_fields', [$this, 'configurationsFieldsProductsCategories'], 60, 1);
add_filter('wc1c_configurations-update_form_load_fields', [$this, 'configurationsFieldsProductsNames'], 60, 1);
add_filter('wc1c_configurations-update_form_load_fields', [$this, 'configurationsFieldsProductsDescriptions'], 60, 1);
add_filter('wc1c_configurations-update_form_load_fields', [$this, 'configurationsFieldsProductsImages'], 60, 1);
@@ -42,7 +43,6 @@ public function initConfigurationsFields()
add_filter('wc1c_configurations-update_form_load_fields', [$this, 'configurationsFieldsProductsTaxes'], 70, 1);
add_filter('wc1c_configurations-update_form_load_fields', [$this, 'configurationsFieldsProductsInventories'], 72, 1);
add_filter('wc1c_configurations-update_form_load_fields', [$this, 'configurationsFieldsProductsDimensions'], 74, 1);
- add_filter('wc1c_configurations-update_form_load_fields', [$this, 'configurationsFieldsProductsCategories'], 76, 1);
add_filter('wc1c_configurations-update_form_load_fields', [$this, 'configurationsFieldsProductsOther'], 79, 1);
From 63788df228da4804f2566445e99e46beabd4be40 Mon Sep 17 00:00:00 2001
From: Oleg <109225168+frescoref@users.noreply.github.com>
Date: Sat, 4 Mar 2023 10:34:50 +0300
Subject: [PATCH 11/17] Fix: more
---
Admin.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/Admin.php b/Admin.php
index d5e4671..4f80d5e 100644
--- a/Admin.php
+++ b/Admin.php
@@ -40,8 +40,8 @@ public function initConfigurationsFields()
add_filter('wc1c_configurations-update_form_load_fields', [$this, 'configurationsFieldsProductsAttributes'], 60, 1);
add_filter('wc1c_configurations-update_form_load_fields', [$this, 'configurationsFieldsProductsPrices'], 70, 1);
- add_filter('wc1c_configurations-update_form_load_fields', [$this, 'configurationsFieldsProductsTaxes'], 70, 1);
- add_filter('wc1c_configurations-update_form_load_fields', [$this, 'configurationsFieldsProductsInventories'], 72, 1);
+ add_filter('wc1c_configurations-update_form_load_fields', [$this, 'configurationsFieldsProductsInventories'], 71, 1);
+ add_filter('wc1c_configurations-update_form_load_fields', [$this, 'configurationsFieldsProductsTaxes'], 73, 1);
add_filter('wc1c_configurations-update_form_load_fields', [$this, 'configurationsFieldsProductsDimensions'], 74, 1);
add_filter('wc1c_configurations-update_form_load_fields', [$this, 'configurationsFieldsProductsOther'], 79, 1);
From 7dd488358da44b9b412b591797bf8fb0d4548859 Mon Sep 17 00:00:00 2001
From: Oleg <109225168+frescoref@users.noreply.github.com>
Date: Sat, 4 Mar 2023 10:54:16 +0300
Subject: [PATCH 12/17] Init: _catalog_full_time
---
Core.php | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/Core.php b/Core.php
index 46a902b..f86dfdb 100644
--- a/Core.php
+++ b/Core.php
@@ -940,6 +940,13 @@ public function processingCatalog(Reader $reader)
$only_changes = false;
}
$reader->catalog->setOnlyChanges($only_changes);
+
+ if(false === $only_changes)
+ {
+ $this->log()->notice(__('The time of the last full exchange has been set.', 'wc1c-main'));
+ $this->configuration()->addMetaData('_catalog_full_time', current_time('timestamp'), true);
+ $this->configuration()->saveMetaData();
+ }
}
if($reader->parentNodeName === 'Каталог')
From 6d5126b35099f567007da56d6ff1cf33a8ca9f75 Mon Sep 17 00:00:00 2001
From: Oleg <109225168+frescoref@users.noreply.github.com>
Date: Sat, 4 Mar 2023 15:31:34 +0300
Subject: [PATCH 13/17] Init: _catalog_full_time #2
---
Receiver.php | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/Receiver.php b/Receiver.php
index bcf5d27..31f8e0a 100644
--- a/Receiver.php
+++ b/Receiver.php
@@ -127,6 +127,16 @@ public function handlerCatalogModeComplete()
*/
public function handlerCatalogModeDeactivate()
{
+ if(isset($_GET['deactivate×tamp']))
+ {
+ $timestamp = (int)$_GET['deactivate×tamp'];
+
+ $this->core()->log()->notice(__('The time of the last full exchange has been set.', 'wc1c-main'));
+
+ $this->core()->configuration()->addMetaData('_catalog_full_time', $timestamp, true);
+ $this->core()->configuration()->saveMetaData();
+ }
+
$this->sendResponseByType('success');
}
From 6e1887326de54e2740d6bd902fa5236dc7db3bb7 Mon Sep 17 00:00:00 2001
From: Oleg <109225168+frescoref@users.noreply.github.com>
Date: Sat, 4 Mar 2023 21:58:33 +0300
Subject: [PATCH 14/17] Fix: _catalog_full_time #2
---
Receiver.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/Receiver.php b/Receiver.php
index 31f8e0a..8676101 100644
--- a/Receiver.php
+++ b/Receiver.php
@@ -127,9 +127,9 @@ public function handlerCatalogModeComplete()
*/
public function handlerCatalogModeDeactivate()
{
- if(isset($_GET['deactivate×tamp']))
+ if(isset($_GET['timestamp']))
{
- $timestamp = (int)$_GET['deactivate×tamp'];
+ $timestamp = (int)$_GET['timestamp'];
$this->core()->log()->notice(__('The time of the last full exchange has been set.', 'wc1c-main'));
From 92d941f2135a6459229c3be4847d1614487ac7fd Mon Sep 17 00:00:00 2001
From: Oleg <109225168+frescoref@users.noreply.github.com>
Date: Sun, 5 Mar 2023 02:11:29 +0300
Subject: [PATCH 15/17] Ability: categories
---
Admin.php | 60 +++++++++++++++++++++++++----
Core.php | 113 ++++++++++++++++++++++++++++++++++++++++++++----------
2 files changed, 145 insertions(+), 28 deletions(-)
diff --git a/Admin.php b/Admin.php
index 4f80d5e..543ad4b 100644
--- a/Admin.php
+++ b/Admin.php
@@ -555,6 +555,30 @@ public function configurationsFieldsProductsCategories(array $fields): array
),
];
+ $products_categories_source_options =
+ [
+ 'no' => __('Do not use', 'wc1c-main'),
+ 'classifier_groups' => __('From classifier groups', 'wc1c-main'),
+ ];
+
+ $fields['products_categories_source'] =
+ [
+ 'title' => __('Source for categories', 'wc1c-main'),
+ 'type' => 'select',
+ 'description' => sprintf
+ (
+ '%s
%s - %s
%s - %s %s',
+ __('The setting works when creating and updating products (goods).', 'wc1c-main'),
+ __('Do not use', 'wc1c-main'),
+ __('Populating the categories data from CommerceML data will be skipped. If a product is updating, then its current categories will not be updated.', 'wc1c-main'),
+ __('From classifier groups', 'wc1c-main'),
+ __('The categories data will be filled in based on the classifier groups of the products (goods).', 'wc1c-main'),
+ __('To use this mode, need to configure the creation of categories based on classifier groups.', 'wc1c-main')
+ ),
+ 'default' => 'classifier_groups',
+ 'options' => $products_categories_source_options
+ ];
+
$fields['products_create_adding_category'] =
[
'title' => __('Assigning categories of the created product', 'wc1c-main'),
@@ -583,14 +607,34 @@ public function configurationsFieldsProductsCategories(array $fields): array
'default' => 'yes'
];
- $fields['products_update_categories'] =
- [
- 'title' => __('Product categories update when requesting product updates', 'wc1c-main'),
- 'type' => 'checkbox',
- 'label' => __('Check the box if you want to enable this feature. Disabled by default.', 'wc1c-main'),
- 'description' => __('If the setting is disabled, new categories will not be assigned to old products. Categories can be edited manually and the data will remain unchanged.', 'wc1c-main'),
- 'default' => 'no'
- ];
+ $products_update_categories_options =
+ [
+ 'no' => __('Do not update', 'wc1c-main'),
+ 'yes' => __('Update in any case', 'wc1c-main'),
+ 'add' => __('Add if not on the site and available in 1C', 'wc1c-main'),
+ 'yes_yes' => __('Update if present on the site and in 1C', 'wc1c-main'),
+ ];
+
+ $fields['products_update_categories'] =
+ [
+ 'title' => __('Categories updating when products updates', 'wc1c-main'),
+ 'default' => 'no',
+ 'type' => 'select',
+ 'description' => sprintf
+ (
+ '%s - %s
%s - %s
%s - %s
%s - %s
%s',
+ __('Do not update', 'wc1c-main'),
+ __('Categories updates will be skipped in any case.', 'wc1c-main'),
+ __('Update in any case', 'wc1c-main'),
+ __('Categories will be updated in any case. The same value will always be on the site and in 1C.', 'wc1c-main'),
+ __('Add if not on the site and available in 1C', 'wc1c-main'),
+ __('Existing categories will not be affected. There will be a filling of those missing on the site if they are available in 1C.', 'wc1c-main'),
+ __('Update if present on the site and in 1C', 'wc1c-main'),
+ __('Categories will be updated only if they are filled in 1C and on the site at the same time.', 'wc1c-main'),
+ __('The setting works when updating products (goods).', 'wc1c-main')
+ ),
+ 'options' => $products_update_categories_options
+ ];
$fields['products_update_categories_fill_parent'] =
[
diff --git a/Core.php b/Core.php
index f86dfdb..194a1ae 100644
--- a/Core.php
+++ b/Core.php
@@ -1668,12 +1668,17 @@ public function assignProductsItemDescriptionsFull(ProductContract $internal_pro
*/
public function assignProductsItemCategories(ProductContract $internal_product, ProductDataContract $external_product, string $mode, Reader $reader): ProductContract
{
- if('create' === $mode && 'yes' !== $this->getOptions('products_create_adding_category', 'yes'))
+ if('create' === $mode && 'no' === $this->getOptions('products_create_adding_category', 'yes'))
{
return $internal_product;
}
- if('update' === $mode && 'yes' !== $this->getOptions('products_update_categories', 'no'))
+ if('create' === $mode && false === $external_product->hasClassifierGroups())
+ {
+ return $internal_product;
+ }
+
+ if('update' === $mode && 'no' === $this->getOptions('products_update_categories', 'no'))
{
return $internal_product;
}
@@ -1683,34 +1688,102 @@ public function assignProductsItemCategories(ProductContract $internal_product,
return $internal_product;
}
- if('create' === $mode && false === $external_product->hasClassifierGroups())
- {
- return $internal_product;
- }
+ $source = $this->getOptions('products_categories_source', 'classifier_groups');
- $cats = [];
+ if('no' === $source)
+ {
+ return $internal_product;
+ }
- if($external_product->hasClassifierGroups())
- {
- /** @var CategoriesStorageContract $categories_storage */
- $categories_storage = Storage::load('category');
+ $cats = [];
- foreach($external_product->getClassifierGroups() as $classifier_group)
- {
- $cat = $categories_storage->getByExternalId($classifier_group);
+ if(($source === 'classifier_groups') && $external_product->hasClassifierGroups())
+ {
+ $classifier_groups = $external_product->getClassifierGroups();
- if($cat instanceof Category)
- {
- $cats[] = $cat->getId();
- }
- }
- }
+ /** @var CategoriesStorageContract $categories_storage */
+ $categories_storage = Storage::load('category');
+
+ foreach($classifier_groups as $classifier_group)
+ {
+ $cat = $categories_storage->getByExternalId($classifier_group);
+
+ if($cat instanceof Category)
+ {
+ $cats[] = $cat->getId();
+ }
+ }
+ }
+
+ if('update' === $mode && 'add' === $this->getOptions('products_update_categories', 'no') && !empty($internal_product->get_category_ids()))
+ {
+ return $internal_product;
+ }
+
+ if('update' === $mode && empty($cats) && 'yes_yes' === $this->getOptions('products_update_categories', 'no') && empty($internal_product->get_category_ids()))
+ {
+ return $internal_product;
+ }
+
+ if
+ (
+ ('create' === $mode && $this->getOptions('products_create_adding_category_fill_parent', 'yes') === 'yes')
+ ||
+ ('update' === $mode && $this->getOptions('products_update_categories_fill_parent', 'yes') === 'yes')
+ )
+ {
+ $this->fillParentCategories($product_categories);
+ }
$internal_product->set_category_ids($cats);
return $internal_product;
}
+ /**
+ * Заполняет родительские категории у продукта
+ *
+ * @param $product_categories
+ *
+ * @return array
+ */
+ private function fillParentCategories(&$product_categories): array
+ {
+ if(empty($product_categories))
+ {
+ return $product_categories;
+ }
+
+ foreach($product_categories as $category_id)
+ {
+ $parents = $this->findParentCategories($category_id);
+
+ foreach($parents as $parent_id)
+ {
+ $key = array_search($parent_id, $product_categories, true);
+
+ if($key === false)
+ {
+ $product_categories[] = $parent_id;
+ }
+ }
+ }
+
+ return $product_categories;
+ }
+
+ /**
+ * Поиск всех родительских категорий
+ *
+ * @param int $category_id
+ *
+ * @return array
+ */
+ private function findParentCategories(int $category_id): array
+ {
+ return get_ancestors($category_id, 'product_cat');
+ }
+
/**
* Назначение данных продукта исходя из режима: статус налога
*
From cdc41867f19dfd69f3b4a5fb7c1c4a6e85cf0dbf Mon Sep 17 00:00:00 2001
From: Oleg <109225168+frescoref@users.noreply.github.com>
Date: Sun, 5 Mar 2023 02:16:04 +0300
Subject: [PATCH 16/17] Fix: more
---
Admin.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Admin.php b/Admin.php
index 543ad4b..af9e84b 100644
--- a/Admin.php
+++ b/Admin.php
@@ -581,7 +581,7 @@ public function configurationsFieldsProductsCategories(array $fields): array
$fields['products_create_adding_category'] =
[
- 'title' => __('Assigning categories of the created product', 'wc1c-main'),
+ 'title' => __('Assigning categories of the creating products', 'wc1c-main'),
'type' => 'checkbox',
'label' => __('Check the box to enable this feature. Enabled by default.', 'wc1c-main'),
'description' => sprintf
From 728461e4516f98e21b68b8e6a440c9271c258bc0 Mon Sep 17 00:00:00 2001
From: Oleg <109225168+frescoref@users.noreply.github.com>
Date: Sun, 5 Mar 2023 02:46:06 +0300
Subject: [PATCH 17/17] Fix: more
---
Admin.php | 148 +++++++++++++++++++++++-------------------------------
1 file changed, 64 insertions(+), 84 deletions(-)
diff --git a/Admin.php b/Admin.php
index af9e84b..3c660c2 100644
--- a/Admin.php
+++ b/Admin.php
@@ -49,7 +49,6 @@ public function initConfigurationsFields()
add_filter('wc1c_configurations-update_form_load_fields', [$this, 'configurationsFieldsProductsWithCharacteristics'], 80, 1);
add_filter('wc1c_configurations-update_form_load_fields', [$this, 'configurationsFieldsCategories'], 80, 1);
- add_filter('wc1c_configurations-update_form_load_fields', [$this, 'configurationsFieldsCategoriesClassifierGroups'], 85, 1);
add_filter('wc1c_configurations-update_form_load_fields', [$this, 'configurationsFieldsAttributes'], 90, 1);
@@ -267,6 +266,33 @@ public function configurationsFieldsCategories(array $fields): array
'default' => 'no'
];
+ $fields['categories_classifier_groups_create'] =
+ [
+ 'title' => __('Creating categories from classifier groups', 'wc1c-main'),
+ 'type' => 'checkbox',
+ 'label' => __('Check the box if you want to enable this feature. Disabled by default.', 'wc1c-main'),
+ 'description' => __('Categories are only created if they have not been created before. Also, if access to work with categories is allowed from the global settings.', 'wc1c-main'),
+ 'default' => 'no'
+ ];
+
+ $fields['categories_classifier_groups_create_assign_parent'] =
+ [
+ 'title' => __('Assign parent categories on creating', 'wc1c-main'),
+ 'type' => 'checkbox',
+ 'label' => __('Check the box if you want to enable this feature. Disabled by default.', 'wc1c-main'),
+ 'description' => __('If there is a parent category in 1C, it will also be assigned in WooCommerce. The setting is triggered when a category is created.', 'wc1c-main'),
+ 'default' => 'yes'
+ ];
+
+ $fields['categories_classifier_groups_create_assign_description'] =
+ [
+ 'title' => __('Assign categories description on creating', 'wc1c-main'),
+ 'type' => 'checkbox',
+ 'label' => __('Check the box if you want to enable this feature. Disabled by default.', 'wc1c-main'),
+ 'description' => __('When creating categories, descriptions will be filled in if category descriptions are present in 1C.', 'wc1c-main'),
+ 'default' => 'no'
+ ];
+
$fields['categories_update'] =
[
'title' => __('Updating categories', 'wc1c-main'),
@@ -281,6 +307,43 @@ public function configurationsFieldsCategories(array $fields): array
'default' => 'no'
];
+ $fields['categories_classifier_groups_update'] =
+ [
+ 'title' => __('Updating categories from classifier groups', 'wc1c-main'),
+ 'type' => 'checkbox',
+ 'label' => __('Check the box if you want to enable this feature. Disabled by default.', 'wc1c-main'),
+ 'description' => __('If the category created earlier was linked to 1C data, then when you change any category data in 1C, the data will also change in WooCommerce.', 'wc1c-main'),
+ 'default' => 'no'
+ ];
+
+ $fields['categories_classifier_groups_update_parent'] =
+ [
+ 'title' => __('Update parent categories on updating', 'wc1c-main'),
+ 'type' => 'checkbox',
+ 'label' => __('Check the box if you want to enable this feature. Disabled by default.', 'wc1c-main'),
+ 'description' => __('When enabled, parent categories will be updated when they are updated in 1C. The setting is triggered when a category is updated.', 'wc1c-main'),
+ 'default' => 'yes'
+ ];
+
+ $fields['categories_classifier_groups_update_name'] =
+ [
+ 'title' => __('Updating categories name', 'wc1c-main'),
+ 'type' => 'checkbox',
+ 'label' => __('Check the box if you want to enable this feature. Disabled by default.', 'wc1c-main'),
+ 'description' => __('If the category was previously linked to 1C data, then when changing the name in 1C, the name will also change in WooCommerce.', 'wc1c-main'),
+ 'default' => 'no'
+ ];
+
+ $fields['categories_classifier_groups_update_description'] =
+ [
+ 'title' => __('Updating categories description', 'wc1c-main'),
+ 'type' => 'checkbox',
+ 'label' => __('Check the box if you want to enable this feature. Disabled by default.', 'wc1c-main'),
+ 'description' => __('If the category was previously linked to 1C data, then when you change the description in 1C, the description will also change in WooCommerce.
+ It should be borne in mind that descriptions in 1C are not always stored. Therefore, you should not enable this function if the descriptions were filled out on the site.', 'wc1c-main'),
+ 'default' => 'no'
+ ];
+
$fields['categories_update_only_configuration'] =
[
'title' => __('Consider configuration when updating categories', 'wc1c-main'),
@@ -302,89 +365,6 @@ public function configurationsFieldsCategories(array $fields): array
return $fields;
}
- /**
- * Configuration fields: categories from classifier groups
- *
- * @param array $fields
- *
- * @return array
- */
- public function configurationsFieldsCategoriesClassifierGroups(array $fields): array
- {
- $fields['categories_classifier_groups'] =
- [
- 'title' => __('Categories: classifier groups', 'wc1c-main'),
- 'type' => 'title',
- 'description' => __('Create and update categories based on groups from the classifier.', 'wc1c-main'),
- ];
-
- $fields['categories_classifier_groups_create'] =
- [
- 'title' => __('Creating categories from classifier groups', 'wc1c-main'),
- 'type' => 'checkbox',
- 'label' => __('Check the box if you want to enable this feature. Disabled by default.', 'wc1c-main'),
- 'description' => __('Categories are only created if they have not been created before. Also, if access to work with categories is allowed from the global settings.', 'wc1c-main'),
- 'default' => 'no'
- ];
-
- $fields['categories_classifier_groups_create_assign_parent'] =
- [
- 'title' => __('Assign parent categories on creating', 'wc1c-main'),
- 'type' => 'checkbox',
- 'label' => __('Check the box if you want to enable this feature. Disabled by default.', 'wc1c-main'),
- 'description' => __('If there is a parent category in 1C, it will also be assigned in WooCommerce. The setting is triggered when a category is created.', 'wc1c-main'),
- 'default' => 'yes'
- ];
-
- $fields['categories_classifier_groups_create_assign_description'] =
- [
- 'title' => __('Assign categories description on creating', 'wc1c-main'),
- 'type' => 'checkbox',
- 'label' => __('Check the box if you want to enable this feature. Disabled by default.', 'wc1c-main'),
- 'description' => __('When creating categories, descriptions will be filled in if category descriptions are present in 1C.', 'wc1c-main'),
- 'default' => 'no'
- ];
-
- $fields['categories_classifier_groups_update'] =
- [
- 'title' => __('Updating categories from classifier groups', 'wc1c-main'),
- 'type' => 'checkbox',
- 'label' => __('Check the box if you want to enable this feature. Disabled by default.', 'wc1c-main'),
- 'description' => __('If the category created earlier was linked to 1C data, then when you change any category data in 1C, the data will also change in WooCommerce.', 'wc1c-main'),
- 'default' => 'no'
- ];
-
- $fields['categories_classifier_groups_update_parent'] =
- [
- 'title' => __('Update parent categories on updating', 'wc1c-main'),
- 'type' => 'checkbox',
- 'label' => __('Check the box if you want to enable this feature. Disabled by default.', 'wc1c-main'),
- 'description' => __('When enabled, parent categories will be updated when they are updated in 1C. The setting is triggered when a category is updated.', 'wc1c-main'),
- 'default' => 'yes'
- ];
-
- $fields['categories_classifier_groups_update_name'] =
- [
- 'title' => __('Updating categories name', 'wc1c-main'),
- 'type' => 'checkbox',
- 'label' => __('Check the box if you want to enable this feature. Disabled by default.', 'wc1c-main'),
- 'description' => __('If the category was previously linked to 1C data, then when changing the name in 1C, the name will also change in WooCommerce.', 'wc1c-main'),
- 'default' => 'no'
- ];
-
- $fields['categories_classifier_groups_update_description'] =
- [
- 'title' => __('Updating categories description', 'wc1c-main'),
- 'type' => 'checkbox',
- 'label' => __('Check the box if you want to enable this feature. Disabled by default.', 'wc1c-main'),
- 'description' => __('If the category was previously linked to 1C data, then when you change the description in 1C, the description will also change in WooCommerce.
- It should be borne in mind that descriptions in 1C are not always stored. Therefore, you should not enable this function if the descriptions were filled out on the site.', 'wc1c-main'),
- 'default' => 'no'
- ];
-
- return $fields;
- }
-
/**
* Configuration fields: products with characteristics
*