From 69b195f025e393d40e1f592f11e40f8e31893377 Mon Sep 17 00:00:00 2001 From: Maikel Koek Date: Tue, 15 Aug 2023 12:02:18 +0200 Subject: [PATCH 1/3] refactor(TEN-661): prettier on abstract class import profile --- src/Model/ImportProfile.php | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/Model/ImportProfile.php b/src/Model/ImportProfile.php index 3f77a8a..3a5bc4f 100644 --- a/src/Model/ImportProfile.php +++ b/src/Model/ImportProfile.php @@ -65,7 +65,6 @@ public function __construct( $this->log = $log; } - /** * Run the actual import * @@ -85,12 +84,11 @@ public function run() $errors = $importer->processImport($items); $stopwatchEvent = $this->stopwatch->stop('importinstance'); - $output = (string) new Phrase( - '%1 items imported in %2 sec, %3 items / sec (%4mb used)', [ + $output = (string) new Phrase('%1 items imported in %2 sec, %3 items / sec (%4mb used)', [ count($items), round($stopwatchEvent->getDuration() / 1000, 1), round(count($items) / ($stopwatchEvent->getDuration() / 1000), 1), - round($stopwatchEvent->getMemory() / 1024 / 1024, 1) + round($stopwatchEvent->getMemory() / 1024 / 1024, 1), ]); $this->consoleOutput->writeln($output); @@ -135,17 +133,16 @@ private function getItemsMeasured() $items = $this->getItems(); $stopwatchEvent = $this->stopwatch->stop('profileinstance'); - if (! $stopwatchEvent->getDuration()) { + if (!$stopwatchEvent->getDuration()) { return $items; } - $output = (string) new Phrase('%1 items processed in %2 sec, %3 items / sec (%4mb used)', - [ - count($items), - round($stopwatchEvent->getDuration() / 1000, 1), - round(count($items) / ($stopwatchEvent->getDuration() / 1000), 1), - round($stopwatchEvent->getMemory() / 1024 / 1024, 1) - ]); + $output = (string) new Phrase('%1 items processed in %2 sec, %3 items / sec (%4mb used)', [ + count($items), + round($stopwatchEvent->getDuration() / 1000, 1), + round(count($items) / ($stopwatchEvent->getDuration() / 1000), 1), + round($stopwatchEvent->getMemory() / 1024 / 1024, 1), + ]); $this->consoleOutput->writeln($output); $this->log->info($output); @@ -153,7 +150,6 @@ private function getItemsMeasured() return $items; } - /** * Gets initialized object manager * - Loads the Admin space from the CLI @@ -170,7 +166,6 @@ private function getObjectManager() $omParams[\Magento\Store\Model\Store::CUSTOM_ENTRY_POINT_PARAM] = true; $this->objectManager = $this->objectManagerFactory->create($omParams); - $area = \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE; /** @var \Magento\Framework\App\State $appState */ $appState = $this->objectManager->get(\Magento\Framework\App\State::class); From efb7981b44ad48d7ace38c3dffc7a77a8e96f7b8 Mon Sep 17 00:00:00 2001 From: Maikel Koek Date: Tue, 15 Aug 2023 12:16:47 +0200 Subject: [PATCH 2/3] feat(TEN-661): store errors in import profile class --- src/Api/ImportProfileInterface.php | 7 +++++-- src/Model/ImportProfile.php | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Api/ImportProfileInterface.php b/src/Api/ImportProfileInterface.php index 72f4652..4cf5bbe 100644 --- a/src/Api/ImportProfileInterface.php +++ b/src/Api/ImportProfileInterface.php @@ -15,7 +15,6 @@ interface ImportProfileInterface */ public function getItems(); - /** * Array of the config values * @@ -23,7 +22,6 @@ public function getItems(); */ public function getConfig(); - /** * Run the import * @@ -35,4 +33,9 @@ public function run(); * @return \Exception */ public function getException(); + + /** + * @return string + */ + public function getErrors(); } diff --git a/src/Model/ImportProfile.php b/src/Model/ImportProfile.php index 3a5bc4f..67e5159 100644 --- a/src/Model/ImportProfile.php +++ b/src/Model/ImportProfile.php @@ -47,6 +47,11 @@ abstract class ImportProfile implements ImportProfileInterface */ private $exception; + /** + * @var ?string + */ + private $errors = null; + /** * @param ObjectManagerFactory $objectManagerFactory * @param Stopwatch $stopwatch @@ -97,6 +102,8 @@ public function run() $this->consoleOutput->writeln("$errors"); $this->log->error($errors); + $this->errors = $errors; + return \Magento\Framework\Console\Cli::RETURN_SUCCESS; } catch (\Exception $e) { $this->consoleOutput->writeln($e->getMessage()); @@ -120,6 +127,14 @@ public function getException(): \Exception return $this->exception; } + /** + * @return string + */ + public function getErrors() + { + return $this->errors; + } + /** * Get all items that need to be imported * From 5de15c302cc1028ac565fb6da34e96a7f96dfbe1 Mon Sep 17 00:00:00 2001 From: Maikel Koek Date: Tue, 29 Aug 2023 12:22:00 +0200 Subject: [PATCH 3/3] fix(TEN-661): use strtolower when searching existing skus _oldSkus is filled with lowercase skus, so we have to use strtolower. See \Magento\CatalogImportExport\Model\Import\Product\SkuProcessor::_getSkus --- src/Rewrite/ImportExport/Import/Product.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Rewrite/ImportExport/Import/Product.php b/src/Rewrite/ImportExport/Import/Product.php index c406255..91487d9 100644 --- a/src/Rewrite/ImportExport/Import/Product.php +++ b/src/Rewrite/ImportExport/Import/Product.php @@ -505,7 +505,7 @@ protected function _saveProducts() $rowData = $productTypeModel->prepareAttributesWithDefaultValueForSave( $rowData, - !isset($this->_oldSku[$rowSku]) + !isset($this->_oldSku[strtolower($rowSku)]) ); $product = $this->_proxyProdFactory->create(['data' => $rowData]); @@ -551,7 +551,7 @@ protected function _saveProducts() } elseif (self::SCOPE_STORE == $attribute->getIsGlobal()) { $storeIds = [$rowStore]; } - if (!isset($this->_oldSku[$rowSku])) { + if (!isset($this->_oldSku[strtolower($rowSku)])) { $storeIds[] = 0; } } @@ -597,7 +597,7 @@ protected function _saveProducts() public function skipUpdatingAttribute($rowSku, $attrCode) { - return isset($this->_oldSku[$rowSku]) && \array_key_exists(self::SKIP_ATTRIBUTES_WHEN_UPDATING, $this->_parameters) && \array_key_exists($attrCode, $this->_parameters[self::SKIP_ATTRIBUTES_WHEN_UPDATING]); + return isset($this->_oldSku[strtolower($rowSku)]) && \array_key_exists(self::SKIP_ATTRIBUTES_WHEN_UPDATING, $this->_parameters) && \array_key_exists($attrCode, $this->_parameters[self::SKIP_ATTRIBUTES_WHEN_UPDATING]); } /** @@ -637,7 +637,7 @@ public function validateRow(array $rowData, $rowNum) $rowScope = $this->getRowScope($rowData); // BEHAVIOR_DELETE use specific validation logic if (Import::BEHAVIOR_DELETE == $this->getBehavior()) { - if (self::SCOPE_DEFAULT == $rowScope && !isset($this->_oldSku[$rowData[self::COL_SKU]])) { + if (self::SCOPE_DEFAULT == $rowScope && !isset($this->_oldSku[strtolower($rowData[self::COL_SKU])])) { $this->addRowError(ValidatorInterface::ERROR_SKU_NOT_FOUND_FOR_DELETE, $rowNum); return false; }