Skip to content

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

Open
@nige-one

Description

@nige-one

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:

/**
* Add inventory reservation before placing synchronous order or if stock reservation is deferred.
*
* @param OrderManagementInterface $subject
* @param callable $proceed
* @param OrderInterface $order
* @return OrderInterface
* @throws \Exception
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function aroundPlace(

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).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Ready for Grooming

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions