Skip to content
This repository has been archived by the owner on Apr 29, 2019. It is now read-only.

Magento_ImportExport: Running multiple product imports after each other can create faulty duplicate sku's #47

Open
piotrekkaminski opened this issue Nov 6, 2017 · 1 comment

Comments

@piotrekkaminski
Copy link
Contributor

From @koenner01 on January 23, 2017 12:57

When running multiple product imports through the importExport module of Magento, duplicate sku's can be generated during the import process because of the SkuProcessor model being used as a singleton.

Preconditions

  1. MG 2.1.2 or MG 2.1.3
  2. PHP7.0

Steps to reproduce

  1. create a Magento\ImportExport\Model\Import model in a loop
  2. run multiple product imports with more than 50 products in the data with behaviour 'append'
    As a test we are running an import with 100 products without their relations (related, upsell, crosssell) and then an import with the same 100 sku's but only with their relations.

Expected result

  1. 100 products should've been created in Magento

Actual result

  1. More than 100 products are created in Magento (double sku's were created!)

I've traced this issue back to Magento\CatalogImportExport\Model\Import\Product instantiating it's skuProcessor through the constructor as a singleton. Because it is a singleton, the oldSkus on the skuProcessor object aren't being reloaded in between the imports.

Currently we are working around this by instantiating the skuProcessor in our custom Model constructor

protected $skuProcessor;

public function __construct(
    ...
    \Magento\CatalogImportExport\Model\Import\Product\SkuProcessor $skuProcessor
) {
    ...
    $this->skuProcessor = $skuProcessor;
    ...
}

And then in the for loop we reload the oldSkus by doing

for (...) {
    $this->skuProcessor->reloadOldSkus();
    ...
    $importerModel = $this->importerModelFactory->create();
    ...
}

Because the skuProcessor is being treated as a singleton, the oldSku's in Magento\CatalogImportExport\Model\Import\Product will be correct

Copied from original issue: magento/magento2#8235

@gustavogravina
Copy link

I'm having the same issue on 2.2.2
I cannot update current SKUs. I only get duplicated SKUs.
Thanks.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants