From 6f5ad1190dcc805b1841b831f4df540de39b8979 Mon Sep 17 00:00:00 2001 From: Frescoref Date: Fri, 9 Jun 2023 08:16:11 +0300 Subject: [PATCH 1/3] Prepare: 0.13.0 --- Core.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core.php b/Core.php index 26a12cb..1e6164b 100644 --- a/Core.php +++ b/Core.php @@ -59,7 +59,7 @@ class Core extends SchemaAbstract public function __construct() { $this->setId('productscml'); - $this->setVersion('0.12.0'); + $this->setVersion('0.13.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')); From b1f3d5c5919d2c5f34249c60b1bfb156c68d316e Mon Sep 17 00:00:00 2001 From: Frescoref Date: Thu, 15 Jun 2023 14:43:02 +0300 Subject: [PATCH 2/3] Fix: more --- Receiver.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Receiver.php b/Receiver.php index fe5419a..e521378 100644 --- a/Receiver.php +++ b/Receiver.php @@ -343,13 +343,13 @@ public function handlerCheckauth() */ public function handlerCheckauthKey(bool $send_response = false): bool { + if('yes' === $this->core()->getOptions('browser_debug', 'no')) + { + return true; + } + if(!isset($_GET['lazysign'])) { - if('yes' === $this->core()->getOptions('browser_debug', 'no')) - { - return true; - } - $warning = __('Authorization key verification failed. 1C did not send the name of the lazy signature.', 'wc1c-main'); $this->core()->log()->warning($warning); From 0deae71bf7d586744de8164798971c265c62d086 Mon Sep 17 00:00:00 2001 From: Frescoref Date: Fri, 23 Jun 2023 22:03:38 +0300 Subject: [PATCH 3/3] Fix: more --- Admin.php | 17 ++++++++++++- Core.php | 75 ++++++++++++++++++++++++++++++++++--------------------- 2 files changed, 63 insertions(+), 29 deletions(-) diff --git a/Admin.php b/Admin.php index 5c31bfd..f601146 100644 --- a/Admin.php +++ b/Admin.php @@ -462,7 +462,7 @@ public function configurationsFieldsProductsWithCharacteristics(array $fields): [ 'title' => __('Using global attributes for products', 'wc1c-main'), 'type' => 'checkbox', - 'label' => __('Check the box if you want to enable this feature. Disabled by default.', 'wc1c-main'), + 'label' => __('Check the box if you want to enable this feature. Enabled by default.', 'wc1c-main'), 'description' => sprintf ( '%s

%s', @@ -472,6 +472,21 @@ public function configurationsFieldsProductsWithCharacteristics(array $fields): 'default' => 'yes' ]; + $fields['products_with_characteristics_simple'] = + [ + 'title' => __('Create simple products from features', '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', + __('Sometimes 1C does not provide complete information for creating variable products in WooCommerce.', 'wc1c-main'), + __('The option allows you to enable the creation of simple products according to the characteristics of the item from 1C.', 'wc1c-main'), + __('As a result, it turns out like this: a characteristic in 1C is equal to a simple product in WooCommerce.', 'wc1c-main') + ), + 'default' => 'no' + ]; + return $fields; } diff --git a/Core.php b/Core.php index 1e6164b..6dbdc08 100644 --- a/Core.php +++ b/Core.php @@ -355,7 +355,7 @@ public function processingClassifier(Reader $reader) if(!$classifier instanceof ClassifierDataContract) { - $this->log()->debug(__('Classifier !instanceof ClassifierDataContract. Skip processing.', 'wc1c-main'), ['data' => $classifier]); + $this->log()->debug(__('Classifier !instanceof ClassifierDataContract. Processing skipped.', 'wc1c-main'), ['data' => $classifier]); return; } @@ -1189,7 +1189,7 @@ public function processingCatalog(Reader $reader) if(!$product instanceof ProductDataContract) { - $this->log()->warning(__('Product !instanceof ProductDataContract. Skip processing.', 'wc1c-main'), ['data' => $product]); + $this->log()->warning(__('Product !instanceof ProductDataContract. Processing skipped.', 'wc1c-main'), ['data' => $product]); return; } @@ -3398,24 +3398,36 @@ public function processingProductsItem(ProductDataContract $external_product, Re */ if($external_product->hasCharacteristicId()) { - $this->log()->notice(__('The product contains the characteristics.', 'wc1c-main')); // todo: реализация - return; + $this->log()->notice(__('The product contains the characteristics. Parent product is not found.', 'wc1c-main')); + + if('yes' !== $this->getOptions('products_with_characteristics_simple', 'no')) + { + $this->log()->info(__('Creating simple products by characteristics is disabled in the settings. Processing skipped.', 'wc1c-main')); + return; + } + + $this->log()->info(__('The product is simple by characteristics. Creating.', 'wc1c-main')); } else { - $this->log()->info(__('The product is simple. Create.', 'wc1c-main')); + $this->log()->info(__('The product is simple. Creating.', 'wc1c-main')); + } - /** - * Создание простого продукта с заполнением данных - * - * @var $internal_product ProductContract - */ - $internal_product = new SimpleProduct(); + /** + * Создание простого продукта с заполнением данных + * + * @var $internal_product ProductContract + */ + $internal_product = new SimpleProduct(); - $internal_product->setSchemaId($this->getId()); - $internal_product->setConfigurationId($this->configuration()->getId()); - $internal_product->setExternalId($external_product->getId()); - } + $internal_product->setSchemaId($this->getId()); + $internal_product->setConfigurationId($this->configuration()->getId()); + $internal_product->setExternalId($external_product->getId()); + + if($external_product->hasCharacteristicId()) + { + $internal_product->setExternalCharacteristicId($external_product->getCharacteristicId()); + } /** * Назначение данных создаваемого продукта по внешним алгоритмам перед сохранением @@ -3434,6 +3446,8 @@ public function processingProductsItem(ProductDataContract $external_product, Re $internal_product = $this->setProductTimes($internal_product); + $internal_product->update_meta_data('_wc1c_time_catalog', (int)$this->configuration()->getMeta('_catalog_full_time')); + try { $id = $internal_product->save(); @@ -3539,6 +3553,8 @@ public function processingProductsItem(ProductDataContract $external_product, Re $update_product = $this->setProductTimes($update_product); + $update_product->update_meta_data('_wc1c_time_catalog', (int)$this->configuration()->getMeta('_catalog_full_time')); + try { $update_product->save(); @@ -3633,7 +3649,7 @@ public function processingOffersItem(ProductDataContract $external_offer, Reader $internal_parent_offer_id = 0; if(!empty($external_offer->getCharacteristicId())) { - $internal_parent_offer_id = $product_factory->findIdsByExternalIdAndCharacteristicId($external_offer->getId(), ''); + $internal_parent_offer_id = $product_factory->findIdsByExternalIdAndCharacteristicId($external_offer->getId(), $external_offer->getCharacteristicId()); if(is_array($internal_parent_offer_id)) // todo: обработка нескольких? { @@ -3644,24 +3660,27 @@ public function processingOffersItem(ProductDataContract $external_offer, Reader /* * Родительский продукт не найден */ - if(0 === $internal_parent_offer_id) + if(empty($internal_parent_offer_id)) { $this->log()->notice(__('Product parent not found. Offer update skipped.', 'wc1c-main'), ['offer' => $external_offer]); return; } - $internal_product_parent = $product_factory->getProduct($internal_parent_offer_id); + if($internal_parent_offer_id !== $internal_offer_id) + { + $internal_product_parent = $product_factory->getProduct($internal_parent_offer_id); - /* - * Продукт не вариативный, превращаем его в вариативный - */ - if(!$internal_product_parent instanceof VariableProduct) - { - $this->log()->debug(__('Changing the product type to variable.', 'wc1c-main'), ['product_id' => $internal_parent_offer_id]); + /* + * Продукт не вариативный, превращаем его в вариативный + */ + if(!$internal_product_parent instanceof VariableProduct) + { + $this->log()->debug(__('Changing the product type to variable.', 'wc1c-main'), ['product_id' => $internal_parent_offer_id]); - $internal_product_parent = new VariableProduct($internal_parent_offer_id); - $internal_parent_offer_id = $internal_product_parent->save(); - } + $internal_product_parent = new VariableProduct($internal_parent_offer_id); + $internal_parent_offer_id = $internal_product_parent->save(); + } + } } /* @@ -3865,7 +3884,7 @@ public function processingOffers(Reader $reader) if(!$offer instanceof ProductDataContract) { - $this->log()->warning(__('Offer !instanceof ProductDataContract. Skip processing.', 'wc1c-main'), ['data' => $offer]); + $this->log()->warning(__('Offer !instanceof ProductDataContract. Processing skipped.', 'wc1c-main'), ['data' => $offer]); return; }