<?php if (!defined('STORE_ROOT')) { http_response_code(403); exit; }  $dualCards = []; try { $dualCards = 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 2", [':sid' => $storeId] ); } catch (\Throwable $e) {} foreach ($dualCards as &$dc) { $dc['title'] = Crypt::d($dc['name'] ?? ''); $dc['short_desc'] = Crypt::d($dc['notes'] ?? ''); $dc['image_url'] = $dc['image_path'] ?? ''; $dc['price'] = (float)Crypt::d($dc['base_price'] ?? '0'); $dc['sale_price'] = 0; $dc['display_price'] = $dc['price']; $dc['units'] = []; try { $dc['units'] = DB::all("SELECT id, unit_amount, unit_price FROM product_units WHERE product_id = :pid ORDER BY display_order ASC", [':pid' => (int)$dc['id']]); foreach ($dc['units'] as &$u) { $u['unit_amount'] = Crypt::d($u['unit_amount']); $u['unit_price'] = (float)Crypt::d($u['unit_price']); } unset($u); } catch (\Throwable $e) {} } unset($dc); if (empty($dualCards)) return; ?> <section id="row-cards-<?= $rowIdx ?>" class="sf-row sf-dual-cards" data-row-id="<?= (int)$row['id'] ?>">     <div class="sf-dual-cards-grid">         <?php foreach ($dualCards as $dc): $pid = (int)$dc['id']; $unitsJson = htmlspecialchars(json_encode($dc['units']), ENT_QUOTES); ?>         <article id="card-product-<?= $pid ?>" class="sf-wide-card" data-product-id="<?= $pid ?>" data-base-price="<?= $dc['display_price'] ?>" data-units="<?= $unitsJson ?>">             <div class="sf-wide-card-img">                 <?php if (!empty($dc['image_url'])): ?>                 <img src="<?= htmlspecialchars($dc['image_url']) ?>" alt="<?= htmlspecialchars($dc['title']) ?>">                 <?php else: ?>                 <div class="sf-card-img-empty"></div>                 <?php endif; ?>             </div>             <div class="sf-wide-card-body">                 <h3 class="sf-wide-card-title"><a href="?v=product&id=<?= $pid ?>" route="product"><?= htmlspecialchars($dc['title']) ?></a></h3>                 <p class="sf-wide-card-desc"><?= htmlspecialchars($dc['short_desc']) ?></p>                 <?php if (!empty($dc['units'])): ?>                 <div class="sf-unit-selector" data-pid="<?= $pid ?>">                     <?php foreach ($dc['units'] as $ui => $u): ?>                     <button class="sf-unit<?= $ui === 0 ? ' active' : '' ?>" data-unit-price="<?= $u['unit_price'] ?>"><?= htmlspecialchars($u['unit_amount']) ?></button>                     <?php endforeach; ?>                 </div>                 <?php endif; ?>                 <div class="sf-wide-card-footer">                     <span id="card-price-<?= $pid ?>" class="sf-card-price" data-base="<?= $dc['display_price'] ?>">$<?= number_format($dc['display_price'], 2) ?></span>                     <div class="sf-card-actions">                         <button class="sf-btn-cart sf-btn-sm" data-id="<?= $pid ?>">                             <svg width="14" height="14" 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" href="?v=checkout&id=<?= $pid ?>&qty=1" route="checkout">Purchase</a>                     </div>                 </div>             </div>         </article>         <?php endforeach; ?>     </div> </section>
