v1.0.0.1
StocketBase
- <?php
-
- declare(strict_types=1);
-
- require_once __DIR__ . '/currency.php';
-
- function renderProductCard(array $product): string
- {
- $html = '<article class="product-card">';
- $html .= '<a href="' . htmlspecialchars(SiteFront::productUrl($product['slug']), ENT_QUOTES) . '">';
-
- if (!empty($product['cover_image_path'])) {
- $html .= '<img src="' . htmlspecialchars($product['cover_image_path']) . '" alt="" class="product-card-image">';
- }
-
- $html .= '<div class="product-card-body">';
-
- if (!empty($product['category_name'])) {
- $html .= '<span class="product-card-category">' . htmlspecialchars($product['category_name']) . '</span>';
- }
-
- $html .= '<h3>' . htmlspecialchars($product['title']) . '</h3>';
- $html .= '<p>' . htmlspecialchars($product['excerpt']) . '</p>';
-
- if (!empty($product['price_cents'])) {
- $html .= '<span class="product-card-price">' . htmlspecialchars(Currency::format((int) $product['price_cents'], (string) ($product['currency'] ?: 'USD'))) . '</span>';
- } elseif (!empty($product['billing_interval'])) {
- $html .= '<span class="product-card-price">' . htmlspecialchars(Language::get('product_subscription_label', 'Subscription')) . '</span>';
- }
-
- $html .= '</div></a></article>';
-
- return $html;
- }
-
- function renderFeaturedBanner(array $products): string
- {
- if (empty($products)) {
- return '';
- }
-
- $html = '<div class="featured-banner">';
- foreach ($products as $index => $product) {
- $sizeClass = $index === 0 ? ' featured-banner-item-large' : ' featured-banner-item-small';
- $html .= '<a class="featured-banner-item' . $sizeClass . '" href="' . htmlspecialchars(SiteFront::productUrl($product['slug']), ENT_QUOTES) . '">';
- if (!empty($product['cover_image_path'])) {
- $html .= '<img src="' . htmlspecialchars($product['cover_image_path']) . '" alt="">';
- }
- $html .= '<span class="featured-banner-title">' . htmlspecialchars($product['title']) . '</span>';
- $html .= '</a>';
- }
- $html .= '</div>';
-
- return $html;
- }
-