Fix line item meta data overwrite#14
Conversation
2bb09a9 to
5b0fc9a
Compare
| end | ||
| rescue ActiveRecord::RecordInvalid => e | ||
| @order.errors.add(:base, e.record.errors.full_messages.join(", ")) | ||
| customer_metadata = params.require(:customer_metadata).permit! if params[:customer_metadata].present? |
There was a problem hiding this comment.
We have decided and documented how meta data should work.
We had the discussion that sanitisation and conformity including checks as in:
- do I overwrite metadata
- should I check what meta data is present
is the job of the interacting party and should therfor go into the frontend and not into the core.
In this case the interaction is happening in the starter frontend, validation if identical line_item(s) are present should be done on the data entry section (logic powering the form) and not inside the core.
There was a problem hiding this comment.
The changes were made in the Starter Frontend, not in the Core.
| @line_item = @order.contents.add(variant, quantity) | ||
| if customer_metadata.present? | ||
| customer_metadata.each do |key, value| | ||
| next unless key == "user_serial_number" |
There was a problem hiding this comment.
The logic should be generic.
Is meta data present > are key value pairs identical > build the array
It might be a consideration to pass all line item meta data as array even if only one value is present.
There was a problem hiding this comment.
For user_serial_number we converted it into an array, even for a single value.
There was a problem hiding this comment.
@JustShah As bespoken please name it line_item_identifier as we will correct incorrect data from the erp, this value will not be present on admin data, in addition, please consider that customer_metadata { user_serial_number
is redundant as customer and user are redundant.
There was a problem hiding this comment.
Resolved, Renamed key and column.
|
Some general notes: |
|
We need to decide where to put this. |
- Update attribute and method names for consistency and clarity. - Adjust views and migration to reflect the new naming convention.
- Updated the logic to handle `line_item_identifier` in customer metadata. - Ensured that `line_item_identifier` is stored as an array in the line item's customer metadata. - Removed the generation of unique keys for `line_item_identifier`. This change ensures that the `line_item_identifier` is correctly stored as an array in the line item's customer metadata, allowing multiple serial numbers to be associated with a single line item.
5b0fc9a to
dbdf81a
Compare

line_item_identifierin customer metadata.line_item_identifieris stored as an array in the line item's customer metadata.line_item_identifier.This change ensures that the
line_item_identifieris correctly stored as an array in the line item's customer metadata, allowing multiple serial numbers to be associated with a single line item.