Skip to content

Session getLastRealOrder may return wrong order when duplicate incrementIds are used #40259

@Allcharles

Description

@Allcharles

Preconditions and environment

  • Magento version: 2.4.8-p1
  • Anything else that would help a developer reproduce the bug

Given a system which has managed to create two orders for two different stores, with the same increment id in the sales_order table; the loadByIncrementId function in Order.php can return the wrong order. In my scenario, getLastRealOrder from app/code/Magento/Checkout/Model/Session.php would return the wrong order.

In my case, because there was no DB constraint preventing this data from existing, and parts of the magento code base assume that the incrementId will be unique, my system would attempt to update the wrong order at certain points.

I do not know how to replicate the scenario which caused by DB to get into such a state, but this does appear to be a small gap in the system. Assuming this gap is not for supporting an old behaviour of the system, it would make sense to either update the code base to close the possibility, or update the constraint check on the DB.

DB Constraint on the sales_order table:

Image

Related Code:

  1. loadByIncrementId with bad assumption that increment_id can uniquely identify an order:
    public function loadByIncrementId($incrementId)
  2. Example of this function being used which affected my system:
    $this->_order->loadByIncrementId($orderId);

Assuming the number of users who could possibly be affected by this issue is low, I have marked the priority as S4.

Steps to reproduce

  1. Create two orders in the sales_order table using different store IDs, and the same incrementId
  2. Call loadByIncrementId

Expected result

  1. loadByIncrementId should return a list of orders

Actual result

  1. loadByIncrementId selects an order if multiple match

Additional information

No response

Release note

No response

Triage and priority

  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue: ready for confirmationReported on 2.4.8-p1Indicates original Magento version for the Issue report.Triage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject it

    Type

    No type

    Projects

    Status

    Ready for Confirmation

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions