{# Product Card ============ A versatile product card component for e-commerce listings. Supports multiple sizes, badges, ratings, and quick actions. Parameters: - product_var: Alpine.js variable name for the product object (default: 'product') - size: 'sm' | 'md' | 'lg' (default: 'md') - show_rating: Show star rating (default: true) - show_quick_add: Show quick add to cart button (default: true) - show_wishlist: Show wishlist heart icon (default: true) - show_store: Show store name for marketplace (default: false) - add_to_cart_action: Alpine.js action for add to cart (default: 'addToCart(product)') - wishlist_action: Alpine.js action for wishlist toggle (default: 'toggleWishlist(product)') - product_url_field: Field name for product URL (default: 'url') - image_field: Field name for image URL (default: 'image_url') - title_field: Field name for product title (default: 'name') - price_field: Field name for price (default: 'price') - sale_price_field: Field name for sale price (default: 'sale_price') - rating_field: Field name for rating (default: 'rating') - review_count_field: Field name for review count (default: 'review_count') - stock_field: Field name for stock quantity (default: 'stock') - store_field: Field name for store name (default: 'store_name') Expected product object structure: { id: number, name: string, url: string, image_url: string, price: number, sale_price: number | null, rating: number (0-5), review_count: number, stock: number, is_new: boolean, store_name: string (optional) } Usage: {% from 'shared/macros/storefront/product-card.html' import product_card %} {# With custom settings #} {{ product_card(product_var='featuredProduct', size='lg', show_store=true) }} #} {% macro product_card( product_var='product', size='md', show_rating=true, show_quick_add=true, show_wishlist=true, show_store=false, add_to_cart_action='addToCart(product)', wishlist_action='toggleWishlist(product)', product_url_field='url', image_field='image_url', title_field='name', price_field='price', sale_price_field='sale_price', rating_field='rating', review_count_field='review_count', stock_field='stock', store_field='store_name' ) %} {% set sizes = { 'sm': { 'card': 'max-w-[200px]', 'image': 'h-32', 'title': 'text-sm', 'price': 'text-sm', 'badge': 'text-xs px-1.5 py-0.5', 'btn': 'text-xs px-2 py-1', 'icon': 'w-4 h-4', 'rating': 'w-3 h-3' }, 'md': { 'card': 'max-w-[280px]', 'image': 'h-48', 'title': 'text-base', 'price': 'text-base', 'badge': 'text-xs px-2 py-1', 'btn': 'text-sm px-3 py-2', 'icon': 'w-5 h-5', 'rating': 'w-4 h-4' }, 'lg': { 'card': 'max-w-[360px]', 'image': 'h-64', 'title': 'text-lg', 'price': 'text-lg', 'badge': 'text-sm px-2.5 py-1', 'btn': 'text-base px-4 py-2.5', 'icon': 'w-6 h-6', 'rating': 'w-5 h-5' } } %} {% set s = sizes[size] %}
{# Image Container #}
{# Badges #}
{# Sale Badge #} {# New Badge #} New
{# Wishlist Button #} {% if show_wishlist %} {% endif %} {# Out of Stock Overlay #}
Out of Stock
{# Content #}
{# Store Name #} {% if show_store %}

{% endif %} {# Title #}

{# Rating #} {% if show_rating %}
{% endif %} {# Price #}
{# Quick Add Button #} {% if show_quick_add %} {% endif %}
{% endmacro %} {# Product Badge ============= Standalone badge component for product overlays. Parameters: - type: 'sale' | 'new' | 'bestseller' | 'low_stock' | 'out_of_stock' - value: Optional value (e.g., '-20%' for sale, 'Only 3 left' for low_stock) - size: 'sm' | 'md' | 'lg' (default: 'md') Usage: {{ product_badge(type='sale', value='-20%') }} {{ product_badge(type='new') }} {{ product_badge(type='low_stock', value='Only 3 left') }} #} {% macro product_badge(type, value=none, size='md') %} {% set badge_styles = { 'sale': 'bg-red-500 text-white', 'new': 'bg-green-500 text-white', 'bestseller': 'bg-yellow-500 text-gray-900', 'low_stock': 'bg-orange-500 text-white', 'out_of_stock': 'bg-gray-700 text-white' } %} {% set badge_labels = { 'sale': 'Sale', 'new': 'New', 'bestseller': 'Bestseller', 'low_stock': 'Low Stock', 'out_of_stock': 'Out of Stock' } %} {% set sizes = { 'sm': 'text-xs px-1.5 py-0.5', 'md': 'text-xs px-2 py-1', 'lg': 'text-sm px-2.5 py-1' } %} {{ value if value else badge_labels[type] }} {% endmacro %}