Skip to content

Commit

Permalink
Merge pull request #21 from wc1c/dev
Browse files Browse the repository at this point in the history
Dev 0.13.0
  • Loading branch information
frescoref authored Jun 23, 2023
2 parents 8b705b7 + 0deae71 commit 6401142
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 35 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
77 changes: 48 additions & 29 deletions Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down 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
10 changes: 5 additions & 5 deletions Receiver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 6401142

Please sign in to comment.