Skip to content

Magento changed the entity type of $order after calls $invoice = $this->_invoiceService->prepareInvoice($order); #40154

@RadarsofthouseDev

Description

@RadarsofthouseDev

Preconditions and environment

  • Magento version: 2.4.8-p2

Steps to reproduce

  1. Create a custom script or use a module with the following code:
/** @var \Magento\Sales\Api\OrderRepositoryInterface $orderRepository */
/** @var \Magento\Sales\Model\Service\InvoiceService $invoiceService */

$orderId = 7030365; // use a valid order_id that can be invoiced
$order = $orderRepository->get($orderId);

$this->_logger->info("Before entity type: " . $order->getEntityType());
$invoice = $invoiceService->prepareInvoice($order);
$this->_logger->info("After entity type: " . $order->getEntityType());`
  1. Run the custom script.

Expected result

Before entity type: order
After entity type: order

Actual result

Before entity type: order
After entity type: invoice

Additional information

The $order object’s entity type changes to invoice after calling prepareInvoice().
$order should always remain of entity type "order".

Impact:
This behavior can cause unexpected side effects:
Other logic using the same $order object may incorrectly treat it as an invoice.
Leads to data integrity issues and inconsistent behavior.

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

    Area: OrderComponent: SalesIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P2A defect with this priority could have functionality issues which are not to expectations.Reported on 2.4.8-p2Indicates original Magento version for the Issue report.Reproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branchTriage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject it

    Type

    No type

    Projects

    Status

    Ready for Development

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions