File manager - Edit - /home/webapp69.cm.in.th/u69319090028/Shop/views/components/product_card.php
Back
<?php /** * Unified Reusable Product Card Component * Strictly complies with Customer UX/UI System guidelines: * - Displays Product Image, Seller Badge, Product Name, Current Price, Original Price/Discount, Province, Wishlist Button * - NEVER displays Store Name or Seller Name inside the card * - Reusable across: Homepage, Search, Category, Store, Wishlist, Related Products */ $cardProduct = $product ?? $p ?? null; if (!$cardProduct) { return; } $productId = (int)$cardProduct['id']; $productName = e($cardProduct['name']); $productPrice = (float)$cardProduct['price']; $originalPrice = !empty($cardProduct['original_price']) ? (float)$cardProduct['original_price'] : null; $productSlug = e($cardProduct['slug'] ?? $productId); $province = e($cardProduct['province'] ?? 'กรุงเทพมหานคร'); $mainImage = product_image_url($cardProduct['main_image'] ?? $cardProduct['gallery_image'] ?? null); $stock = (int)($cardProduct['stock'] ?? 0); $isOutOfStock = ($stock <= 0); // Calculate discount percentage if original price is strictly greater than selling price $discountPercent = null; if ($originalPrice && $originalPrice > $productPrice) { $discountPercent = round((($originalPrice - $productPrice) / $originalPrice) * 100); } // Seller-selected badge (only if provided in database) $sellerBadge = !empty($cardProduct['badges']) ? e($cardProduct['badges']) : null; $isFavorited = !empty($cardProduct['is_favorited']) || (!empty($isWishlistPage)); ?> <div class="col"> <div class="cargoo-product-card h-100 position-relative"> <!-- Badges Container --> <div class="card-badge-container"> <?php if ($discountPercent): ?> <span class="badge-discount">-<?= $discountPercent ?>%</span> <?php endif; ?> <?php if ($sellerBadge): ?> <span class="badge-seller"><?= $sellerBadge ?></span> <?php endif; ?> </div> <!-- Favorite / Wishlist Action Button --> <button type="button" class="btn-wishlist-card <?= $isFavorited ? 'active text-danger' : '' ?>" data-product-id="<?= $productId ?>" title="บันทึกในรายการโปรด" aria-label="Add to wishlist"> <i class="bi <?= $isFavorited ? 'bi-heart-fill' : 'bi-heart' ?>"></i> </button> <!-- Product Image (Aspect Ratio 1:1) --> <a href="<?= url('/product/' . $productId) ?>" class="card-img-wrapper d-block text-decoration-none"> <img src="<?= $mainImage ?>" alt="<?= $productName ?>" loading="lazy"> <?php if ($isOutOfStock): ?> <div class="stock-overlay"> <span class="badge bg-dark px-2 py-1 small rounded-pill">สินค้าหมด</span> </div> <?php endif; ?> </a> <!-- Card Body Content --> <div class="card-content"> <a href="<?= url('/product/' . $productId) ?>" class="text-decoration-none"> <h6 class="product-title" title="<?= $productName ?>"><?= $productName ?></h6> </a> <!-- Pricing Row --> <div class="product-price-row"> <span class="current-price">฿<?= number_format($productPrice, 2) ?></span> <?php if ($originalPrice && $originalPrice > $productPrice): ?> <span class="original-price">฿<?= number_format($originalPrice, 2) ?></span> <?php endif; ?> </div> <!-- Metadata: Province Tag, Rating & Stock Indicator (NO STORE NAME) --> <div class="product-meta-row d-flex justify-content-between align-items-center"> <span class="text-truncate" style="max-width: 90px;"> <i class="bi bi-geo-alt me-1 text-muted"></i><?= $province ?> </span> <?php $cardRating = (float)($cardProduct['rating_avg'] ?? 0); $cardReviewCount = (int)($cardProduct['rating_count'] ?? 0); ?> <?php if ($cardRating > 0): ?> <span class="text-warning small d-inline-flex align-items-center gap-1" style="font-size: 0.72rem;"> <i class="bi bi-star-fill text-warning"></i> <span class="fw-bold text-dark"><?= number_format($cardRating, 1) ?></span> <span class="text-muted">(<?= $cardReviewCount ?>)</span> </span> <?php elseif ($stock > 0 && $stock <= 5): ?> <span class="text-warning" style="font-size: 0.7rem;">เหลือ <?= $stock ?> ชิ้น</span> <?php elseif ($stock > 0): ?> <span class="text-success" style="font-size: 0.7rem;"><i class="bi bi-check-circle-fill me-1"></i>พร้อมส่ง</span> <?php endif; ?> </div> </div> </div> </div>
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.23 |
proxy
|
phpinfo
|
Settings