Unable to add order line item without overriding the unit price in custom form

Created on 3 November 2023, 11 months ago
Updated 16 November 2023, 10 months ago

Describe your bug or feature request.

As part of #2910410: Unable to add or edit order line item without overriding the unit price , some logic was added to UnitPriceWidget::extractFormValues() to detect the order the order item belongs to in order to calculate the unit price when it is not explicitly overridden in the widget. See changes.

With this logic, it firstly tries to get the order from the order item, and if it fails, it tries to retrieve it from the entity form, if only it is an instance of OrderForm.

Later, in a second iteration as part of #3137651: Error: Call to undefined method Drupal\commerce_order\Entity\OrderItem::getCustomer() , this logic was changed in order to ensure that order was correctly loaded in order to calculate the price. See change.

However,trying to optimize the query, the situation ended up forcing to have an instance of OrderForm to make it work. It happens because the whole calculation process ignores the order declared by the order item, if any. See line 179 of the current code.

Our proposal is to adjust the logic to take into account the order defined by the order item, if any, and then fallback to the one defined by the form, and finally skip the process if the order is not set. That was the aim of #3137651: Error: Call to undefined method Drupal\commerce_order\Entity\OrderItem::getCustomer() .

If a bug, provide steps to reproduce it from a clean install.

We found this issue while working on the Commerce Order Item UI module, so the easiest way to reproduce this bug is installing that module:

  1. Download and install Commerce Suite & Commerce Order Item UI
  2. Create an order either via checkout process or the admin UI
  3. Confirm that "Order Items" tab is available
  4. Try to add a new order item from the "Add new order item" link
  5. Fill the product variation order item & quantity fields
  6. Leave the "Override the unit price" option unchecked
  7. System throws an error instead of creating a new order item whose price value is the default one
🐛 Bug report
Status

Fixed

Version

2.0

Component

Order

Created by

🇪🇸Spain plopesc Valladolid

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024