magento / magento/inventory

Append Reservation Plugin Applied To OrderManagementInterface which is only triggered when submitting a Quote

Open
#3,419 1 comment 0 reactions 0 assignees View on GitHub
Progress: ready for grooming
Dominant language
PHP
Stars
357
Forks
262
PR merge metrics
No merged PRs in 30d

Description

### Summary (*)
The Append Reservation Plugin only fires when creating an order is triggered via quote management. This leads to issues when a order is created directly. Following the order lifecycle by creating shipments and creditmemo will mix up the reservervations leading to wrongly rendered salable quantities for products.

### Examples (*)
For automatically appending new reserverations an around plugin is used:
https://github.com/magento/inventory/blob/0208e433376704358c1461e078f71d1270279f7b/InventorySales/Plugin/Sales/OrderManagement/AppendReservationsAfterOrderPlacementPlugin.php#L100-L110

The plugged method:
https://github.com/magento/magento2/blob/2217274eb99b66a2c8e63cb488d0edaceb8f0ae3/app/code/Magento/Sales/Model/Service/OrderService.php#L261

is only used when creating an order via QuoteManagement. An order could also by placed via the order's model itself by using it's own `place` function:
https://github.com/magento/magento2/blob/2217274eb99b66a2c8e63cb488d0edaceb8f0ae3/app/code/Magento/Sales/Model/Order.php#L1273
method.
This is even used inside the plugged method eventually:
https://github.com/magento/magento2/blob/2217274eb99b66a2c8e63cb488d0edaceb8f0ae3/app/code/Magento/Sales/Model/Service/OrderService.php#L264

### Proposed solution
Since creating an order without going through a quote first is totally legit I suggest changing this, Utlizing the thrown event `sales_order_place_after` inside the order's `place` method would even be a way cleaner approach, since the order itself is not touched by the mechanism thus using an event is the better approach in my view.

I stumbled upon this when using a third party service that is creating orders as descriped (not via quotes).

Contributor guide

Open the contributing guide

Research direction

Start with InventorySales/Plugin/Sales/OrderManagement/AppendReservationsAfterOrderPlacementPlugin.php and compare its OrderService.php path with the place method in Sales/Model/Order.php. Trace the sales_order_place_after event and reservation handling for direct order placement. Done means direct orders trigger the same reservation behavior without mixing reservations during shipment and creditmemo processing.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.