Skip to content

Commit

Permalink
Fix: more
Browse files Browse the repository at this point in the history
  • Loading branch information
frescoref committed Jun 23, 2023
1 parent b1f3d5c commit 0deae71
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 29 deletions.
17 changes: 16 additions & 1 deletion Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<br /><hr>%s',
Expand All @@ -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<br /><hr>%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;
}

Expand Down
75 changes: 47 additions & 28 deletions Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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());
}

/**
* Назначение данных создаваемого продукта по внешним алгоритмам перед сохранением
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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: обработка нескольких?
{
Expand All @@ -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();
}
}
}

/*
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 0deae71

Please sign in to comment.