Skip to content

Instantly share code, notes, and snippets.

@megasmack
Created July 16, 2025 18:15
Show Gist options
  • Select an option

  • Save megasmack/ce00ce248a1d3d87dd67e283468754d3 to your computer and use it in GitHub Desktop.

Select an option

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
// 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