/
[in-commerce] Use "LoadFromHash" with order items [5.2.1]

[in-commerce] Use "LoadFromHash" with order items [5.2.1]

Currently, when changing order item contents during order processing in OrdersEventHandler class such code is used:

$order_item->SetDBFieldsFromHash($rec);
$order_item->SetId($rec['OrderItemId']);
...
$order_item->Update();

Problem with this approach is that inside OnBeforeItemUpdate, that is called during update the original field values of the object are not taken from database and default values are used. This way any code checking that field value was changed using $object->GetOriginalField method will always think that field is changed, but it's not true in majority of cases.

Solution

Use this code instead.

$order_item->LoadFromHash($rec);
...
$order_item->Update();

Related Tasks