<?php if (!defined('STORE_ROOT')) { http_response_code(403); exit; }  $columns = (int)($rowConfig['columns'] ?? 4); $gridProducts = []; try { $gridProducts = DB::all( "SELECT id, name, image_path, base_price, notes FROM products WHERE store_id = :sid AND status = 'active' ORDER BY display_order ASC, id ASC LIMIT 8", [':sid' => $storeId] ); } catch (\Throwable $e) {} foreach ($gridProducts as &$gp) { $gp['title'] = Crypt::d($gp['name'] ?? ''); $gp['short_desc'] = Crypt::d($gp['notes'] ?? ''); $gp['image_url'] = $gp['image_path'] ?? ''; $gp['price'] = (float)Crypt::d($gp['base_price'] ?? '0'); $gp['sale_price'] = 0; $gp['display_price'] = $gp['price']; } unset($gp); if (empty($gridProducts)) return; $sectionTitle = $rowConfig['section_title'] ?? 'Browse Collection'; ?> <section id="row-grid-<?= $rowIdx ?>" class="sf-row sf-product-grid" data-row-id="<?= (int)$row['id'] ?>">     <div class="sf-section-header">         <span id="grid-title-<?= $rowIdx ?>" class="sf-section-title"><?= htmlspecialchars($sectionTitle) ?></span>     </div>     <div class="sf-grid sf-cols-<?= $columns ?>">         <?php foreach ($gridProducts as $gp): $pid = (int)$gp['id']; ?>         <article id="grid-product-<?= $pid ?>" class="sf-grid-card" data-product-id="<?= $pid ?>">             <div class="sf-grid-card-img">                 <?php if (!empty($gp['image_url'])): ?>                 <a href="?v=product&id=<?= $pid ?>" route="product"><img src="<?= htmlspecialchars($gp['image_url']) ?>" alt="<?= htmlspecialchars($gp['title']) ?>"></a>                 <?php else: ?>                 <div class="sf-card-img-empty"></div>                 <?php endif; ?>             </div>             <div class="sf-grid-card-body">                 <h3 class="sf-grid-card-title"><a href="?v=product&id=<?= $pid ?>" route="product"><?= htmlspecialchars($gp['title']) ?></a></h3>                 <span id="grid-price-<?= $pid ?>" class="sf-card-price">$<?= number_format($gp['display_price'], 2) ?></span>             </div>             <div class="sf-grid-card-actions">                 <div class="sf-qty-stepper sf-qty-sm" data-pid="<?= $pid ?>">                     <button class="sf-qty-btn" data-dir="-1">−</button>                     <span class="sf-qty-val" data-qty="1">1</span>                     <button class="sf-qty-btn" data-dir="1">+</button>                 </div>                 <button class="sf-btn-cart sf-btn-sm" data-id="<?= $pid ?>">                     <svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="9" cy="21" r="1"/><circle cx="20" cy="21" r="1"/><path d="M1 1h4l2.68 13.39a2 2 0 002 1.61h9.72a2 2 0 002-1.61L23 6H6"/></svg>                 </button>                 <a class="sf-btn-buy sf-btn-sm" href="?v=checkout&id=<?= $pid ?>&qty=1" route="checkout">Buy</a>             </div>         </article>         <?php endforeach; ?>     </div> </section>
