AmpersandHQ / magento2-disable-stock-reservation

This module disables the inventory reservation logic introduced as part of MSI in Magento 2.3.3
GNU Lesser General Public License v3.0
209 stars 60 forks source link

Intermittent Undefined index: <sku> in GetDefaultSortedSourcesResult when placing an order #77

Open Silarn opened 2 years ago

Silarn commented 2 years ago

This is only affecting orders occasionally, but it seems to be stopping the order after the transaction is complete during the various 'after order' plugins. (Emails and a few other post-order functions are not running.)

So far this has happened only on orders with bundles, but not for every one. If I knew how to replicate it I would see if I could step through the code.

Here's a stacktrace.

Exception: Notice: Undefined index: platinum.8168 in /vendor/magento/module-inventory-source-selection-api/Model/Algorithms/Result/GetDefaultSortedSourcesResult.php on line 127
1
File "/vendor/magento/framework/App/ErrorHandler.php" line 61
2
Magento\Framework\App\ErrorHandler::handler [args]
3
File "/vendor/rollbar/rollbar/src/Handlers/ErrorHandler.php" line 38 in call_user_func [args]
4
File "/vendor/magento/module-inventory-source-selection-api/Model/Algorithms/Result/GetDefaultSortedSourcesResult.php" line 127 in Rollbar\Handlers\ErrorHandler::handle [args]
5
File "/vendor/magento/module-inventory-source-selection/Model/Algorithms/PriorityBasedAlgorithm.php" line 73 in Magento\InventorySourceSelectionApi\Model\Algorithms\Result\GetDefaultSortedSourcesResult::execute [args]
6
File "/vendor/magento/module-inventory-source-selection-api/Model/SourceSelectionService.php" line 61 in Magento\InventorySourceSelection\Model\Algorithms\PriorityBasedAlgorithm::execute [args]
7
File "/vendor/ampersand/magento2-disable-stock-reservation/src/Model/GetSourceSelectionResultFromOrder.php" line 98 in Magento\InventorySourceSelectionApi\Model\SourceSelectionService::execute [args]
8
File "/vendor/ampersand/magento2-disable-stock-reservation/src/Plugin/SourceDeductionProcessor.php" line 131 in Ampersand\DisableStockReservation\Model\GetSourceSelectionResultFromOrder::execute [args]
9
File "/vendor/magento/framework/Interception/Interceptor.php" line 146 in Ampersand\DisableStockReservation\Plugin\SourceDeductionProcessor::afterPlace [args]
10
File "/vendor/magento/module-inventory-sales/Plugin/Sales/OrderManagement/AppendReservationsAfterOrderPlacementPlugin.php" line 195 in Magento\Sales\Model\Service\OrderService\Interceptor::Magento\Framework\Interception\{closure} [args]
11
File "/vendor/magento/framework/Interception/Interceptor.php" line 135 in Magento\InventorySales\Plugin\Sales\OrderManagement\AppendReservationsAfterOrderPlacementPlugin::aroundPlace [args]
12
File "/vendor/magento/framework/Interception/Interceptor.php" line 153 in Magento\Sales\Model\Service\OrderService\Interceptor::Magento\Framework\Interception\{closure} [args]
13
File "/generated/code/Magento/Sales/Model/Service/OrderService/Interceptor.php" line 32 in Magento\Sales\Model\Service\OrderService\Interceptor::___callPlugins [args]
14
File "/vendor/magento/module-quote/Model/QuoteManagement.php" line 575 in Magento\Sales\Model\Service\OrderService\Interceptor::place [args]
15
File "/vendor/magento/module-quote/Model/QuoteManagement.php" line 456 in Magento\Quote\Model\QuoteManagement::submitQuote [args]
16
File "/vendor/magento/framework/Interception/Interceptor.php" line 58 in Magento\Quote\Model\QuoteManagement::submit [args]
17
File "/vendor/magento/framework/Interception/Interceptor.php" line 138 in Magento\Quote\Model\QuoteManagement\Interceptor::___callParent [args]
18
File "/vendor/magento/framework/Interception/Interceptor.php" line 153 in Magento\Quote\Model\QuoteManagement\Interceptor::Magento\Framework\Interception\{closure} [args]
19
File "/generated/code/Magento/Quote/Model/QuoteManagement/Interceptor.php" line 23 in Magento\Quote\Model\QuoteManagement\Interceptor::___callPlugins [args]
20
File "/vendor/magento/module-quote/Model/QuoteManagement.php" line 414 in Magento\Quote\Model\QuoteManagement\Interceptor::submit [args]
21
File "/vendor/magento/module-checkout/Model/PaymentInformationManagement.php" line 125 in Magento\Quote\Model\QuoteManagement::placeOrder [args]
22
File "/vendor/magento/framework/Interception/Interceptor.php" line 58 in Magento\Checkout\Model\PaymentInformationManagement::savePaymentInformationAndPlaceOrder [args]
23
File "/vendor/magento/framework/Interception/Interceptor.php" line 138 in Magento\Checkout\Model\PaymentInformationManagement\Interceptor::___callParent [args]
24
File "/vendor/magento/framework/Interception/Interceptor.php" line 153 in Magento\Checkout\Model\PaymentInformationManagement\Interceptor::Magento\Framework\Interception\{closure} [args]
25
File "/generated/code/Magento/Checkout/Model/PaymentInformationManagement/Interceptor.php" line 23 in Magento\Checkout\Model\PaymentInformationManagement\Interceptor::___callPlugins [args]
26
Magento\Checkout\Model\PaymentInformationManagement\Interceptor::savePaymentInformationAndPlaceOrder [args]
27
File "/vendor/magento/module-webapi/Controller/Rest/SynchronousRequestProcessor.php" line 95 in call_user_func_array [args]
28
File "/vendor/magento/module-webapi/Controller/Rest.php" line 188 in Magento\Webapi\Controller\Rest\SynchronousRequestProcessor::process [args]
29
File "/vendor/magento/framework/Interception/Interceptor.php" line 58 in Magento\Webapi\Controller\Rest::dispatch [args]
30
File "/vendor/magento/framework/Interception/Interceptor.php" line 138 in Magento\Webapi\Controller\Rest\Interceptor::___callParent [args]
31
File "/vendor/fastly/magento2/Model/FrontControllerPlugin.php" line 135 in Magento\Webapi\Controller\Rest\Interceptor::Magento\Framework\Interception\{closure} [args]
32
File "/vendor/magento/framework/Interception/Interceptor.php" line 135 in Fastly\Cdn\Model\FrontControllerPlugin::aroundDispatch [args]
33
File "/vendor/magento/framework/Interception/Interceptor.php" line 153 in Magento\Webapi\Controller\Rest\Interceptor::Magento\Framework\Interception\{closure} [args]
34
File "/generated/code/Magento/Webapi/Controller/Rest/Interceptor.php" line 23 in Magento\Webapi\Controller\Rest\Interceptor::___callPlugins [args]
35
File "/vendor/magento/framework/App/Http.php" line 116 in Magento\Webapi\Controller\Rest\Interceptor::dispatch [args]
36
File "/vendor/magento/framework/Interception/Interceptor.php" line 58 in Magento\Framework\App\Http::launch
37
File "/vendor/magento/framework/Interception/Interceptor.php" line 138 in Magento\Framework\App\Http\Interceptor::___callParent [args]
38
File "/vendor/magento/framework/Interception/Interceptor.php" line 153 in Magento\Framework\App\Http\Interceptor::Magento\Framework\Interception\{closure}
39
File "/generated/code/Magento/Framework/App/Http/Interceptor.php" line 23 in Magento\Framework\App\Http\Interceptor::___callPlugins [args]
40
File "/vendor/magento/framework/App/Bootstrap.php" line 264 in Magento\Framework\App\Http\Interceptor::launch
41
File "/pub/index.php" line 29 in Magento\Framework\App\Bootstrap::run [args]
Magento\Framework\Exception\CouldNotSaveException: A server error stopped your order from being placed. Please try to place your order again.
1
File "/vendor/magento/module-checkout/Model/PaymentInformationManagement.php" line 136
2
File "/vendor/magento/framework/Interception/Interceptor.php" line 58 in Magento\Checkout\Model\PaymentInformationManagement::savePaymentInformationAndPlaceOrder [args]
3
File "/vendor/magento/framework/Interception/Interceptor.php" line 138 in Magento\Checkout\Model\PaymentInformationManagement\Interceptor::___callParent [args]
4
File "/vendor/magento/framework/Interception/Interceptor.php" line 153 in Magento\Checkout\Model\PaymentInformationManagement\Interceptor::Magento\Framework\Interception\{closure} [args]
5
File "/generated/code/Magento/Checkout/Model/PaymentInformationManagement/Interceptor.php" line 23 in Magento\Checkout\Model\PaymentInformationManagement\Interceptor::___callPlugins [args]
6
Magento\Checkout\Model\PaymentInformationManagement\Interceptor::savePaymentInformationAndPlaceOrder [args]
7
File "/vendor/magento/module-webapi/Controller/Rest/SynchronousRequestProcessor.php" line 95 in call_user_func_array [args]
8
File "/vendor/magento/module-webapi/Controller/Rest.php" line 188 in Magento\Webapi\Controller\Rest\SynchronousRequestProcessor::process [args]
9
File "/vendor/magento/framework/Interception/Interceptor.php" line 58 in Magento\Webapi\Controller\Rest::dispatch [args]
10
File "/vendor/magento/framework/Interception/Interceptor.php" line 138 in Magento\Webapi\Controller\Rest\Interceptor::___callParent [args]
11
File "/vendor/fastly/magento2/Model/FrontControllerPlugin.php" line 135 in Magento\Webapi\Controller\Rest\Interceptor::Magento\Framework\Interception\{closure} [args]
12
File "/vendor/magento/framework/Interception/Interceptor.php" line 135 in Fastly\Cdn\Model\FrontControllerPlugin::aroundDispatch [args]
13
File "/vendor/magento/framework/Interception/Interceptor.php" line 153 in Magento\Webapi\Controller\Rest\Interceptor::Magento\Framework\Interception\{closure} [args]
14
File "/generated/code/Magento/Webapi/Controller/Rest/Interceptor.php" line 23 in Magento\Webapi\Controller\Rest\Interceptor::___callPlugins [args]
15
File "/vendor/magento/framework/App/Http.php" line 116 in Magento\Webapi\Controller\Rest\Interceptor::dispatch [args]
16
File "/vendor/magento/framework/Interception/Interceptor.php" line 58 in Magento\Framework\App\Http::launch
17
File "/vendor/magento/framework/Interception/Interceptor.php" line 138 in Magento\Framework\App\Http\Interceptor::___callParent [args]
18
File "/vendor/magento/framework/Interception/Interceptor.php" line 153 in Magento\Framework\App\Http\Interceptor::Magento\Framework\Interception\{closure}
19
File "/generated/code/Magento/Framework/App/Http/Interceptor.php" line 23 in Magento\Framework\App\Http\Interceptor::___callPlugins [args]
20
File "/vendor/magento/framework/App/Bootstrap.php" line 264 in Magento\Framework\App\Http\Interceptor::launch
21
File "/pub/index.php" line 29 in Magento\Framework\App\Bootstrap::run [args]
convenient commented 1 year ago

@Silarn maybe this? https://github.com/AmpersandHQ/magento2-disable-stock-reservation/issues/34#issuecomment-780872927

Silarn commented 1 year ago

This did indeed appear to be a potential cause, however I'm somewhat confused about the fact that were were almost twice as many SKUs with trailing spaces in the inventory_source_item table than there were in the catalog_product_entity table.

Is this some sort of core Magento issue?

convenient commented 1 year ago

@Silarn I've never come across it myself. It may be a core magento issue that somehow mangles these skus, or perhaps some way of creating the products / stock inventory that we don't hit during our REST API product creation flow šŸ¤·

Tsalkapone commented 1 year ago

We have recently come accross this issue as well and it seems that it is caused by the normalizeSku function. Products with sku containing non-word characters messing with array indexing causing exception notice in line 127: $itemsTdDeliver[$normalizedSku] -= $qtyToDeduct;

We fixed the issue by modifying normalizeSku function in order to remove non-words characters from sku and the error was fixed:

private function normalizeSku(string $sku): string { return preg_replace("/[^\w\d]/","",mb_convert_case($sku, MB_CASE_LOWER, 'UTF-8')); }