Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot create shipment: Source item not found by source code: default and sku: [my-sku custom option] #2043

Closed
adarshkhatri opened this issue Feb 14, 2019 · 17 comments
Assignees
Milestone

Comments

@adarshkhatri
Copy link

adarshkhatri commented Feb 14, 2019

Preconditions (*)

  1. Magento Open Source 2.3
  2. Inventory Source Enabled (By default? cannot disable)
  3. https://imgur.com/uFZE5Y4

Steps to reproduce (*)

  1. Config product with Custom Options
  2. Place order from frontend
  3. Create Invoice
  4. Create Shipment

Expected result (*)

  1. It should create shipment

Actual result (*)

  1. Source item not found by source code: default and sku: sols-imp-adult-t-shirt-Black-Full Colour - position 2.
  2. No shipment created. No logs

PS I had reported this in magento/magento2#21219, but they advised to report here.

@maghamed maghamed added this to the MSI Part III milestone Feb 18, 2019
@smoskaluk
Copy link

smoskaluk commented Feb 18, 2019

Hi @adarshkhatri! Thank you for your report. I could not reproduce this issue, In my case I was able to create invoice and shipment without problems.

image

image

May you please provide more information about your issue. Did you make new install of Magento 2.3.0 with MSI or you did upgrade from previous version of Magento? What version of MSI you have installed? Was it installation via composer or from git repository? May please give all details of custom option you created for your product as well.

@adarshkhatri
Copy link
Author

Hi @smoskaluk

Thanks for reply. I had installed clean M2 2.3.0.

Product has to be configurable with custom option.

Product detail: https://imgur.com/a/rCOasA9

Hope this helps.

Thanks.

@maghamed
Copy link
Contributor

This looks like a duplicate of issue #1912

Btw we have a pull request fixing this issue, which was not validated for other product types - #2012

@adarshkhatri could you please check that fix in #2012 works for you?

Btw @smoskaluk is it really not reproducible for you? As the initial ticket created back to November 2018
Or you checked on Simple Product?

@adarshkhatri
Copy link
Author

And after applying above #2012, it now gives similar exception:

Source item not found by source code: Store and sku: sols-imp-adult-t-shirt-Black.

@smoskaluk
Copy link

@maghamed yes, from initial description I didn't understand that issue about configurable product and tried to reproduce with simple product with custom option.
With configurable product it reproducing, and as you already mentioned, it duplicate #1912.

@smoskaluk
Copy link

Hi @adarshkhatri ! I've tried fix in PR #2012 , and it was working well.

image
I wonder, may be it didn't work in your case because you have 0 quantity for your child products of configurable product? Please recheck

image

@adarshkhatri
Copy link
Author

@smoskaluk

They are zero because I am not managing stocks.

@VitaliyBoyko
Copy link
Contributor

@smoskaluk @maghamed
As far as I have understood from comments, this issue is not a duplicate of #1912.
We need to disable source selection when manage stock is off on the shipment.
Right?

@VitaliyBoyko
Copy link
Contributor

VitaliyBoyko commented Feb 20, 2019

@adarshkhatri what the reason to use multiple sources if managing stock is disabled?

@adarshkhatri
Copy link
Author

@VitaliyBoyko

Exactly, I am not managing stock but MSI is enabled by default.

Also, I might want to manage stock for specific item in future. In this case I would still want to have MSI enabled.

PS, I haven't created any source, there is just 1 available ie. "default".

Thanks.

@adarshkhatri
Copy link
Author

It looks like there is check in place:

        if (!$stockItemConfiguration->isManageStock()) {
            //We don't need to Manage Stock
            continue;
        }

https://github.com/magento-engcom/msi/blob/2.3-develop/app/code/Magento/InventorySourceDeductionApi/Model/SourceDeductionService.php#L76

I think solution would be to find the list by product id instead of sku. I see that when creating order Magento adds Custom Option to the configurable item, when it has custom option

For example:
Config item's sku: Config Item with Custom Option
Child Item: Config Item with Custom Option-Black-First

But when order created:
db

Because of this, system will never find the product.

   //namespace Magento\InventorySourceDeductionApi\Model\GetSourceItemBySourceCodeAndSku

    $searchCriteria = $this->searchCriteriaBuilder
        ->addFilter(SourceItemInterface::SOURCE_CODE, $sourceCode) //default
        ->addFilter(SourceItemInterface::SKU, $sku) //Config Item with Custom Option-Black-First Custom Option
        ->create();
    $sourceItemsResult = $this->sourceItemRepository->getList($searchCriteria);

I think, finding the source item by product id will always find the product if it exist.

@adarshkhatri
Copy link
Author

Also on my further investigation, I found this:

class Magento\InventorySourceDeductionApi\Model\SourceDeductionService

/**
     * @inheritdoc
     */
    public function execute(SourceDeductionRequestInterface $sourceDeductionRequest): void
    {
        $sourceItems = [];
        $sourceCode = $sourceDeductionRequest->getSourceCode();
        $salesChannel = $sourceDeductionRequest->getSalesChannel();

        $stockId = $this->getStockBySalesChannel->execute($salesChannel)->getStockId();
        foreach ($sourceDeductionRequest->getItems() as $item) {
            $itemSku = $item->getSku();
            $qty = $item->getQty();
            $stockItemConfiguration = $this->getStockItemConfiguration->execute(
                $itemSku,
                $stockId
            );

            if (!$stockItemConfiguration->isManageStock()) {
                //We don't need to Manage Stock
                continue;
            }

            $sourceItem = $this->getSourceItemBySourceCodeAndSku->execute($sourceCode, $itemSku);
            if (($sourceItem->getQuantity() - $qty) >= 0) {
                $sourceItem->setQuantity($sourceItem->getQuantity() - $qty);
                $sourceItems[] = $sourceItem;
            } else {
                throw new LocalizedException(
                    __('Not all of your products are available in the requested quantity.')
                );
            }
        }

        if (!empty($sourceItems)) {
            $this->sourceItemsSave->execute($sourceItems);
        }
    }

$stockItemConfiguration->isManageStock() for config item with custom option always returns 1. I confirm, I am not managing stock for child and parent.

I also confirm, in my different instance, I have not created any STOCK SOURCE yet.
Manage Source: Default
Manage Stock: Default Stock

sourcce
stock

@VitaliyBoyko
Copy link
Contributor

Fixed in 2.3 develop

@teodorpav
Copy link

teodorpav commented May 3, 2019

I have the same issue on 2.3.1 with simple product without any custom options. The issue is when the products are imported but 'Salable Quantity' is 0. If you Edit/Save the product the issue will be fixed.

@avoelkl
Copy link

avoelkl commented Jun 21, 2019

I can confirm I just encountered the same issue as @teodorpav above with Magento Open Source 2.3.1 and imported products. Saving the product in the backend solves the issue

@tschirmer
Copy link

We had this happen when a sku was put in , ordered, then changed before shipping. The shipment then tries to find an skus that is no longer being indexed (and nor should it be). The index would be far better off running on product entity_ids so this kind of this doesn't happen.

@tschirmer
Copy link

This has happened on our 2.3.6-p1 version with the latest msi installed.

The best solution we've found is to block out the sku field on edit, so it's treated like an id that can't be edited.

This also doesn't work well if skus have spaces in them

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

No branches or pull requests

7 participants