Skip to content

[5.x]: Recalculation of completed orders removes out of stock/unavailable line items #4332

Description

@jmauzyk

What happened?

Description

Noticed a behavior where running recalculation on a completed order can result in line items being removed if their purchasables' stock has reached 0 Available or been marked as not available for purchase.

Steps to reproduce

  1. Complete an order containing a line item for purchasable X.
  2. Either set purchasable X's Available inventory to 0 or toggle its Available for purchase field off.
  3. On the order's edit page in the CP, click Edit, then click Recalculate order.

Expected behavior

Order recalculates adjustments but retains line items based on their availability when the order was placed.

Actual behavior

The entire order is recalculated, removing line items based on their purchasables' current stock and availability. Even if its purchasable has On Hand stock and a committed quantity for the line item, it will be removed if the
Available stock is 0.

Craft CMS version

Craft Pro 5.10.8.1

Craft Commerce version

5.6.6.1

PHP version

8.2.4

Operating system and version

Linux 4.15.0-65-generic

Database type and version

PostgreSQL 14.7

Image driver and version

Imagick 3.7.0 (ImageMagick 6.9.7-4)

Installed plugins and versions

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions