magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.57k stars 9.32k forks source link

inventory_source_item sku not updating when user updates product SKU #39335

Open Swannyj opened 2 weeks ago

Swannyj commented 2 weeks ago

Preconditions and environment

Steps to reproduce

  1. Create a Product in the CMS. Add a SKU (for example 4201503002/size38/bleu fonce) and assign a stock source against it

  2. Save the Product

  3. Change the Product SKU (for example 4201503002/size38/bleu foncé)

  4. Save

  5. Navigate to the storefront

  6. Add this product to your basket and checkout

  7. In the CMS go to Sales/Orders and find the order

  8. You should see an order item with the updated sku (4201503002/size38/bleu foncé)

  9. Click 'Ship'

Expected result

The admin user should be able to click ship and progress through the order journey.

Actual result

The user is presented with the following error

Warning: Undefined array key "4201503002/size38/bleu fonce" in /var/www/website/vendor/magento/module-inventory-source-selection-api/Model/Algorithms/Result/GetDefaultSortedSourcesResult.php on line 140

Additional information

Looking through the execute function in GetDefaultSortedSourcesResult.php, it seems that the code retrieves a list of items in the order

        foreach ($inventoryRequest->getItems() as $item) {
            $normalizedSku = $this->normalizeSku($item->getSku());
            $itemsTdDeliver[$normalizedSku] = $item->getQty();
        }

        \Magento\Framework\App\ObjectManager::getInstance()->get('Psr\Log\LoggerInterface')->info("Items to Deliver: ");
        \Magento\Framework\App\ObjectManager::getInstance()->get('Psr\Log\LoggerInterface')->info(print_r(array_keys($itemsTdDeliver),true));

I can see the below in my debug.log


[2024-11-06T12:12:46.347503+00:00] main.INFO: Items to Deliver:  [] []
[2024-11-06T12:12:46.347769+00:00] main.INFO: Array
(
    [0] => 4201503002/size38/bleu foncé
)

After this, the code calls the execute function in GetInStockSourceItemsBySkusAndSortedSource

I have added the below logging in this function:

        $items = $this->sourceItemRepository->getList($searchCriteria)->getItems();

        \Magento\Framework\App\ObjectManager::getInstance()->get('Psr\Log\LoggerInterface')->info("Items after source item repo search");
        \Magento\Framework\App\ObjectManager::getInstance()->get('Psr\Log\LoggerInterface')->info(print_r(array_keys($items), true));

which prints the following to my debug.log

[2024-11-06T13:07:08.591215+00:00] main.INFO: Items after source item repo search [] []
[2024-11-06T13:07:08.591596+00:00] main.INFO: Array
(
    [0] => 7161324
)
 [] []

The above ID returns the following from the database 7161324 and back inside the execute function in GetDefaultSortedSourcesResult.php this ID returns the following from the database when it is looping through the $sourceItems

 foreach ($sourceItems as $sourceItem) {
            \Magento\Framework\App\ObjectManager::getInstance()->get('Psr\Log\LoggerInterface')->info("Source Item SKU: ");
            \Magento\Framework\App\ObjectManager::getInstance()->get('Psr\Log\LoggerInterface')->info(print_r($sourceItem->getSku(),true));
[2024-11-06T13:07:08.592511+00:00] main.INFO: Source Item SKU:  [] []
[2024-11-06T13:07:08.592965+00:00] main.INFO: 4201503002/Size38/Bleu Fonce [] []

inventory_source_item table image

catalog_product_entity table image


IMPORTANT The code uses the inventory_source_item sku and searches the the variable $itemsTdDeliver for this sku however this array conatins the product sku and so returns the undefined array key error.

Release note

No response

Triage and priority

m2-assistant[bot] commented 2 weeks ago

Hi @Swannyj. Thank you for your report. To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce.

m2-assistant[bot] commented 2 weeks ago

Hi @engcom-Bravo. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

engcom-Bravo commented 2 weeks ago

Hi @Swannyj,

Thanks for your reporting and collaboration.

We have verified the issue in Latest 2.4-develop instance and the issue is reproducible.Kindly refer the attached video.

https://github.com/user-attachments/assets/8b2802db-f807-4cc2-8014-713ebd4def48

When Clicking shipping we are getting the error Following products with requested skus were not found: 4201503002/size38/bleu fonce

Hence Confirming the issue.

Thanks.

github-jira-sync-bot commented 2 weeks ago

:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-13319 is successfully created for this GitHub issue.

m2-assistant[bot] commented 2 weeks ago

:white_check_mark: Confirmed by @engcom-Bravo. Thank you for verifying the issue.
Issue Available: @engcom-Bravo, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.