UNPKG

@mayurgodhani/ecomtools-cli

Version:

E-commerce tools MCP server for Shopify development

168 lines (146 loc) 3.78 kB
Title: Shopify Product Card Description: A responsive product card component for displaying products in collections with image, title, price, and add to cart button. Code: <div class="product-card"> <a href="{{ product.url | within: collection }}" class="product-card__link"> <div class="product-card__image-wrapper"> {% if product.featured_image %} <img class="product-card__image" src="{{ product.featured_image | img_url: '400x' }}" alt="{{ product.featured_image.alt | escape }}" width="400" height="400" loading="lazy" > {% else %} {{ 'product-1' | placeholder_svg_tag: 'product-card__image placeholder-svg' }} {% endif %} {% if product.compare_at_price > product.price %} <span class="product-card__badge">Sale</span> {% endif %} </div> <div class="product-card__info"> <h3 class="product-card__title">{{ product.title }}</h3> <div class="product-card__price"> {% if product.compare_at_price > product.price %} <span class="product-card__price-regular">{{ product.price | money }}</span> <span class="product-card__price-compare">{{ product.compare_at_price | money }}</span> {% else %} <span class="product-card__price-regular">{{ product.price | money }}</span> {% endif %} </div> </div> </a> <div class="product-card__actions"> {% if product.available %} <button class="product-card__add-to-cart" data-product-id="{{ product.id }}" data-variant-id="{{ product.selected_or_first_available_variant.id }}" > Add to cart </button> {% else %} <button class="product-card__sold-out" disabled>Sold out</button> {% endif %} </div> </div> <style> .product-card { position: relative; margin-bottom: 30px; border-radius: 8px; overflow: hidden; box-shadow: 0 2px 5px rgba(0,0,0,0.1); transition: transform 0.3s, box-shadow 0.3s; } .product-card:hover { transform: translateY(-5px); box-shadow: 0 5px 15px rgba(0,0,0,0.1); } .product-card__link { display: block; text-decoration: none; color: inherit; } .product-card__image-wrapper { position: relative; padding-top: 100%; /* 1:1 Aspect Ratio */ overflow: hidden; } .product-card__image { position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover; transition: transform 0.3s; } .product-card:hover .product-card__image { transform: scale(1.05); } .product-card__badge { position: absolute; top: 10px; right: 10px; background-color: #e53e3e; color: white; padding: 5px 10px; border-radius: 4px; font-size: 0.75rem; font-weight: bold; } .product-card__info { padding: 15px; background-color: white; } .product-card__title { margin: 0 0 10px; font-size: 1rem; font-weight: 500; } .product-card__price { display: flex; align-items: center; flex-wrap: wrap; font-weight: 500; } .product-card__price-regular { font-size: 1rem; } .product-card__price-compare { margin-left: 8px; font-size: 0.875rem; color: #666; text-decoration: line-through; } .product-card__actions { padding: 0 15px 15px; background-color: white; } .product-card__add-to-cart, .product-card__sold-out { width: 100%; padding: 10px 15px; border: none; border-radius: 4px; font-size: 0.875rem; font-weight: 500; cursor: pointer; transition: background-color 0.2s; } .product-card__add-to-cart { background-color: #3182ce; color: white; } .product-card__add-to-cart:hover { background-color: #2c5282; } .product-card__sold-out { background-color: #e2e8f0; color: #4a5568; cursor: not-allowed; } </style>