Skip to content
This repository has been archived by the owner on Oct 18, 2023. It is now read-only.

Commit

Permalink
Adding consolidated summary of product import rather than loggging on…
Browse files Browse the repository at this point in the history
… incidents.
  • Loading branch information
piyuesh23 committed Aug 28, 2018
1 parent f2f2d5d commit ebe6ba4
Showing 1 changed file with 41 additions and 9 deletions.
50 changes: 41 additions & 9 deletions modules/sku/src/ProductManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ class ProductManager implements ProductManagerInterface {
private $deleted;
private $created;
private $updated;

private $failed_skus;
private $created_skus;
private $ignored_skus;
private $deleted_skus;
private $updated_skus;
private $debugDir;

/**
Expand Down Expand Up @@ -286,6 +290,7 @@ public function synchronizeProducts(array $products = [], $storeId = '') {
'@store' => $product['store_id'],
'@langcode' => $langcode,
]);
$this->ignored_skus[] = $product['sku'] . '(Langcode is empty for store_id:' . $product['store_id'] . '.)';
$this->ignored++;
// Release the lock on this sku.
$lock->release($lock_key);
Expand Down Expand Up @@ -313,7 +318,7 @@ public function synchronizeProducts(array $products = [], $storeId = '') {

if (!isset($product['type'])) {
$message = "Product type must be defined. " . $product['sku'] . " was not synchronized.";
$this->logger->error($message);
$this->failed_skus[] = $product['sku'] . '(Missing Product Type)';
$this->failed++;
// Release the lock on this sku.
$lock->release($lock_key);
Expand All @@ -329,7 +334,7 @@ public function synchronizeProducts(array $products = [], $storeId = '') {

if (!$has_bundle) {
$message = "Product type " . $product['type'] . " is not supported yet. " . $product['sku'] . " was not synchronized.";
$this->logger->error($message);
$this->ignored_skus[] = $product['sku'] . '(Product type not supported yet.' . $product['type'] . ')';
$this->ignored++;
// Release the lock on this sku.
$lock->release($lock_key);
Expand All @@ -338,7 +343,7 @@ public function synchronizeProducts(array $products = [], $storeId = '') {
}

if (!isset($product['sku']) || !strlen($product['sku'])) {
$this->logger->error('Invalid or empty product SKU.');
$this->ignored_skus[] = $product['sku'] . '(Invalid or empty product SKU.)';
$this->ignored++;
// Release the lock on this sku.
$lock->release($lock_key);
Expand All @@ -350,10 +355,11 @@ public function synchronizeProducts(array $products = [], $storeId = '') {
// @TODO(mirom): Call validation function by $product['type'].
if ($product['type'] == 'configurable' && empty($product['extension']['configurable_product_options'])) {
$productToString = print_r($product, TRUE);
$this->logger->error('Empty configurable options for SKU: @sku, Details: @deets', [
$this->debugLogger('Empty configurable options for SKU: @sku, Details: @deets', [
'@sku' => $product['sku'],
'@deets' => $productToString,
]);
$this->ignored_skus[] = $product['sku'] . '(Empty configurable options for SKU.)';
$this->ignored++;
// Release the lock on this sku.
$lock->release($lock_key);
Expand All @@ -366,7 +372,7 @@ public function synchronizeProducts(array $products = [], $storeId = '') {
$sku_ids = $query->execute();

if (count($sku_ids) > 1) {
$this->logger->error('Duplicate product SKU @sku found.', ['@sku' => $product['sku']]);
$this->failed_skus[] = $product['sku'] . '(Duplicate product SKU found.)';
$this->failed++;
// Release the lock on this sku.
$lock->release($lock_key);
Expand All @@ -388,6 +394,7 @@ public function synchronizeProducts(array $products = [], $storeId = '') {
$node = $plugin->getDisplayNode($sku, FALSE, TRUE);
if (empty($node)) {
$node = $this->createDisplayNode($product, $langcode);
$this->created_skus[] = $product['sku'];
$this->created++;
}
elseif ($node->hasTranslationChanges()) {
Expand Down Expand Up @@ -461,6 +468,30 @@ public function synchronizeProducts(array $products = [], $storeId = '') {
$lock_key = NULL;
}

// Log product import summary.
if (!empty($this->created_skus)) {
$this->logger->info('Created SKUs: @created_skus', ['@created_skus' => implode(',', $this->created_skus)]);
}

if (!empty($this->deleted_skus)) {
$this->logger->info('Deleted SKUs: @deleted_skus', ['@deleted_skus' => implode(',', $this->deleted_skus)])
}

if (!empty($this->updated_skus)) {
$this->logger->info('Updated SKUs: @updated_skus', ['@updated_skus' => implode(',', $this->updated_skus)])
}

if (!empty($this->failed_skus)) {
$this->logger->error('Failed importing SKUs: @failed_skus', ['@failed_skus' => implode(',', $this->failed_skus)]);
}

if (!empty($this->ignored_skus)) {
$this->logger->error('Ignored importing SKUs: @ignored_skus', ['@ignored_skus' => implode(',', $this->ignored_skus)])
}




return [
'success' => !$this->failed && ($this->created || $this->updated || $this->ignored || $this->deleted),
'created' => $this->created,
Expand Down Expand Up @@ -669,16 +700,18 @@ public function processSku(array $product, $langcode) {

// Delete the SKU.
$sku->delete();
$this->deleted_skus[] = $product['sku'];
$this->deleted++;
return NULL;
}

$this->logger->info('Updating product SKU @sku.', ['@sku' => $product['sku']]);
$this->updated_skus[] = $product['sku'];
$this->updated++;
}
else {
if ($product['status'] != 1 && $this->configFactory->get('acm.connector')->get('delete_disabled_skus')) {
$this->logger->info('Not creating disabled SKU in system: @sku.', ['@sku' => $product['sku']]);
$this->ignored_skus[] = $product['sku'] . '(Disabled SKU).';
$this->ignored++;
return NULL;
}
Expand All @@ -689,8 +722,7 @@ public function processSku(array $product, $langcode) {
'langcode' => $langcode,
]);

$this->logger->info('Creating product SKU @sku.', ['@sku' => $product['sku']]);

$this->crearted_skus[] = $product['sku'];
$this->created++;
}

Expand Down

0 comments on commit ebe6ba4

Please sign in to comment.