sodexo-cart-template
The sodexo-cart-template component contains all cart and checkout features. This template includes built-in API integration, i18n, cart management, and theme provider.
Authentication Required
This template requires a valid authentication token to process cart and payment operations.
Properties
| Property | HTML Attribute | Type | Default | Description |
|---|---|---|---|---|
theme | theme | Theme | Default Sodexo theme | Customization variables for Sodexo components theme |
apiKey | api-key | string | - | X-API-key for Sodexo API |
token | token | string | - | Authentication token for Sodexo API |
redirectPaymentUri | redirect-payment-uri | string | - | URI for redirecting after card payment (badge reload or order payment). Use :badgeId placeholder for badge reload |
redirectPaymentUri Details
The redirect URI is used after completing card payment operations. The system automatically adds an action query parameter to indicate the operation type:
action=reloadBadge- After badge reloadaction=createOrder- After order payment
Badge reload example: If you provide https://myapp.com/wallet/:badgeId, it becomes https://myapp.com/wallet/12345?action=reloadBadge
Order payment example: https://myapp.com/orders?action=createOrder
Events
| Event | Type | Description |
|---|---|---|
sodexoCartTemplateOrderCreated | CustomEvent<string> | Emitted with order ID when order is created (on-site payment only). Recommended action: Navigate to orders page |
sodexoCartTemplatePaymentCcRequired | CustomEvent<void> | Emitted when credit card payment is required. Recommended action: Navigate to payment page |
sodexoCartTemplateCGVClicked | CustomEvent<void> | Emitted when terms and conditions link is clicked. Recommended action: Navigate to legal page |
Usage
- HTML
<!DOCTYPE html>
<html>
<body>
<sodexo-cart-template
api-key="your-api-key"
token="user-auth-token"
redirect-payment-uri="https://myapp.com/orders"
></sodexo-cart-template>
<script>
const element = document.querySelector('sodexo-cart-template');
// Apply custom theme
element.theme = {
'--sodexo-primary-color': '#283897',
'--sodexo-primary-text-color': '#283897',
'--sodexo-primary-background-color': '#f7f8ff',
'--sodexo-font-family': 'Open Sans',
};
// Handle order creation (on-site payment)
element.addEventListener('sodexoCartTemplateOrderCreated', (event) => {
const orderId = event.detail;
console.log('Order created:', orderId);
// Redirect to orders page
window.location.href = `/orders?orderId=${orderId}`;
});
// Handle credit card payment required
element.addEventListener('sodexoCartTemplatePaymentCcRequired', () => {
window.location.href = '/payment';
});
// Handle CGV/terms link click
element.addEventListener('sodexoCartTemplateCGVClicked', () => {
console.log('CGV clicked');
// Open terms in new tab or navigate
window.open('/legal/terms', '_blank');
});
</script>
</body>
</html>
Property Naming Convention
Naming Syntax
When using properties:
- In HTML: Use kebab-case (e.g.,
api-key,redirect-payment-uri) - In JavaScript: Use camelCase (e.g.,
apiKey,redirectPaymentUri) - Events: Can only be handled in JavaScript, not in HTML attributes
Navigation Flow
This diagram shows the recommended navigation flow for the cart template:
Recommended Actions
- On
sodexoCartTemplateOrderCreated: Navigate to orders page (on-site payment)
const orderId = event.detail;
navigate(`/orders?orderId=${orderId}`);
- On
sodexoCartTemplatePaymentCcRequired: Navigate to payment page
navigate("/payment");
- On
sodexoCartTemplateCGVClicked: Open terms and conditions
window.open("/legal/terms", "_blank");