# Kiến trúc theme Liquid Gennova

Theme điều khiển bố cục, tính năng và style của storefront. Code theme nằm trong cấu trúc thư mục chuẩn (Liquid + JSON + asset), không phải trong app runtime.

HTML công khai (sidebar + search): [https://docs.gennovadev.com/themes](https://docs.gennovadev.com/themes). Raw: `/themes.md`.

### Đọc nhanh

**Tổng quan**
- [Kiến trúc trang](#kien-truc-trang)
- [Asset, locale và cấu hình phụ](#asset-locale-va-cau-hinh-phu)
- [Cấu hình theme](#cau-hinh-theme)

**Cấu trúc theme**
- [Cấu trúc thư mục](#cau-truc-thu-muc)
- [Bản đồ template và section](#ban-do-template-va-section)
- [Tags và logic Liquid](#tags-va-logic-liquid)

**Objects & dữ liệu**
- [Objects có trên mọi trang](#objects-co-tren-moi-trang)
- [Truy cập collection theo id/slug](#truy-cap-collection-theo-idslug)
- [Object shop](#object-shop)
- [Object channel](#object-channel)
- [Objects theo từng template](#objects-theo-tung-template)
- [Object product và trang PDP](#object-product-va-trang-pdp)
- [Danh mục và phân trang](#danh-muc-va-phan-trang)
- [CMS và tìm kiếm](#cms-va-tim-kiem)
- [Menu, section settings và khách hàng](#menu-section-settings-va-khach-hang)

**Filters & media**
- [Filters Liquid](#filters-liquid)
- [Biến thể ảnh CDN và WebP](#bien-the-anh-cdn-va-webp)

**Thực hành**
- [Quy ước đặt tên](#quy-uoc-dat-ten)
- [Forms và hook giỏ hàng](#forms-va-hook-gio-hang)
- [Code mẫu](#code-mau)
  - [Section composition](#section-composition)
  - [Layout tối thiểu](#layout-toi-thieu)
  - [Menu linklists](#menu-linklists)
  - [Vòng lặp catalog](#vong-lap-catalog)
  - [PLP danh mục](#plp-danh-muc)
  - [Phân trang](#phan-trang)
  - [Card sản phẩm](#card-san-pham)
  - [PDP gallery và mua hàng](#pdp-gallery-va-mua-hang)
  - [PDP swatch biến thể](#pdp-swatch-bien-the)
  - [PDP license matrix](#pdp-license-matrix)
  - [Search / CMS / Forms / Giỏ](#search-results)
- [Quy ước Gennova](#quy-uoc-gennova)
- [Tài liệu liên quan](#tai-lieu-lien-quan)

---

## Kiến trúc trang

Mỗi trang storefront được ghép từ các lớp sau (thứ tự từ ngoài vào trong):

| Số | Thành phần | Mô tả |
|----|------------|--------|
| 1 | **Layout** | Nền trang: `layout/theme.liquid` (header, footer, `content_for_*`). Tuỳ chọn `layout/checkout.liquid` cho shell checkout. |
| 2 | **Template** | File trong `templates/**` quyết định nội dung theo loại trang (index, product, category, …). Thường mỏng: chỉ `{% section '…' %}`. |
| 3 | **Section** | File `sections/<slug>.json` — composition: danh sách partial + (tuỳ chọn) `settings` / `settings_definitions` cho merchant. |
| 4 | **Partial (snippet)** | File `partials/<name>.liquid` — khối HTML/Liquid tái sử dụng; gọi bằng `{% include 'name' %}`. |
| 5 | **Asset / locale / config** | CSS, JS, ảnh; chuỗi `| t`; `theme_settings` từ config. |

Tính năng giao diện (form, giỏ, swatch, SEO) viết bằng Liquid + CSS/JS trong layout, template, section và partial — không phụ thuộc cấu trúc app nền tảng.

### Placeholder layout

- `{{ content_for_header }}` — CSS/JS nền tảng + stylesheet asset theme; đặt trong `<head>` nếu layout có head.
- `{{ content_for_layout }}` — nội dung template/section đang render.
- `{{ content_for_footer }}` — thường rỗng; dành script cuối body nếu cần.

Checkout do nền tảng xử lý; theme có thể cung cấp `layout/checkout.liquid`, nếu thiếu thì fallback `layout/theme`.

---

## Asset, locale và cấu hình phụ

### `assets/`

Ảnh, CSS, JavaScript của theme. Tham chiếu:

```liquid
{{ 'custom.css' | asset_url | stylesheet_tag }}
{{ 'custom.js' | asset_url | script_tag }}
{{ media | asset_image_url: 'medium' }}
```

Khi publish theme lên Haravan / Theme Studio: **basename file trong `assets/` ≤ 36 ký tự** (kể cả đuôi), chỉ ASCII `a-z0-9-_.`.

### `locales/`

Chuỗi UI theo ngôn ngữ (`vi.json`, `en.json`). Trong Liquid:

```liquid
{{ 'nav.home' | t }}
```

---

## Cấu hình theme

| File | Vai trò |
|------|---------|
| `config/settings.json` | Schema cài đặt theme (typography, màu, layout, …) |
| `config/settings_data.json` | Giá trị merchant → object Liquid `theme_settings` |

Partial `theme-root-variables.liquid` thường map `theme_settings` sang CSS variables `--sf-*` trên `:root`.

Ví dụ key thường gặp: `typography_font_family`, `layout_container_width`, `layout_logo_image`, `section_hero_banner_heading`, …

Cài đặt theo khối (section) nằm trong JSON section (`settings` / `settings_definitions`), không bắt buộc đưa hết vào theme settings toàn cục.

---

## Cấu trúc thư mục

Theme phải dùng cấu trúc sau (theme mẫu populate `storefront_theme_basic`):

```text
.
├── assets/
├── config/
├── layout/
├── locales/
├── partials/
├── sections/
└── templates/
    ├── indexes/
    ├── product/
    ├── categories/
    ├── catalogs/
    ├── searches/
    ├── pages/
    ├── page/
    ├── blogs/
    ├── blog/
    ├── article/
    ├── carts/
    ├── checkouts/
    └── customers/
```

### `layout/`

File Liquid bọc toàn trang. Bắt buộc có `theme.liquid` để storefront chạy. Có thể khai báo đầy đủ `<!doctype html>`, `<head>`, `<body>` — xem [Thẻ Liquid Gennova](#the-liquid-gennova).

### `templates/`

Một (hoặc vài) template mỗi loại trang. Không có template khớp route thì trang đó không render được. Có thể thêm suffix: `templates/product/<suffix>.liquid` theo `template_suffix` (mặc định `default`).

### `sections/`

JSON composition. Ví dụ entry:

```json
{
  "kind": "partial",
  "partial": "home-hero",
  "settings": { "kicker": "", "tagline": "" },
  "settings_definitions": [
    { "key": "kicker", "value": "", "description": "…", "control": "text" },
    { "key": "tagline", "value": "", "description": "…", "control": "textarea" }
  ]
}
```

`control` hợp lệ: `text`, `textarea`, `number`, `checkbox`, `select` (+ `options`), `media`, `file`, `category`, `product`, `categories`, `linklist`. Giá trị vào `section.settings.<key>` trong partial tương ứng.

Legacy: `{ "kind": "section", "section": "hero-banner", "settings": { … } }` — vẫn inject `section.settings` vào `partials/hero-banner.liquid`.

Ưu tiên dữ liệu hero điển hình: **`section.settings` → `theme_settings` → `| t`**.

### `partials/`

Snippet Liquid. Không hiện riêng trong theme editor như section; dùng `{% include %}`.

### `config/`, `locales/`, `assets/`

Xem các mục Config và Supporting assets ở trên.

---

## Bản đồ template và section

| File template | Section / nội dung chính |
|---------------|--------------------------|
| `templates/indexes/indexes.liquid` | `home-storefront` |
| `templates/product/default.liquid` | `page-product` |
| `templates/categories/category.liquid` | `page-category` |
| `templates/categories/categories.liquid` | `page-categories-index` |
| `templates/catalogs/catalogs.liquid` | `page-catalog` |
| `templates/searches/searches.liquid` | `page-search` |
| `templates/pages/pages.liquid` | `page-content-index` |
| `templates/page/default.liquid` | `page-content` |
| `templates/page/contact.liquid` | `page-contact` |
| `templates/page/privacy-policy.liquid` | `page-policy` |
| `templates/page/newsletter-confirm.liquid` | `page-newsletter-confirm` |
| `templates/blogs/blogs.liquid` | `page-blogs-index` |
| `templates/blog/default.liquid` | `page-blog` |
| `templates/article/default.liquid` | `page-article` |
| `templates/carts/carts.liquid` | `page-cart` |
| `templates/customers/*.liquid` | Khung tài khoản / đơn |

Trang chủ mẫu: `sections/home-storefront.json` liệt kê các partial (hero, slider, sản phẩm nổi bật, trust, reviews, …). Landing riêng có thể thay composition (ví dụ `home-gennova-*`) mà không đổi kiến trúc thư mục.

---

## Tags và logic Liquid

### Cú pháp chung (liquidjs)

Output `{{ }}`, logic `{% %}`. Hỗ trợ `if` / `unless` / `case` / `for` / `assign` / `capture` / `comment` / `raw`, toán tử `==`, `!=`, `>`, `<`, `or`, `and`, `contains`. `forloop`: `index`, `first`, `last`, `length`.

### `{% section 'slug' %}`

Gọi composition `sections/slug.json`. Ví dụ trong layout: `theme-root-variables`, `layout-header`, `layout-footer`, slot `layout-slot-*`, `sf-storefront-cart`, `sf-captcha-runtime`. Trang chủ: `{% section 'home-storefront' %}`.

### `{% include 'partial-name' %}`

File `partials/partial-name.liquid` (không ghi đuôi trong thẻ). Truyền tham số:

```liquid
{% include 'card-product', product: p, featured_image_priority: true %}
{% include 'sf-pagination', paginate: storefront_category.paginate, base_path: pagination_base, item_t: 'pagination.count_products' %}
{% include 'sf-tag-filter-links', tags: product.tags, tag_filter_base: '/products' %}
```

Theme seed chủ yếu dùng `include` (`render` có thể có tùy phiên bản engine).

### `<head>` trong layout

Khi `layout/theme.liquid` khai báo `<head>` thật:

- `<title>`, `<meta>`, `<link>` (không phải stylesheet) được đưa vào head trang.
- Stylesheet / `<style>` / `<script>` trong head vẫn chạy, giữ thứ tự (đặt đầu body nếu nền tảng tách shell).
- Thẻ theme đã viết thì thắng; thẻ thiếu (title, description, canonical, `og:*`, icon, …) nền tảng bổ sung từ `page_title`, `page_description`, `canonical_url`.
- Thuộc tính `<body>` (`class`, `id`, `data-*`, …) gắn lên `div[data-sf-theme-body]` — CSS nên nhắm class đó, không giả định `body.xxx` thuần.
- `<head>` viết trực tiếp trong `layout/theme.liquid`, không đặt trong `include`.

```liquid
<!doctype html>
<html>
<head>
  <title>{{ page_title | escape }}</title>
  <meta name="description" content="{{ page_description | escape }}">
  <link rel="canonical" href="{{ canonical_url }}">
  {{ 'custom.css' | asset_url | stylesheet_tag }}
  {{ content_for_header }}
</head>
<body class="template-{{ template }}">
  …
  {{ content_for_layout }}
  …
</body>
</html>
```

### Form hệ thống

```liquid
{% form 'contact' %} … {% endform %}
{% form 'newsletter' %} … {% endform %}
{% form 'review' %} … {% endform %}
```

Chi tiết `id` / `name` / endpoint: [Forms và hook giỏ](#forms-va-hook-gio).

---

## Objects có trên mọi trang

Mọi key context là **snake_case** (kể cả nested). Ảnh đại diện: `featured_media` (không `featuredMedia`).

Các key sau luôn có trong context (builder `buildStorefrontLiquidContext`). Trang cụ thể có thể **ghi đè** hoặc **bổ sung** thêm key — xem [Objects theo template](#objects-theo-template).

| Key | Kiểu | Ý nghĩa | Ghi chú |
|-----|------|---------|---------|
| `shop` | object | Shop công khai | Xem [shop](#shop) |
| `channel` | object | Kênh storefront hiện tại | Xem [channel](#channel) |
| `form_captcha` | object | CAPTCHA form | `{ provider, site_key, recaptcha_v3_min_score }` — trùng `shop.settings.storefront_form_captcha` |
| `products` | array + lookup | Danh sách SP | Mặc định `[]`; trang chủ / catalog ghi đè; `[id]` / `['handle']` — xem [Truy cập số nhiều](#truy-cap-so-nhieu-theo-idslug) |
| `categories` | array + lookup | Nav / cây danh mục | Node category rút gọn; `[id]` / `['slug']` |
| `pages` | array + lookup | Trang CMS | Mặc định `[]`; `[id]` / `['handle']` |
| `blogs` | array + lookup | Blog | Mặc định `[]`; `[id]` / `['handle']` |
| `articles` | array + lookup | Bài viết | Mặc định `[]`; `[id]` / `['handle']` |
| `page_title` | string | Tiêu đề SEO | |
| `page_description` | string | Mô tả SEO / tagline | |
| `canonical_url` | string | URL tuyệt đối (hoặc path) | |
| `language` | string | Mã ngôn ngữ active | vd. `vi` |
| `languages` | array | `[{ code }]` | |
| `payment_currency` | string | Mã tiền khách đang xem | **API công khai** — dùng với `\| money:` |
| `payment_currencies` | array | `[{ code }]` | |
| `channels` | array | Luôn `[]` hiện tại | Reserved |
| `customer` | object\|null | Khách đăng nhập | null nếu chưa login |
| `cart` | null | **Luôn `null` trong Liquid SSR** | Giỏ = island JS / BFF; đừng kỳ vọng `cart.item_count` |
| `request` | object | Request hiện tại | `path`, `origin`, `locale_path_prefix` |
| `template` | string | Key template | vd. `index`, `product`, `category` |
| `content_for_header` | string | HTML CSS/JS inject | Đặt trong `<head>` |
| `content_for_footer` | string | Thường `""` | Script cuối body |
| `content_for_layout` | string | Nội dung trang | Inject khi render layout |
| `show_theme_debug` | boolean | Mặc định `false` | |
| `alerts` | array | Mặc định `[]` | |
| `current_year` | number | Năm hiện tại | |
| `support_email` | string | Email hỗ trợ nền tảng | |
| `linklists` | object | Menu theo handle | `linklists['main-menu']` — xem [linklists](#linklists-section-theme_settings-customer) |
| `promotions` | array + lookup | Promo highlight shop | `[id]` / `['code']` nếu có |
| `theme_settings` | object | Từ `config/settings_data.json` | |

**Không dùng trong theme production:** `__context` (dump nội bộ channel/theme assets).

```liquid
<title>{{ page_title | escape }}</title>
<meta name="description" content="{{ page_description | escape }}">
<link rel="canonical" href="{{ canonical_url }}">
<p>{{ 'footer.year' | t }} {{ current_year }}</p>
```

---

## Truy cập collection theo id/slug

Các root số nhiều FE inject vào context vừa **lặp được** (`{% for %}`) vừa **tra theo khóa** kiểu Shopify/Haravan: `SốNhiều[id]` hoặc `SốNhiều['slug']` / `SốNhiều['handle']`.

| Root | Khóa lookup | Ghi chú |
|------|-------------|---------|
| `categories` | `id`, `slug` | Nav ~48 danh mục; mỗi node có `products` (mảng, **tối đa 24**) |
| `products` | `id`, `handle` | Chỉ SP đã inject vào trang (không phải full catalog) |
| `pages` | `id`, `handle` | CMS pages trên trang |
| `blogs` | `id`, `handle` | Index blog kênh; mỗi node có `articles` (mảng, **tối đa 24**) |
| `articles` | `id`, `handle` | |
| `promotions` | `id`, `code` | `code` khi API gửi |
| `linklists` | `handle` | Object map sẵn — không phải array |

Phạm vi: **node đã có trong context trang** (ví dụ `categories` nav gần như mọi trang; `products` / CMS theo list route). Không có `collections` (Gennova dùng `categories`). Không có `all_products` shop-wide trong SSR.

`{% for cat in categories %}` vẫn chạy. Alias tường minh: `categories.all` (mảng gốc). Key thiếu → falsy. Áp dụng mọi template (kể cả CMS `page`).

Nested Shopify-like (mọi template, kể cả `page`):

- `categories['slug'].products` — mảng phẳng (card PLP), **cap 24** (đủ `{% for p in … limit: n %}` featured). PLP phân trang đầy đủ vẫn dùng `storefront_category.products`.
- `blogs['handle'].articles` — mảng phẳng bài (meta/excerpt; không body nặng), **cap 24**.

Khi dump ra JS: dùng `{{ x | default: nil | json }}` — miss không được để trống (gây `console.log("x",);` lỗi cú pháp).

```liquid
{% assign featured = categories['ao-thun'] %}
{% if featured %}
  <a href="/categories/{{ featured.slug }}">{{ featured.title }}</a>
{% endif %}

{% if featured.products.size > 0 %}
  {% for p in featured.products limit: 8 %}
    {% include 'card-product', product: p %}
  {% endfor %}
{% endif %}

{% assign news = blogs['news'] %}
{% for a in news.articles limit: 6 %}
  <a href="/blogs/{{ news.handle }}/{{ a.handle }}">{{ a.title }}</a>
{% endfor %}

{% assign by_id = categories[section.settings.category_id] %}
{% assign p = products['blue-tee'] %}
{% assign about = pages['about'] %}
{% assign post = articles['welcome'] %}
{% assign main_menu = linklists['main-menu'] %}
```

---

## Object shop

| Key | Kiểu | Ý nghĩa |
|-----|------|---------|
| `shop.id` | number\|null | Shop id |
| `shop.name` | string | Tên hiển thị |
| `shop.logo` | string\|null | URL logo (alias) |
| `shop.logo_url` | string\|null | URL logo — ưu tiên trong theme |
| `shop.website` | string\|null | Website shop |
| `shop.currency` | string\|null | Đồng **lưu giá** catalog |
| `shop.language` | string\|null | Ngôn ngữ chính shop |
| `shop.default_locale` | string\|null | Locale catalog kênh |
| `shop.channel_locales` | array | `[{ lang_code, is_default }]` |
| `shop.default_payment_currency` | string\|null | Đồng thanh toán mặc định kênh |
| `shop.payment_currency_base` | string\|null | Đồng gốc thanh toán |
| `shop.channel_payment_currencies` | array | `[{ currency_code, is_default, symbol, name }]` |
| `shop.storefront_commerce_enabled` | boolean | Bật giỏ / mua trên storefront |
| `shop.settings.storefront_form_captcha` | object | Cùng shape `form_captcha` |

```liquid
<img src="{{ shop.logo_url | asset_image_url: 'small' }}" alt="{{ shop.name | escape }}">
{{ product.price_sale | money: payment_currency }}
```

---

## Object channel

| Key | Kiểu | Ý nghĩa |
|-----|------|---------|
| `channel.shop_id` | number | Tenant shop |
| `channel.channel_id` | number | Id kênh |
| `channel.source` | string | Nguồn resolve host |
| `channel.channel_code` | string | Mã kênh |
| `channel.channel_name` | string | Tên kênh |
| `channel.channel_title` | string | Tiêu đề hiển thị |
| `channel.commerce_enabled` | boolean | Trùng hiệu lực `shop.storefront_commerce_enabled` |
| `channel.deposit_enabled` | boolean | Bật cọc |
| `channel.deposit_percent` | number\|null | % cọc |
| `channel.payos_checkout_mode` | string | `legacy` \| `deposit_first` |
| `channel.checkout_settings` | object | Chính sách checkout (bảng dưới) |
| `channel.reviews_enabled` | boolean | Cho phép gửi đánh giá |
| `channel.reviews` | array | Sample đánh giá kênh |
| `channel.review_count` | number | Số đánh giá |
| `channel.review_average_rating` | number\|null | Điểm TB |
| `channel.openai_ads_pixel_id` | string\|null | Ads |
| `channel.openai_ads_debug` | boolean\|null | |
| `channel.openai_ads_user` | string\|null | |
| `channel.google_ads_pixel_id` | string\|null | |
| `channel.google_ads_debug` | boolean\|null | |
| `channel.facebook_ads_pixel_id` | string\|null | |
| `channel.facebook_ads_debug` | boolean\|null | |

### `channel.checkout_settings` (snake_case)

| Key | Ý nghĩa |
|-----|---------|
| `customer_accounts` | `optional` \| `disabled` \| `required_before_checkout` |
| `email_collect` | `optional` \| `required_for_order` |
| `abandoned_checkout_reminder` | `off` \| `after_6h` \| `after_24h` |
| `local_pickup_enabled` | boolean |
| `local_pickup_branch_ids` | array id |
| `local_pickup_branches` | `[{ id, name, code }]` |
| `delivery_enabled` | boolean |
| `home_delivery_enabled` | boolean |
| `home_delivery_carrier_whitelist_ids` | array id |
| `default_home_carrier_id` | number\|null |
| `effective_default_home_carrier_id` | number\|null |
| `require_carrier_for_home` | boolean |
| `delivery_mode_choice_offered` | boolean |
| `customer_order_cancel_before_carrier_enabled` | boolean |
| `payment_methods_enabled` | boolean |
| `payment_method_whitelist_ids` | array id |
| `default_payment_method_id` | number\|null |

```liquid
{% assign commerce_on = shop.storefront_commerce_enabled %}
{% if channel.commerce_enabled == false %}
  {% assign commerce_on = false %}
{% endif %}
{% if commerce_on %}
  <button type="button" data-sf-add-to-cart data-product-item-id="{{ row.id }}">
    {{ 'product.add_to_cart' | t }}
  </button>
{% else %}
  <p class="text-sm text-[color:var(--sf-text-muted)]">Chỉ xem catalog.</p>
{% endif %}

{% assign co = channel.checkout_settings %}
{% if co and co.local_pickup_enabled and co.delivery_mode_choice_offered %}
  <p>{{ 'checkout.pickup_or_delivery' | t }}</p>
{% endif %}
```

---

## Objects theo từng template

| `template` / trang | Key bổ sung (root) |
|--------------------|--------------------|
| `index` (trang chủ) | `products`, `featured_products_paginate`, `categories`, `pages`, `blogs`, `articles`, có thể `review_submit_target` |
| `product` (PDP) | `product`, `items`, `variants`, `product_items`, `pdp_gallery?`, `promotions_highlight`, `related_products`, `review_submit_target?`, `product_json_ld_json?`, `categories` |
| `category` (PLP) | `storefront_category`, `review_submit_target?` |
| `categories` | `categories`, `paginate` |
| `catalog` (`/products`) | `products`, `paginate`, `current_tags`, `tag_match`, `products_tag_base_path`, `catalog_pagination_base` |
| `pages` (index CMS) | `cms_pages`, `paginate`, `current_tags`, `tag_match`, `pages_pagination_base` |
| `page` | `page`, `pages`, `related_pages`, `review_submit_target?` |
| `blogs` | `blogs`, `blogs_paginate`, `current_tags`, `tag_match`, `blogs_pagination_base` |
| `blog` | `blog`, `articles`, `articles_paginate`, tags/base, `review_submit_target?` |
| `article` | `blog`, `article`, `articles`, `related_articles`, `review_submit_target?` |
| `search` | `search_query`, `mode`, `search_results` |
| `cart` | *(không populate `cart` Liquid — UI React)* |
| `customers` / account | `customer`, `orders`, `order`, `account_auth_endpoints` (+ `order_public_checkout_token` trên trang đơn công khai) |

Tag filter query: `tags` (lặp hoặc CSV), `tagMatch` = `ALL` (mặc định) \| `ANY` trên `/products`, `/pages`, `/blogs`, `/blogs/:handle`.

---

## Object product và trang PDP

### `product` (node / PDP)

| Key | Kiểu | Ý nghĩa |
|-----|------|---------|
| `id` | number | |
| `name`, `title` | string | Tên |
| `handle` | string | Slug URL |
| `url` | string | Path PDP |
| `description` | string | Mô tả |
| `description_seo` | string | SEO |
| `description_json` | array | Block rich text (PDP) — `{ id, type, data, sort_order }` |
| `sku`, `barcode` | string | |
| `price`, `price_sale`, `price_sale_combo` | number | Giá số |
| `price_min`, `price_max`, `price_sale_min`, `price_sale_max` | number | Khoảng giá |
| `price_display`, `price_sale_display`, `price_sale_combo_display` | string | Chuỗi đã format theo đồng hiển thị |
| `display_payment_currency` | string | Đồng của bản display |
| `is_combo` | boolean | |
| `is_publish` | boolean | |
| `published_at` | string\|null | |
| `sales_live` | boolean | |
| `is_available`, `available_for_purchase` | boolean | |
| `track_inventory`, `allow_backorder` | boolean | |
| `quantity_available` | number\|null | |
| `template_suffix` | string\|null | |
| `featured_media` | object\|null | `{ id, type, url, alt, image_variant_urls }` |
| `media` | array | Cùng shape media |
| `tags` | array string | ShopTag |
| `review_average_rating`, `review_count` | number | |
| `reviews` | array | `{ id, rating, title, body, author_name, created_at }` |

### Root siblings trên PDP (không nằm trong `product`)

| Key | Ý nghĩa |
|-----|---------|
| `product_items` / `items` | Dòng bán: `id`, `variant_id`, `quantity`, `price`, `price_sale`, `is_combo_self`, `variant`, `*_display` |
| `variants` | Biến thể: `id`, `name`, `title`, `sku`, `price`, `price_sale`, availability, `attributes`, media |
| `pdp_gallery` | `[{ product_item_id, slides: [{ grande_url, small_url, alt }] }]` (legacy short `i`/`g`/`s`/`a` đã bỏ khỏi API; JS seed vẫn dual-read) |
| `promotions_highlight` | Promo gắn PDP |
| `related_products` | `{ nodes, recipe, explain }` |
| `product_json_ld_json` | Chuỗi JSON-LD |
| `review_submit_target` | `{ entity, entity_id }` — thường `ShopProduct` |

```liquid
<h1>{{ product.title | default: product.name | escape }}</h1>
{% if product.featured_media %}
  <img
    src="{{ product.featured_media | asset_image_url: 'grande' }}"
    alt="{{ product.featured_media.alt | default: product.title | escape }}"
    loading="eager"
    decoding="async"
  >
{% endif %}
<p>{{ product.price_sale | money: payment_currency }}</p>
{% for row in product_items %}
  <button type="button" data-sf-add-to-cart data-product-item-id="{{ row.id }}">
    {{ row.variant.title | default: row.variant.name | escape }}
  </button>
{% endfor %}
```

---

## Danh mục và phân trang

### `storefront_category` (PLP)

| Key | Ý nghĩa |
|-----|---------|
| `category` | Node danh mục |
| `products` | Mảng product list node |
| `product_filters_pending` | Cờ UI bộ lọc |
| `paginate` | Object phân trang |

### `category` (node)

| Key | Ý nghĩa |
|-----|---------|
| `id`, `name`, `title`, `slug`, `code` | Định danh |
| `description`, `position` | |
| `image` | `{ url, alt }` |
| `filters` | Bộ lọc (nếu có) |
| `updated_at` | |
| `review_average_rating`, `review_count`, `reviews` | Trên PLP khi có |

### `paginate` (Gennova — không phải tag Shopify)

| Key | Ý nghĩa |
|-----|---------|
| `page` | Trang hiện tại (1-based) |
| `page_size` / `limit` | Kích thước trang |
| `offset` | Offset |
| `total_count` | Tổng bản ghi |
| `total_pages` | Tổng trang |
| `has_next_page`, `has_prev_page` | |

Cùng shape: `featured_products_paginate`, `blogs_paginate`, `articles_paginate`, và `paginate` trên catalog/CMS.

```liquid
{% assign category_slug = storefront_category.category.slug | default: '' %}
{% assign pagination_base = '/categories/' | append: category_slug %}
{% include 'sf-pagination', paginate: storefront_category.paginate, base_path: pagination_base, item_t: 'pagination.count_products' %}
```

Khi URL đã có query (`catalog_pagination_base` chứa `?tags=`…): snippet nối `&page=` thay vì `?page=`.

---

## CMS và tìm kiếm

### `page`

`id`, `handle`, `title`, `body`, `description_seo`, `template_suffix`, `featured_media`, `media`, `updated_at`, `tags` (+ reviews khi query).

### `blog`

`id`, `handle`, `title`, `description`, `description_seo`, `template_suffix`, media, `updated_at`, `tags`.

### `article`

`id`, `blog_handle`, `handle`, `title`, `excerpt`, `body`, `author_name`, `published_at`, `template_suffix`, media, `updated_at`, `tags` (+ `tag_links` / `tagLinks` nếu API gửi).

Index: `cms_pages` (pages index), `blogs`, `articles`. Related: `related_pages` / `related_articles` = `{ nodes, recipe, explain }`.

Gallery: `{% include 'sf-cms-media-gallery', cms_entity: page, alt_title: page.title %}`.

### `search_results`

| Key | Ý nghĩa |
|-----|---------|
| `search_query` | Chuỗi `q` |
| `mode` | Chế độ tìm |
| `search_results` | `{ query, mode, products, pages, articles, blogs }` — mỗi nhóm `{ nodes, paginate }` |

---

## Menu, section settings và khách hàng

### `linklists`

Map `handle → { id, handle, title, links[] }`.

Mỗi `link`: `title`, `url`, `type`, `object_type`, `active`, `links[]` (con), `object` (payload đích hoặc null).

```liquid
{% assign main_menu = linklists['main-menu'] %}
{% if main_menu and main_menu.links %}
  <ul role="list">
    {% for link in main_menu.links %}
      <li>
        <a href="{{ link.url }}" class="{% if link.active %}font-semibold{% endif %}">{{ link.title }}</a>
      </li>
    {% endfor %}
  </ul>
{% endif %}
```

### `section` (chỉ khi render partial trong composition)

| Key | Ý nghĩa |
|-----|---------|
| `section.type` | Slug partial |
| `section.settings` | Settings khối (từ JSON section) |

Ưu tiên dữ liệu hero: `section.settings` → `theme_settings` → `| t`.

### `theme_settings`

Object tự do từ `config/settings_data.json` (đã snake_case). Ví dụ: `typography_font_family`, `layout_container_width`, `layout_logo_image`, `product_show_related`, `product_related_limit`, …

### `customer` (khi đăng nhập)

`id`, `email`, `name`, `first_name`, `last_name`, `phone`, `orders_count`, `two_factor_enabled`, `shipping_addresses[]`, `billing_addresses[]`, `profile_address`.

### Account extras

| Key | Ý nghĩa |
|-----|---------|
| `orders` / `order` | Danh sách / chi tiết đơn |
| `account_auth_endpoints` | `{ login, register, otp_request, second_factor, session }` |
| `order_public_checkout_token` | Token trang đơn công khai |

### `form_captcha`

| Key | Ý nghĩa |
|-----|---------|
| `provider` | `none` \| `turnstile` \| `recaptcha_v2` \| `recaptcha_v3` |
| `site_key` | Public site key |
| `recaptcha_v3_min_score` | number\|null |

### `request`

| Key | Ý nghĩa |
|-----|---------|
| `request.path` | Path có locale (vd. `/vi/products?page=2`) |
| `request.origin` | `https://shop-domain` |
| `request.locale_path_prefix` | Prefix locale |

---

## Filters Liquid

Filter **đăng ký trên engine storefront** (liquidjs). `strictFilters: false` — filter lạ không làm vỡ trang.

| Filter | Chữ ký | Hành vi |
|--------|--------|---------|
| `asset_url` | `(path)` | CDN / `/theme-assets/…`; `storefront-tailwind.css` → path nền tảng |
| `stylesheet_tag` | `(href, fetchPriority?)` | `<link>`; `high`/`low` → fetchpriority; `async`/`defer` → media print swap |
| `script_tag` | `(src)` | `<script defer>` |
| `asset_image_url` | `(input, variant?)` | Media object hoặc path theme; prefer WebP CDN; mặc định variant `original` |
| `img_url` / `image_url` | `(input, size?)` | Alias resize / CDN preset |
| `money` | `(amount, currency?)` | Format tiền; mặc định VND → `vi-VN` + `₫` |
| `t` / `translate` | `(key)` | Dot-path `locales/{lang}.json`; thiếu → trả lại key |
| `status_vi` | `(input, scope?)` | Nhãn trạng thái tiếng Việt |
| `qrcode` | `(input, size?)` | `<img>` data-URL QR (async) |
| `barcode` | `(input, format?)` | `<img>` barcode (CODE128 mặc định) |

**Không có trên engine storefront:** `catalog_media_image_url` (deprecated, đừng dùng), `{% paginate %}` tag Shopify, `powered_by_link`, `link_to_tag`, `money_with_currency`, `img_tag`, …

### liquidjs builtins thường dùng

`default`, `escape`, `strip_html`, `strip`, `upcase`, `downcase`, `capitalize`, `append`, `prepend`, `slice`, `truncate`, `split`, `join`, `size`, `first`, `last`, `json`, `date`, `plus`, `minus`, `times`, `divided_by`, `url_encode`, `where`, `map`, `uniq`, …

```liquid
{{ 'custom.css' | asset_url | stylesheet_tag }}
{{ 'nav.home' | t }}
{{ product.price_sale | money: payment_currency }}
{{ product.featured_media | asset_image_url: 'medium' }}
```

---

## Biến thể ảnh CDN và WebP

Sau upload, nền tảng giữ file gốc và sinh side-car. Media có `image_variant_urls`:

```json
{
  "small": "…/hash_small.jpg",
  "small_webp": "…/hash_small.webp",
  "medium": "…/hash_medium.jpg",
  "medium_webp": "…/hash_medium.webp",
  "grande": "…/hash_grande.jpg",
  "grande_webp": "…/hash_grande.webp",
  "larger": "…/hash_larger.jpg",
  "larger_webp": "…/hash_larger.webp"
}
```

| Quy tắc | Chi tiết |
|---------|----------|
| Prefer WebP | Engine chọn `{preset}_webp` rồi `{preset}`; thiếu → `.url` gốc |
| `asset_image_url` | Đã apply rule — **không** hardcode `.webp` trong theme |
| LCP / OG | `asset_image_url: 'grande'` / `'larger'`, không `media.url` thô |

```liquid
{% if product.featured_media %}
  <img
    src="{{ product.featured_media | asset_image_url: 'medium' }}"
    srcset="{{ product.featured_media | asset_image_url: 'small' }} 320w,
            {{ product.featured_media | asset_image_url: 'medium' }} 640w,
            {{ product.featured_media | asset_image_url: 'grande' }} 1280w"
    sizes="(max-width: 640px) 100vw, 320px"
    alt="{{ product.featured_media.alt | default: product.title | escape }}"
    loading="lazy"
    decoding="async"
  >
{% endif %}
```

---

## Quy ước đặt tên

### Changelog key PDP (gallery / matrix)

- **API `pdp_gallery`:** chỉ còn `product_item_id`, `slides[].grande_url` / `small_url` / `alt`. Short `i`/`g`/`s`/`a` **không còn emit**.
- **Matrix `#sf-pdp-matrix-json`:** chỉ còn `product_item_id`, `max_channels`, `max_branches`, `max_warehouses`, `is_available`. Short `i`/`c`/`b`/`w`/`o` **không còn emit** từ theme seed.
- Seed JS dual-read legacy short keys để theme/merchant cũ vẫn chạy tạm.
- `_h_*` / `_mx_*` vẫn chỉ là `{% assign %}` local — không phải API/DB.


| Loại | Quy tắc | Ví dụ |
|------|---------|--------|
| **Public API (context)** | snake_case, document trên trang này | `payment_currency`, `shop.currency`, `product.featured_media`, `storefront_category` |
| **Biến cục bộ `_`** | Chỉ trong partial; không phải hợp đồng engine | `_h_line`, `_mx_mc` trong PDP seed — OK giữ |
| **`sf_` / `sf_pdp_`** | Hợp đồng theme ↔ JS storefront | `data-sf-add-to-cart`, `sf_pdp_default_pi` |
| **Cấm** | Key context bắt đầu bằng `_` từ engine | Không inject `_pay_ccy` vào context |

### Tiền tệ — API vs alias snippet

**Dạy / dùng trong docs và theme mới:**

```liquid
{{ product.price_sale | money: payment_currency }}
{{ product.price | money: shop.currency }}
```

Snippet `sf-currency-resolve` **chỉ** tạo biến cục bộ sau `{% include %}` (scope cha bị share vì `include`):

- `_shop_ccy` ← `shop.currency` (đồng lưu giá)
- `_pay_ccy` ← `payment_currency` (đồng khách xem)

Đó **không** phải object gốc. Prefer gọi thẳng `payment_currency` khi viết code mới.

---

## Forms và hook giỏ hàng

Storefront tự bắt submit khi markup đúng hợp đồng — **không** gắn `onsubmit` trong theme.

### Contact / newsletter / review

| Form | `id` form | Endpoint |
|------|-----------|----------|
| contact | `storefront-form-contact` | `POST /forms/contact` |
| newsletter | `storefront-form-newsletter` | `POST /forms/newsletter` |
| review | `storefront-form-review` | `POST /forms/review` |

Alert: `#contact-form-alert` / `#newsletter-form-alert` / `#review-form-alert`.

**Contact:**

```liquid
<div id="contact-form-root">
  <div id="contact-form-alert" class="hidden" role="status" aria-live="polite"></div>
  {% form 'contact' %}
    <input id="contact-name" name="name" type="text" required maxlength="255" />
    <input id="contact-email" name="email" type="email" required maxlength="255" />
    <input id="contact-phone" name="phone" type="tel" maxlength="50" />
    <textarea id="contact-message" name="message" required maxlength="20000"></textarea>
    <button type="submit" id="contact-submit">{{ 'contact.form_send' | t }}</button>
  {% endform %}
</div>
```

**Newsletter:** `#newsletter-email` (`name="email"`), `#newsletter-name`, `#newsletter-consent` (`consent`), `#newsletter-submit`.

**Review — field bắt buộc:**

| `id` | `name` |
|------|--------|
| `#review-rating` | `rating` |
| `#review-title` | `title` |
| `#review-name` | `name` |
| `#review-email` | `email` |
| `#review-message` | `message` |

Hidden `entity` / `entityId` từ `review_submit_target` hoặc suy từ `template` + object (`ShopProduct`, `ShopPage`, `ShopArticle`, `ShopBlog`, `ShopChannel`, `ShopProductCategory`). Theme mẫu: `{% include 'sf-storefront-reviews' %}`. Một trang chỉ **một** `id="storefront-form-review"`.

CAPTCHA: section `sf-captcha-runtime` → `window.gennovaStorefrontGetCaptchaToken(form)`.

### GraphQL đánh giá (tuỳ chọn UI động)

- `storefrontReviewSummary(entity, entityId)` → `{ averageRating, reviewCount }`
- `storefrontReviews(entity, entityId, first, offset)` → list review

### Hook giỏ / PDP (`data-sf-*`)

- `#sf-pdp-purchase`, `data-sf-cart-line`, `data-sf-license-matrix`
- `data-sf-add-to-cart` + `data-product-item-id` (combo: `data-is-combo`, `data-product-id`)
- `data-sf-cart-qty`
- `#sf-pdp-matrix-json` rows: `{ product_item_id, max_channels, max_branches, max_warehouses, is_available }` (JS dual-read legacy `i`/`c`/`b`/`w`/`o`); UI dims vẫn `data-sf-dim="c|b|w"`
- `.sf-pdp-panel` + `data-panel-for`
- Quick view: `<template id="sf-qv-pid-{{ product.id }}">`

JSON-LD: `{% include 'sf-product-jsonld' %}` (`product_json_ld_json`).

---

## Code mẫu

Cookbook copy-paste. Mỗi recipe rút gọn từ seed `storefront_theme_basic` (`partials/…` / `sections/…`). Object snake_case; không Shopify `{% paginate %}` / `collections`.

### Section composition

Template route chỉ gọi composition; JSON liệt kê partial:

```liquid
{%- comment -%} templates/categories/category.liquid {%- endcomment -%}
{% section 'page-category' %}
```

```json
{
  "version": 1,
  "name": "Trang danh mục",
  "partials": [
    {
      "kind": "partial",
      "partial": "page-category",
      "settings": {},
      "settings_definitions": []
    }
  ]
}
```

Trang chủ: `{% section 'home-storefront' %}` + `sections/home-storefront.json` (`kind: "section"|"partial"`). Seed: `sections/page-category.json`, `sections/home-storefront.json`.

### Layout tối thiểu

```liquid
<head>
  <title>{{ page_title | escape }}</title>
  {% if page_description %}
  <meta name="description" content="{{ page_description | escape }}">
  {% endif %}
  {{ content_for_header }}
</head>
<body>
  {% section 'theme-root-variables' %}
  {% section 'layout-header' %}
  <main>{{ content_for_layout }}</main>
  {% section 'layout-footer' %}
  {% section 'sf-storefront-cart' %}
  {% section 'sf-product-quick-view' %}
  {% section 'sf-captcha-runtime' %}
  {{ content_for_footer }}
</body>
```

Seed: `layout/theme.liquid`.

### Menu linklists

```liquid
{% assign _menu_ref = theme_settings.header_category_menu.handle | default: 'main-menu' %}
{% assign _linklist = linklists[_menu_ref] %}
{% if _linklist and _linklist.links.size > 0 %}
  <nav aria-label="{{ _linklist.title | escape }}">
    <ul role="list">
      {% for link in _linklist.links %}
        <li>
          <a href="{{ link.url }}" class="{% if link.active %}font-semibold{% endif %}">{{ link.title }}</a>
          {% if link.links.size > 0 %}
            <ul role="list">
              {% for child in link.links %}
                <li><a href="{{ child.url }}">{{ child.title }}</a></li>
              {% endfor %}
            </ul>
          {% endif %}
        </li>
      {% endfor %}
    </ul>
  </nav>
{% else %}
  <a href="/categories">{{ 'nav.categories' | t }}</a>
  <a href="/products">{{ 'nav.products' | t }}</a>
{% endif %}
```

Seed: `partials/layout-menu-desktop.liquid`.

### Vòng lặp catalog

```liquid
{% for p in products %}
  {% include 'card-product', product: p %}
{% else %}
  <p>{{ 'catalog.empty' | t }}</p>
{% endfor %}
{% assign _plp_base = catalog_pagination_base | default: '/products' %}
{% include 'sf-pagination', paginate: paginate, base_path: _plp_base, item_t: 'pagination.count_products' %}
```

```liquid
{% for cat in categories %}
  {% include 'card-category', category: cat %}
{% else %}
  <p>{{ 'categories.empty' | t }}</p>
{% endfor %}
{% include 'sf-pagination', paginate: paginate, base_path: '/categories', item_t: 'pagination.count_categories' %}
```

Seed: `partials/page-catalog.liquid`, `partials/page-categories-index.liquid`.

### PLP danh mục

```liquid
{% assign _cat = storefront_category.category %}
{% assign _prods = storefront_category.products %}
<h1>{{ _cat.title | escape }}</h1>
<ul class="grid grid-cols-1 gap-6 sm:grid-cols-2 lg:grid-cols-3">
  {% for p in _prods %}
    <li class="min-w-0">{% include 'card-product', product: p %}</li>
  {% else %}
    <li>{{ 'catalog.empty' | t }}</li>
  {% endfor %}
</ul>
{% assign _cat_base = '/categories/' | append: _cat.slug %}
{% include 'sf-pagination', paginate: storefront_category.paginate, base_path: _cat_base, item_t: 'pagination.count_products' %}
```

Seed: `partials/page-category.liquid`.

### Phân trang

Object Gennova: `paginate.page`, `total_pages`, `total_count`, `has_prev_page`, `has_next_page`. Snippet tự nối `?page=` hoặc `&page=` nếu `base_path` đã có query:

```liquid
{% assign _base = catalog_pagination_base | default: '/products' %}
{% include 'sf-pagination', paginate: paginate, base_path: _base, item_t: 'pagination.count_products' %}

{% comment %} Khi URL đã có query (tags=…): truyền đúng catalog_pagination_base từ context — snippet nối &page=. {% endcomment %}
{% include 'sf-pagination', paginate: storefront_category.paginate, base_path: catalog_pagination_base, item_t: 'pagination.count_products' %}
```

Seed: `partials/sf-pagination.liquid`.

### Card sản phẩm

```liquid
{% assign cover = product.featured_media | asset_image_url: 'medium' %}
<a href="{{ product.url | default: '/products/' | append: product.handle }}">
  {% if cover != blank %}
    <img src="{{ cover }}" alt="{{ product.title | escape }}" loading="lazy" decoding="async" />
  {% endif %}
  <span>{{ product.title | escape }}</span>
  <span>{{ product.price_sale_min | money: payment_currency }}</span>
</a>
{% if product.is_combo %}
  <button type="button" data-sf-add-to-cart data-is-combo="true" data-product-id="{{ product.id }}" data-qty="1">
    {{ 'product.add_to_cart' | t }}
  </button>
{% elsif product.product_items.size > 1 %}
  <button type="button" data-sf-quick-view-trigger data-sf-qv-template="sf-qv-pid-{{ product.id }}">
    {{ 'product.choose_variant' | t }}
  </button>
  <template id="sf-qv-pid-{{ product.id }}">
    {% for it in product.product_items %}
      <div data-sf-cart-line>
        <input type="number" data-sf-cart-qty value="1" min="1" />
        <button type="button" data-sf-add-to-cart data-product-item-id="{{ it.id }}">{{ 'product.add_to_cart' | t }}</button>
      </div>
    {% endfor %}
  </template>
{% elsif product.product_items.first %}
  <button type="button" data-sf-add-to-cart data-product-item-id="{{ product.product_items.first.id }}" data-qty="1">
    {{ 'product.add_to_cart' | t }}
  </button>
{% endif %}
```

Seed: `partials/card-product.liquid`.

### PDP gallery và mua hàng

```liquid
{% if product.featured_media %}
  <img src="{{ product.featured_media | asset_image_url: 'grande' }}" alt="{{ product.title | escape }}" data-sf-pdp-gallery />
{% endif %}

<div id="sf-pdp-purchase" data-sf-cart-line>
  <input type="number" data-sf-cart-qty value="1" min="1" />
  {% assign _pi = product_items.first | default: product.product_items.first %}
  <button
    type="button"
    data-sf-add-to-cart
    data-product-item-id="{{ _pi.id }}"
  >
    {{ 'product.add_to_cart' | t }}
  </button>
</div>
{% include 'sf-product-jsonld' %}
{% include 'sf-related-products' %}
```

Seed: `partials/page-product.liquid` (rút gọn).

### PDP swatch biến thể

```liquid
{% assign _items = product_items | default: product.product_items %}
<div id="sf-pdp-purchase" data-sf-cart-line>
  <fieldset>
    <legend>{{ 'product.variants' | t }}</legend>
    {% for row in _items %}
      {% assign v = row.variant %}
      <label>
        <input
          type="radio"
          name="sf_pdp_product_item"
          value="{{ row.id }}"
          {% if forloop.first %}checked{% endif %}
        />
        {{ v.title | default: v.name | truncate: 28 | escape }}
      </label>
    {% endfor %}
  </fieldset>
  {% for row in _items %}
    <div
      class="sf-pdp-panel"
      data-panel-for="{{ row.id }}"
      {% unless forloop.first %}hidden{% endunless %}
    >
      {% include 'fragment-pdp-variant-detail', variant: row.variant, product_item: row, currency_code: payment_currency %}
    </div>
  {% endfor %}
  <input type="number" data-sf-cart-qty value="1" min="1" />
  <button type="button" data-sf-add-to-cart data-product-item-id="{{ _items.first.id }}">
    {{ 'product.add_to_cart' | t }}
  </button>
</div>
```

Seed: `partials/page-product.liquid`, `partials/fragment-pdp-variant-detail.liquid`. JS theme đổi panel theo radio + cập nhật `data-product-item-id`.

### PDP license matrix

Key dài (không dùng short `i`/`c`/`b`/`w` trong theme mới):

```liquid
<div data-sf-cart-line data-sf-license-matrix="1" data-default-pi="{{ product_items.first.id }}">
  <script type="application/json" id="sf-pdp-matrix-json">
[
{% for row in product_items %}
  {% assign v = row.variant %}
  {"product_item_id":{{ row.id }},"max_channels":{{ v.attributes.max_channels | default: 0 | json }},"max_branches":{{ v.attributes.max_branches | default: 0 | json }},"max_warehouses":{{ v.attributes.max_warehouses | default: 0 | json }},"is_available":{% if v.is_available %}true{% else %}false{% endif %}}{% unless forloop.last %},{% endunless %}
{% endfor %}
]
  </script>
  <div data-sf-dim="c" role="radiogroup" aria-label="{{ 'product.license_channels' | t | escape }}"></div>
  <div data-sf-dim="b" role="radiogroup" aria-label="{{ 'product.license_branches' | t | escape }}"></div>
  <div data-sf-dim="w" role="radiogroup" aria-label="{{ 'product.license_warehouses' | t | escape }}"></div>
  <button type="button" data-sf-add-to-cart data-product-item-id="{{ product_items.first.id }}">{{ 'product.add_to_cart' | t }}</button>
</div>
```

Seed: `partials/page-product.liquid` (nhánh matrix).

### Tra số nhiều theo id / slug

```liquid
{% assign cat = categories['ao-thun'] %}
{% if cat == blank %}
  {% assign cat = categories[section.settings.category_id] %}
{% endif %}
{% if cat %}
  <h2>{{ cat.title }}</h2>
  {% for p in cat.products limit: 8 %}
    {% include 'card-product', product: p %}
  {% endfor %}
{% endif %}
{% assign featured_product = products[section.settings.product_handle] %}
{% assign blog = blogs['news'] %}
{% for a in blog.articles limit: 4 %}
  <a href="/blogs/{{ blog.handle }}/{{ a.handle }}">{{ a.title }}</a>
{% endfor %}
```

Debug trong `<script>` — luôn có giá trị JSON (tránh `console.log("x",);` khi miss):

```liquid
<script>
  console.log("cat", {{ categories['ao-thun'] | default: nil | json }});
</script>
```

Xem [Truy cập số nhiều theo id/slug](#truy-cap-so-nhieu-theo-idslug). Dùng được trên mọi template (kể cả `page` / CMS), trong phạm vi nodes đã inject (`storefrontCategories` nav ~48).

### Search results

```liquid
{% assign _prods = search_results.products.nodes %}
{% for p in _prods %}
  {% include 'card-product', product: p %}
{% else %}
  <p>{{ 'search.empty' | t }}</p>
{% endfor %}
{% include 'sf-pagination', paginate: search_results.products.paginate, base_path: '/search?q=' | append: search_query, item_t: 'pagination.count_products' %}
```

Seed: template search / partial search tương ứng.

### CMS page / article

```liquid
<article>
  <h1>{{ page.title | escape }}</h1>
  {% include 'sf-cms-media-gallery', cms_entity: page, alt_title: page.title %}
  <div class="prose">{{ page.body }}</div>
</article>
```

```liquid
<article>
  <h1>{{ article.title | escape }}</h1>
  <p>{{ article.author_name | escape }} · {{ article.published_at | date: '%d/%m/%Y' }}</p>
  {% include 'sf-cms-media-gallery', cms_entity: article, alt_title: article.title %}
  <div class="prose">{{ article.body }}</div>
</article>
```

Seed: `partials/page-page.liquid`, `partials/page-article.liquid`.

### Forms — newsletter / review

```liquid
<div id="newsletter-form-alert" role="alert" hidden></div>
{% form 'newsletter' %}
  <input id="newsletter-email" name="email" type="email" required />
  <input id="newsletter-name" name="name" type="text" />
  <input id="newsletter-consent" name="consent" type="checkbox" value="1" required />
  <button id="newsletter-submit" type="submit">{{ 'newsletter.submit' | t }}</button>
{% endform %}
```

```liquid
<div id="review-form-alert" role="alert" hidden></div>
{% form 'review' %}
  <input type="hidden" name="entity" value="{{ review_submit_target.entity }}" />
  <input type="hidden" name="entityId" value="{{ review_submit_target.entity_id }}" />
  <input id="review-rating" name="rating" type="number" min="1" max="5" required />
  <textarea id="review-body" name="body" required></textarea>
  <button id="review-submit" type="submit">{{ 'review.submit' | t }}</button>
{% endform %}
```

Contact đầy đủ: [Forms và hook giỏ](#forms-va-hook-gio). Seed: `partials/sf-newsletter-form.liquid`, `partials/sf-review-form.liquid`.

### Giỏ hàng (island)

`cart` trong Liquid SSR **luôn `null`**. Không đọc `cart.item_count` khi render. UI:

```liquid
{%- comment -%} templates/carts/carts.liquid → page-cart-shell {%- endcomment -%}
<div class="sf-cart-page">
  <!--SF_APP_SLOT-->
</div>
```

Hook mua hàng (bắt buộc đúng attribute để island `sf-storefront-cart` bắt):

```html
<div data-sf-cart-line>
  <input data-sf-cart-qty value="1" min="1" />
  <button type="button" data-sf-add-to-cart data-product-item-id="123">Add</button>
</div>
```

Combo: `data-is-combo="true"` + `data-product-id`. Seed: `partials/page-cart-shell.liquid`, `partials/sf-storefront-cart.liquid`.

### Hero / `section.settings`

```liquid
{% assign heading = section.settings.heading | default: theme_settings.section_hero_banner_heading %}
{% if heading == blank %}
  {% assign heading = 'hero.banner_default' | t %}
{% endif %}
<section class="w-full py-8 px-4">
  <h2 class="text-2xl font-bold text-[color:var(--sf-text-primary)]">{{ heading }}</h2>
</section>
```

### Media trong section (`control: media`)

```liquid
{% assign image_setting = section.settings.image | default: '' | strip %}
{% if image_setting != blank %}
  <img src="{{ image_setting | asset_image_url: 'grande' }}" alt="{{ section.settings.image_alt | strip }}" loading="lazy" decoding="async" />
{% endif %}
```

### Thêm partial vào trang

1. Tạo `partials/<slug>.liquid`
2. Thêm `{ "kind": "partial", "partial": "<slug>", "settings": {…}, "settings_definitions": […] }` vào `sections/<composition>.json`

---

## Quy ước Gennova

- Chỉ dùng filter / object đã document trên trang này.
- Không phụ thuộc `powered_by_link`, `link_to_tag`, `image_url: width:` kiểu engine khác.
- Phân trang: object `paginate` + `sf-pagination` — không `paginate.previous.url` Shopify.
- Ảnh: **`asset_image_url`** (prefer WebP).
- `{{ content_for_header }}` không thay SEO meta theme.
- Không có `{% layout none %}`.
- `{% render 'slug' %}` slug-only thường **không** khớp FS Gennova — ưu tiên `{% include %}`.
- `cart` Liquid luôn `null` — UI giỏ dùng hook JS / island.

---

## Tài liệu liên quan

- [https://docs.gennovadev.com/themes](https://docs.gennovadev.com/themes)
- Raw markdown: `/themes.md`

SSOT: `gennova_platform/main/extensions/apis/application/docs/liquid/gennova-liquid-cheat-sheet.md`.

---

© 2026 GenNova Dev. Bảo lưu mọi quyền.

Gennova — đồng bộ bán hàng, kế toán và hoá đơn.

Gennova Platform
