AddToCartToast custom element displays an elegant notification when a product is added to the shopping cart, showing product details and providing quick actions.
Overview
Thesalla-add-product-toast component is an auto-hiding toast notification that appears when products are added to the cart. It features:
- Product image, name, and price display
- Selected product options
- Auto-hide timer with progress bar
- Pause on hover functionality
- Quick checkout and view cart actions
- Responsive discount pricing
Usage
Features
Auto-hide timer
The toast automatically disappears after 5 seconds, with a visual progress bar indicating the remaining time.Auto-hide duration in milliseconds
Pause on hover
When the user hovers over the toast, the auto-hide timer pauses, allowing them to read the information or click action buttons.Progress indicator
A visual progress bar at the top of the toast shows the remaining time before auto-hide.Product data structure
The toast displays the following product information:Key methods
open
Displays the toast with product information.Product information to display
close
Manually closes the toast and clears timers.handleProductAdded
Internal method that processes the “Product Added” event from Salla.Analytics data from Salla’s product added event
extractOptions
Processes and formats product options for display.Raw product options from cart item
Options like image uploads, file uploads, and map selections have their values hidden, showing only the option name.
startAutoHideTimer
Starts or restarts the auto-hide timer with progress bar animation.clearTimers
Clears all active timers and intervals.Component lifecycle
connectedCallback
Called when the element is added to the DOM. Initializes the component after theme is ready.disconnectedCallback
Called when the element is removed from the DOM. Cleans up timers.Toast structure
The toast displays the following sections:Header
- Success icon
- “Added to Cart” message
- Close button
Body
- Product image (clickable)
- Product name (clickable)
- Selected options (up to 3 visible)
- “Show more” link (if more than 3 options)
- Product price (with discount indication)
Actions
- Complete order button (triggers checkout)
- View cart button (navigates to cart)
Event integration
Product added event
The toast listens to Salla’s product added event:Cart submission
The checkout button triggers cart submission:Localization
The component supports Arabic and English translations:Styling classes
The component uses the following CSS classes:s-add-product-toast- Base container classs-add-product-toast--visible- Applied when toast is showns-add-product-toast__progress- Progress bar containers-add-product-toast__progress-bar- Animated progress indicators-add-product-toast__header- Header sections-add-product-toast__body- Product details sections-add-product-toast__actions- Action buttons sections-add-product-toast__image- Product images-add-product-toast__name- Product names-add-product-toast__options- Product options lists-add-product-toast__price- Price displays-add-product-toast__price-sale- Sale prices-add-product-toast__price-original- Original price (strikethrough)
Security
The component escapes HTML to prevent XSS vulnerabilities:Error handling
The component includes error handling for cart API failures:Customization example
To customize the auto-hide duration:Options display
The toast intelligently handles different option types:- Single selection: Shows the selected option
- Multiple selection: Shows all selected options separated by commas
- File/Image uploads: Shows option name without value
- Map selection: Shows option name without value
- Text input: Shows the entered value