getMessage()); } return FluentCartAdapter::notice( __('This FluentCart element could not be rendered. Check plugin compatibility.', 'sparkcore-commerce'), 'broken' ); } } private static function renderLive(array $settings, string $mode): string { // Mini Cart is deliberately NOT one of CacheGuard::ROUTE_NO_CACHE_CONTEXTS // (see CacheGuard's own docblock, G0H): calling this is a documented // no-op for caching purposes. Kept here anyway so a future reviewer of // this render path sees, in one glance, that cache-safety was // considered and is handled below via a session-neutral shell instead // of route-level no-cache. CacheGuard::protectCustomerState('mini_cart'); $cartIcon = in_array(($settings['cart_icon'] ?? ''), ['cart', 'bag', 'bag-alt'], true) ? $settings['cart_icon'] : 'bag'; $showItemCount = in_array(($settings['show_item_count'] ?? ''), ['always', 'has_items', 'never'], true) ? $settings['show_item_count'] : 'has_items'; $showTotalPrice = !empty($settings['show_total_price']); $autoOpen = !empty($settings['auto_open_on_add']); $countMode = ($settings['count_mode'] ?? '') === 'total_quantity' ? 'total_quantity' : 'distinct_products'; $drawerPosition = ($settings['drawer_position'] ?? '') === 'left' ? 'left' : 'right'; $body = self::renderTrigger($cartIcon, $showItemCount, $showTotalPrice, $countMode); if ($mode === 'drawer') { $body .= self::renderDrawer(); } $wrapAttributes = CustomerStateHydrator::wrapAttributes(['mode' => $mode, 'auto_open' => $autoOpen]) . ' data-fcbd-mini-cart-count-mode="' . esc_attr($countMode) . '"' . ' data-fcbd-mini-cart-drawer-position="' . esc_attr($drawerPosition) . '"'; return '
' . $body . '
'; } /** * FluentCart's own trigger button, `MiniCartRenderer::renderMiniCart()` * (app/Services/Renderer/MiniCartRenderer.php:22-106), reused in BOTH * modes: its markup already carries the real * `data-fluent-cart-cart-expand-button` attribute FluentCart's own global * click-delegation listens for (FluentCartApp.js), so clicking it opens * whichever `[data-fluent-cart-cart-drawer]` exists on the page without * this fork needing to reimplement any open/close wiring of its own beyond * the a11y layer (assets/cart-hydration.js). * * Note this renderer emits a trigger BUTTON ONLY (verified live, * MiniCartRenderer.php:68-103: a single `