ProductCard custom element provides a flexible, feature-rich product card component that supports multiple layouts, wishlist integration, donation products, and dynamic pricing.
Overview
Thecustom-salla-product-card web component renders product information with support for:
- Multiple layout variations (vertical, horizontal, full image, minimal)
- Wishlist functionality
- Product badges and promotions
- Donation products with progress bars
- Special products with countdown timers
- Responsive pricing display
- Product ratings
- Add to cart integration
Usage
Attributes
JSON string containing product data
Renders the card in horizontal layout
Adds shadow effect on hover
Hides the add to cart button
Renders card with full-width image background
Renders minimal card layout
Renders special product card with countdown timer
Displays remaining quantity badge
Product data structure
Theproduct attribute expects a JSON object with the following structure:
Layout variations
Vertical card (default)
Horizontal card
Full image card
Minimal card
Special product card
Key methods
getProductBadge
Determines and returns the appropriate badge HTML for the product. Priority order:- Pre-order label
- Promotion title
- Quantity remaining (if
showQuantityis true) - Out of stock badge
getProductPrice
Generates the price display HTML based on product pricing:- Sale price with strikethrough regular price
- Starting price for products with variants
- Regular price
getAddButtonLabel
Returns the appropriate button label based on product status:- “Pre-order now” for pre-order products
- “Book now” for booking products
- “Add to cart” for regular products
- “Out of stock” for unavailable products
- “Donation exceed” for donation products
formatDate
Formats a date string for countdown timers.Date string to format
initCircleBar
Initializes the circular progress bar for special products showing quantity.Features
Wishlist integration
The product card automatically integrates with Salla’s wishlist functionality:Donation products
For donation products, the card displays:- Progress bar showing donation progress
- Custom amount input field (if enabled)
- Donation-specific messaging
Product ratings
Displays star rating if available:Countdown timer
For special products withdiscount_ends date:
Event handling
Theme ready event
The component waits for the theme to be ready before initializing:Language loading
Translations are loaded dynamically:Styling classes
The component applies various CSS classes based on configuration:s-product-card-entry- Base classs-product-card-vertical- Vertical layouts-product-card-horizontal- Horizontal layouts-product-card-full-image- Full image layouts-product-card-minimal- Minimal layouts-product-card-special- Special products-product-card-donation- Donation products-product-card-shadow- Shadow on hovers-product-card-out-of-stock- Out of stock states-product-card-fit-height- Fit image height
JavaScript integration
Security
The component includes HTML escaping to prevent XSS attacks:Product names and image alt text are automatically escaped to prevent security vulnerabilities.