Custom Stock Handling Issue: The requested SKU is not assigned to the given stock
error for Product with 'Manage Stock = No' #3407
Description
Preconditions
- Tested on fresh Magento community edition
2.4.2-p2
and2.4.7-beta2
Steps to reproduce
- Create a new Stock and set it as the default for the Main website.
- Create a simple or downloadable product.
- In the product settings, go to Advanced Inventory and set 'Manage Stock' to 'No'.
- Save the product.
- Open the product page on the frontend.
Expected result
- The product page should open without any errors, allowing the product to be viewed and purchased. No exceptions or stock-related errors should occur since 'Manage Stock' is set to 'No'.
Actual result
- When attempting to open the product page, an error occurs:
Exception #0 (Magento\InventoryConfigurationApi\Exception\SkuIsNotAssignedToStockException): The requested SKU is not assigned to the given stock.
Exception stacktrace
1 exception(s): Exception #0 (Magento\InventoryConfigurationApi\Exception\SkuIsNotAssignedToStockException): The requested sku is not assigned to given stock. #1 Magento\InventoryConfiguration\Model\GetStockItemConfiguration\Interceptor->___callParent() called at [vendor/magento/framework/Interception/Interceptor.php:138] #2 Magento\InventoryConfiguration\Model\GetStockItemConfiguration\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/framework/Interception/Interceptor.php:153] #3 Magento\InventoryConfiguration\Model\GetStockItemConfiguration\Interceptor->___callPlugins() called at [generated/code/Magento/InventoryConfiguration/Model/GetStockItemConfiguration/Interceptor.php:23] #4 Magento\InventoryConfiguration\Model\GetStockItemConfiguration\Interceptor->execute() called at [vendor/magento/module-inventory-sales-frontend-ui/Plugin/Block/Stockqty/AbstractStockqtyPlugin.php:84] #5 Magento\InventorySalesFrontendUi\Plugin\Block\Stockqty\AbstractStockqtyPlugin->aroundIsMsgVisible() called at [vendor/magento/framework/Interception/Interceptor.php:135] #6 Magento\CatalogInventory\Block\Stockqty\DefaultStockqty\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/framework/Interception/Interceptor.php:153] #7 Magento\CatalogInventory\Block\Stockqty\DefaultStockqty\Interceptor->___callPlugins() called at [generated/code/Magento/CatalogInventory/Block/Stockqty/DefaultStockqty/Interceptor.php:77] #8 Magento\CatalogInventory\Block\Stockqty\DefaultStockqty\Interceptor->isMsgVisible() called at [vendor/magento/module-catalog-inventory/Block/Stockqty/DefaultStockqty.php:28] #9 Magento\CatalogInventory\Block\Stockqty\DefaultStockqty->_toHtml() called at [vendor/magento/framework/View/Element/AbstractBlock.php:1111] #10 Magento\Framework\View\Element\AbstractBlock->Magento\Framework\View\Element\{closure}() called at [vendor/magento/framework/View/Element/AbstractBlock.php:1115] #11 Magento\Framework\View\Element\AbstractBlock->_loadCache() called at [vendor/magento/framework/View/Element/AbstractBlock.php:675] #12 Magento\Framework\View\Element\AbstractBlock->toHtml() called at [generated/code/Magento/CatalogInventory/Block/Stockqty/DefaultStockqty/Interceptor.php:374] #13 Magento\CatalogInventory\Block\Stockqty\DefaultStockqty\Interceptor->toHtml() called at [vendor/magento/framework/View/Layout.php:578] #14 Magento\Framework\View\Layout->_renderBlock() called at [vendor/magento/framework/View/Layout.php:555] #15 Magento\Framework\View\Layout->renderNonCachedElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:149] #16 Magento\Framework\View\Layout\Interceptor->renderNonCachedElement() called at [vendor/magento/framework/View/Layout.php:510] #17 Magento\Framework\View\Layout->renderElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:140] #18 Magento\Framework\View\Layout\Interceptor->renderElement() called at [vendor/magento/framework/View/Layout.php:606] #19 Magento\Framework\View\Layout->_renderContainer() called at [vendor/magento/framework/View/Layout.php:557] #20 Magento\Framework\View\Layout->renderNonCachedElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:149] #21 Magento\Framework\View\Layout\Interceptor->renderNonCachedElement() called at [vendor/magento/framework/View/Layout.php:510] #22 Magento\Framework\View\Layout->renderElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:140] #23 Magento\Framework\View\Layout\Interceptor->renderElement() called at [vendor/magento/framework/View/Layout.php:606] #24 Magento\Framework\View\Layout->_renderContainer() called at [vendor/magento/framework/View/Layout.php:557] #25 Magento\Framework\View\Layout->renderNonCachedElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:149] #26 Magento\Framework\View\Layout\Interceptor->renderNonCachedElement() called at [vendor/magento/framework/View/Layout.php:510] #27 Magento\Framework\View\Layout->renderElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:140] #28 Magento\Framework\View\Layout\Interceptor->renderElement() called at [vendor/magento/framework/View/Layout.php:606] #29 Magento\Framework\View\Layout->_renderContainer() called at [vendor/magento/framework/View/Layout.php:557] #30 Magento\Framework\View\Layout->renderNonCachedElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:149] #31 Magento\Framework\View\Layout\Interceptor->renderNonCachedElement() called at [vendor/magento/framework/View/Layout.php:510] #32 Magento\Framework\View\Layout->renderElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:140] #33 Magento\Framework\View\Layout\Interceptor->renderElement() called at [vendor/magento/framework/View/Layout.php:606] #34 Magento\Framework\View\Layout->_renderContainer() called at [vendor/magento/framework/View/Layout.php:557] #35 Magento\Framework\View\Layout->renderNonCachedElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:149] #36 Magento\Framework\View\Layout\Interceptor->renderNonCachedElement() called at [vendor/magento/framework/View/Layout.php:510] #37 Magento\Framework\View\Layout->renderElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:140] #38 Magento\Framework\View\Layout\Interceptor->renderElement() called at [vendor/magento/framework/View/Layout.php:606] #39 Magento\Framework\View\Layout->_renderContainer() called at [vendor/magento/framework/View/Layout.php:557] #40 Magento\Framework\View\Layout->renderNonCachedElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:149] #41 Magento\Framework\View\Layout\Interceptor->renderNonCachedElement() called at [vendor/magento/framework/View/Layout.php:510] #42 Magento\Framework\View\Layout->renderElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:140] #43 Magento\Framework\View\Layout\Interceptor->renderElement() called at [vendor/magento/framework/View/Layout.php:606] #44 Magento\Framework\View\Layout->_renderContainer() called at [vendor/magento/framework/View/Layout.php:557] #45 Magento\Framework\View\Layout->renderNonCachedElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:149] #46 Magento\Framework\View\Layout\Interceptor->renderNonCachedElement() called at [vendor/magento/framework/View/Layout.php:510] #47 Magento\Framework\View\Layout->renderElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:140] #48 Magento\Framework\View\Layout\Interceptor->renderElement() called at [vendor/magento/framework/View/Layout.php:606] #49 Magento\Framework\View\Layout->_renderContainer() called at [vendor/magento/framework/View/Layout.php:557] #50 Magento\Framework\View\Layout->renderNonCachedElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:149] #51 Magento\Framework\View\Layout\Interceptor->renderNonCachedElement() called at [vendor/magento/framework/View/Layout.php:510] #52 Magento\Framework\View\Layout->renderElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:140] #53 Magento\Framework\View\Layout\Interceptor->renderElement() called at [vendor/magento/framework/View/Layout.php:606] #54 Magento\Framework\View\Layout->_renderContainer() called at [vendor/magento/framework/View/Layout.php:557] #55 Magento\Framework\View\Layout->renderNonCachedElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:149] #56 Magento\Framework\View\Layout\Interceptor->renderNonCachedElement() called at [vendor/magento/framework/View/Layout.php:510] #57 Magento\Framework\View\Layout->renderElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:140] #58 Magento\Framework\View\Layout\Interceptor->renderElement() called at [vendor/magento/framework/View/Layout.php:606] #59 Magento\Framework\View\Layout->_renderContainer() called at [vendor/magento/framework/View/Layout.php:557] #60 Magento\Framework\View\Layout->renderNonCachedElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:149] #61 Magento\Framework\View\Layout\Interceptor->renderNonCachedElement() called at [vendor/magento/framework/View/Layout.php:510] #62 Magento\Framework\View\Layout->renderElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:140] #63 Magento\Framework\View\Layout\Interceptor->renderElement() called at [vendor/magento/framework/View/Layout.php:606] #64 Magento\Framework\View\Layout->_renderContainer() called at [vendor/magento/framework/View/Layout.php:557] #65 Magento\Framework\View\Layout->renderNonCachedElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:149] #66 Magento\Framework\View\Layout\Interceptor->renderNonCachedElement() called at [vendor/magento/framework/View/Layout.php:510] #67 Magento\Framework\View\Layout->renderElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:140] #68 Magento\Framework\View\Layout\Interceptor->renderElement() called at [vendor/magento/framework/View/Layout.php:606] #69 Magento\Framework\View\Layout->_renderContainer() called at [vendor/magento/framework/View/Layout.php:557] #70 Magento\Framework\View\Layout->renderNonCachedElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:149] #71 Magento\Framework\View\Layout\Interceptor->renderNonCachedElement() called at [vendor/magento/framework/View/Layout.php:510] #72 Magento\Framework\View\Layout->renderElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:140] #73 Magento\Framework\View\Layout\Interceptor->renderElement() called at [vendor/magento/framework/View/Layout.php:975] #74 Magento\Framework\View\Layout->getOutput() called at [vendor/magento/framework/Interception/Interceptor.php:58] #75 Magento\Framework\View\Layout\Interceptor->___callParent() called at [vendor/magento/framework/Interception/Interceptor.php:138] #76 Magento\Framework\View\Layout\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/framework/Interception/Interceptor.php:153] #77 Magento\Framework\View\Layout\Interceptor->___callPlugins() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:347] #78 Magento\Framework\View\Layout\Interceptor->getOutput() called at [vendor/magento/framework/View/Result/Page.php:258] #79 Magento\Framework\View\Result\Page->render() called at [vendor/magento/framework/View/Result/Layout.php:171] #80 Magento\Framework\View\Result\Layout->renderResult() called at [vendor/magento/framework/Interception/Interceptor.php:58] #81 Magento\Framework\View\Result\Page\Interceptor->___callParent() called at [vendor/magento/framework/Interception/Interceptor.php:138] #82 Magento\Framework\View\Result\Page\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/framework/Interception/Interceptor.php:153] #83 Magento\Framework\View\Result\Page\Interceptor->___callPlugins() called at [generated/code/Magento/Framework/View/Result/Page/Interceptor.php:95] #84 Magento\Framework\View\Result\Page\Interceptor->renderResult() called at [vendor/magento/framework/App/Http.php:120] #85 Magento\Framework\App\Http->launch() called at [generated/code/Magento/Framework/App/Http/Interceptor.php:23] #86 Magento\Framework\App\Http\Interceptor->launch() called at [vendor/magento/framework/App/Bootstrap.php:263] #87 Magento\Framework\App\Bootstrap->run() called at [pub/index.php:29] #88 require() called at [/Users/maksold/.composer/vendor/weprovide/valet-plus/server.php:131]
This issue seems to happen when the default stock is not the original Magento stock but a newly created stock set as default for the Main website.
Additional Information
Upon further investigation, it appears the issue may be related to the logic in \Magento\InventoryConfiguration\Model\GetStockItemConfiguration::execute
, specifically line 71, where there's a check $this->defaultStockProvider->getId() !== $stockId
. Altering the return value in \Magento\InventoryCatalog\Model\DefaultStockProvider::getId
from 1
to 2
(the ID of the new default stock) seems to resolve the issue. However, it's unclear if this change might affect other areas of the system. This behavior suggests a potential oversight in handling custom default stocks when 'Manage Stock' is set to 'No'.
Metadata
Assignees
Type
Projects
Status
Ready for Grooming