Home > widget-integration > CartService > enrichCartData
CartService.enrichCartData() method
Enrich cart data with shop-specific information Override to add custom fields, metadata, or transformations
Common customization scenarios: - Add product recommendations - Include loyalty points information - Add estimated delivery dates - Add gift wrapping options - Add cross-sell/upsell data
Signature:
protected enrichCartData(cartData: unknown, addedItem: AddToCartItem): Promise<unknown>;
Parameters
|
Parameter |
Type |
Description |
|---|---|---|
|
cartData |
unknown |
Raw cart response data from Shopify Cart API |
|
addedItem |
Cart item that was just added to provide context for enrichment |
Returns:
Promise<unknown>
Promise resolving to enriched cart data with shop-specific additions
Example
Add loyalty points
protected async enrichCartData(cartData: any, addedItem: AddToCartItem) {
const enriched = await super.enrichCartData(cartData, addedItem);
// Add loyalty points calculation
const loyaltyAPI = this.getLoyaltyAPI();
const points = await loyaltyAPI.calculatePoints(cartData.total_price);
return {
...enriched,
loyalty: {
pointsEarned: points,
tierStatus: await loyaltyAPI.getTierStatus(),
},
};
}