The setData() and getData() methods to access the 'data' base property of order entities is very practical when integrating with an external system (for example to store an external order id). It would be great to have that same possibility on OrderItem entities as well, would anything speak against that?

Here's a patch attached that defines the field and the getter/setter methods.

CommentFileSizeAuthor
order_item_data.patch2.36 KBfloretan

Comments

floretan created an issue. See original summary.

bojanz’s picture

The reason why we have $order->data is because there is a need to store temporary keys&values during the checkout process. This is data that has no need to be shown in a UI, rendered or in a widget.
We removed $order_item->data because it had no such needs.

In your case, wouldn't it make more sense to use configurable fields? I always err on that side architecture-wise.
I'd imagine that an external ID is valuable data, to show in a UI or manipulate from code. Commerce even has a special field type for that (commerce_remote_id), although it isn't usable from the UI at the moment (no widget/formatter).

floretan’s picture

One of the issues with configurable fields is that it creates dependencies from custom code on configuration. I did take the route you suggested though, which led to another small bug report (#2846596: RemoteId fields cannot use "0" as a value) but it works.

  • bojanz committed 317652d on 8.x-2.x authored by floretan
    Issue #2844178 by floretan: Add data to order items
    
bojanz’s picture

Status: Active » Fixed

Decided to proceed with this. Added an update function and a test. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.