Skip to content

feat: Allow adding custom product total amount#1233

Open
mmustafa-tse wants to merge 1 commit intomParticle:developmentfrom
mmustafa-tse:feat/customTotalAmount
Open

feat: Allow adding custom product total amount#1233
mmustafa-tse wants to merge 1 commit intomParticle:developmentfrom
mmustafa-tse:feat/customTotalAmount

Conversation

@mmustafa-tse
Copy link
Copy Markdown
Contributor

Background

  • A customer requested that add the ability to manually assign a custom product total amount which is by default calculated by multiplying the price by the quantity

What Has Changed

  • Added the totalAmount as an optional param when creating a product

Screenshots/Video

  • {Include any screenshots or video demonstrating the new feature or fix, if applicable}

Checklist

  • I have performed a self-review of my own code.
  • I have made corresponding changes to the documentation.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have tested this locally.

Additional Notes

  • {Any additional information or context relevant to this PR}

Reference Issue (For employees only. Ignore if you are an outside contributor)

@mmustafa-tse mmustafa-tse requested a review from a team as a code owner March 31, 2026 19:01
@cursor
Copy link
Copy Markdown

cursor bot commented Mar 31, 2026

PR Summary

Medium Risk
Medium risk because it changes the createProduct argument contract and affects how TotalAmount is computed/emitted, which could alter downstream commerce analytics if callers rely on the previous parameter ordering.

Overview
Adds support for custom per-product totals. eCommerce.createProduct now accepts an optional totalAmount parameter and uses it (parsed to a number) instead of always computing Quantity * Price.

Backwards compatibility and coverage. If totalAmount is omitted/invalid it falls back to Quantity * Price, and if an object is passed in that slot it is treated as legacy attributes; tests were added to assert both the default calculation and custom total behavior.

Written by Cursor Bugbot for commit 098b107. This will update automatically on new commits. Configure here.

@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

totalAmount,
name
);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Null totalAmount destroys attributes due to typeof quirk

Medium Severity

The backward-compatibility check typeof totalAmount == 'object' at line 301 also matches null, since typeof null === 'object' in JavaScript. If a caller explicitly passes null for totalAmount (a common pattern when skipping optional positional parameters), sanitizeAttributes(null, name) returns null, overwriting any valid attributes that were already sanitized at line 263. This silently destroys the user's custom attributes.

Fix in Cursor Fix in Web

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.

1 participant