Created
July 16, 2025 18:15
-
-
Save megasmack/ce00ce248a1d3d87dd67e283468754d3 to your computer and use it in GitHub Desktop.
Add Item(s) to Cart with Custom Fields using the commerce/cartApi in Salesforce Core Commerce
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Using add itemS to cart from the commerce/cartApi | |
| import { addItemsToCart } from "commerce/cartApi"; | |
| // Set up an array as a payload. | |
| const payload = [{ | |
| productId: this.productId, | |
| quantity: this.quantity, | |
| type: "Product" | |
| }]; | |
| // Add custom field data to the CartItem record. | |
| if (this.customMetric) { | |
| // Only sending one product in this example. | |
| payload[0].customFields = [ | |
| { | |
| attributes: { | |
| type: "CartItem" | |
| }, | |
| CustomField__c: this.customMetric | |
| } | |
| ]; | |
| } | |
| const result = await addItemsToCart(payload); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment