0

It's been two weeks since I'm facing Registry key "movement_data" already exists error while importing a CSV file greater than 100 records. My Entity type is Products and, import behavior is Add/Update. There wasn't any problem before and, I don't know how to debug this error or where I should look for the solution. I'd be appreciated for your help.

Magento ver. 2.3.5-p2

PHP 7.2.24 enter image description here

3
  • There seems to be error in your csv please check the csv and reimport it.
    – Asssd
    Oct 26, 2021 at 6:23
  • Download the full report show on above screen and then check is there any error there? Oct 26, 2021 at 6:27
  • csv file is ok, I've done this before with this csv and also full report error is not generated, i can't find it Oct 26, 2021 at 7:18

2 Answers 2

2

The problem is that your code is trying to overwrite a registry value, and this causes an error in Magento. Look for every instance in your codebase where register('movement_data') exists (both single and double quotes). You will probably find that there are multiple instances.

Before you can overwrite 'movement_data', you have to unset the value. Ex:

$registry->unregister('movement_data');
$registry->register('movement_data', $yourDataGoesHere);

EDIT:

A quick search shows that this 'movement_data' registry key may be from a module called kiwicommerce/magento2-inventory-log. Do you have that installed? If so, you can see that each import batch fires the 'catalog_product_import_bunch_save_after' event that runs an observer method sets that registry key again, trying to overwrite the previous: $this->registry->register(InventoryLogHelper::MOVEMENT_DATA, $data); (see the file \KiwiCommerce\InventoryLog\Observer\AfterImportProductData::execute). This module was improperly coded because if the batches are 100 each, then it will try to set that registry key again without unsetting it, leading to an error.

You may want to edit that observer method to do the following:

    /**
     * Insert inventory log for stock item
     * @param EventObserver $observer
     */
    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        if ($this->helper->isModuleEnabled()) {
            $this->import = $observer->getEvent()->getAdapter();
            if ($products = $observer->getEvent()->getBunch()) {
                $data = [];
                foreach ($products as $product) {
                    $newSku = $this->import->getNewSku($product['sku']);
                    if (!empty($newSku) && isset($newSku['entity_id'])) {
                        $stockItem = $this->movementResourceModel->getStockItemByProduct($newSku['entity_id']);
                        $data[$newSku['entity_id']] = $stockItem;
                    }
                }
                ## BEGIN EDIT: Unset value if it has been previously set
                if($this->registry->registry(InventoryLogHelper::MOVEMENT_DATA)){
                    $this->registry->unregister(InventoryLogHelper::MOVEMENT_DATA);
                }
                ## END EDIT
                $this->registry->register(InventoryLogHelper::MOVEMENT_DATA, $data);
            }
        }

If you have that module installed, either try disabling it or modify the code as shown above.

3
  • where can i find this ?? it's a Magento default import functionality Oct 28, 2021 at 6:48
  • @MahdiAlikhani - I updated my answer. Oct 29, 2021 at 13:32
  • you are genius!!! thank you so much!! Oct 29, 2021 at 18:52
0

Don't Import 100 values at the time, first of all you must test data with one row instead of 100 rows. Create a test csv and add only one row than import and check what happens than you process further.

Sometimes csv file is ok but could'n be imported due to ms office or csv creating tool version

1
  • I don't have any problem with less than 100 records, only with +100 records. Oct 28, 2021 at 6:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.