Skip to content

Fix line item meta data overwrite#14

Open
JustShah wants to merge 2 commits into
1-0-feature-branchfrom
fix/line-item-meta-data-overwrite
Open

Fix line item meta data overwrite#14
JustShah wants to merge 2 commits into
1-0-feature-branchfrom
fix/line-item-meta-data-overwrite

Conversation

@JustShah

@JustShah JustShah commented Mar 6, 2025

Copy link
Copy Markdown
  • 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.

image
image

@JustShah
JustShah force-pushed the fix/line-item-meta-data-overwrite branch 3 times, most recently from 2bb09a9 to 5b0fc9a Compare March 6, 2025 13:23
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?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JustShah please update on this

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JustShah please update on this

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For user_serial_number we converted it into an array, even for a single value.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Rename the customer metadata key to line_item_identifier
  2. Rename the product column and name it as Require Line Item Identifier

image

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved, Renamed key and column.

@fthobe

fthobe commented Mar 6, 2025

Copy link
Copy Markdown

Some general notes:
customer meta is customer data, it's our responsibility to check or validate as long as we don't provide the visualization and data entry layer. The logic is correct, though it should not alter the core.

@fthobe fthobe left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments

Comment thread app/decorators/controllers/cart_line_items_controller_decorator.rb
@fthobe

fthobe commented Mar 10, 2025

Copy link
Copy Markdown

We need to decide where to put this.
@JustShah we talk tonight about this one.

- 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.
@JustShah
JustShah force-pushed the fix/line-item-meta-data-overwrite branch from 5b0fc9a to dbdf81a Compare March 11, 2025 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants