跳转到内容
免费安装
简体中文
在 Claude 中打开 就此页面提问在 ChatGPT 中打开 就此页面提问

启用 Collection 条件

在模板中添加一个模板文件,使 Collection 条件能够匹配产品。

Collections 条件需要在您的模板中添加一个小型模板文件。没有它,应用就无法在店面上判断某个产品属于哪些产品系列,因此针对产品系列的倒计时不会显示。

每个模板只需操作一次,而且应用会在需要时提示您:倒计时构建器中会出现警告横幅,如果您希望由支持团队代为操作,可以点击 Request setup 按钮。

  1. 在 Shopify 后台中,前往在线商店 → 模板。在目标模板上点击 …(更多操作)按钮,然后选择编辑代码。

    Shopify 模板页面,已打开更多操作菜单并高亮显示“编辑代码”

    通过更多操作 → 编辑代码打开模板的代码编辑器。

  2. 在 Templates 文件夹中,点击 Add a new template,选择类型为 liquid 的 search 模板,并将其命名为:

    samiCountdownsProductsJson

    Shopify 会将其保存为 templates/search.samiCountdownsProductsJson.liquid。

    “添加新模板”对话框,已选择 search,名称输入为 samiCountdownsProductsJson

    创建一个名为 samiCountdownsProductsJson 的 search 模板。

  3. 删除 Shopify 在新文件中放入的所有内容,并粘贴以下代码:

    {%- layout none -%}
    {%- paginate search.results by 1000 -%}
    [{%- for product in search.results -%}
    {%- unless forloop.first -%},{%- endunless -%}
    {
    "id":{{-product.id-}},
    "title":{{-product.title | json-}},
    "handle":{{-product.handle | json-}},
    "price":"{{-product.price-}}",
    "price_max":"{{-product.price_max}}",
    "price_min":"{{-product.price_min}}",
    "type":{{-product.type | json-}},
    "created_at":"{{-product.created_at | date: "%Y-%m-%d %H:%M" -}}",
    "published_at":"{{-product.published_at | date: "%Y-%m-%d %H:%M" -}}",
    "tags": {{-product.tags | json-}},
    "vendor": {{-product.vendor | json-}},
    "featured_image":"{{-product.featured_image-}}",
    "url":"{{-product.url-}}",
    "collections":{{-product.collections | map: 'id' | json-}},
    "compare_at_price":"{{-product.compare_at_price-}}",
    "compare_at_price_max": "{{-product.compare_at_price_max-}}",
    "compare_at_price_min": "{{-product.compare_at_price_min-}}",
    "price_varies": "{{-product.price_varies-}}",
    "compare_at_price_varies": "{{-product.compare_at_price_varies-}}",
    "images":[
    {%- for image in product.images -%}{%- unless forloop.first -%},
    {%- endunless -%}{"id":{{-image.id-}},
    "src":{{-image.src | json-}}}{%- endfor -%}],
    "first_available_variant":{"id":{{-product.selected_or_first_available_variant.id | times: 1 -}}},
    "available":{{-product.available | json-}},
    "options": {{-product.options | json-}},
    "variants":[
    {%- for variant in product.variants -%}{%- unless forloop.first -%},
    {%- endunless -%}
    {
    "id":{{-variant.id-}},
    "title":{{-variant.title | json}},
    "name":{{-variant.name | json}},
    "price":{{-variant.price-}},
    "compare_at_price":{{-variant.compare_at_price | times: 1-}},
    "available":{{-variant.available-}},
    "sku":{{-variant.sku | json -}},
    "weight":"{{-variant.weight-}}",
    "weight_unit": "{{-variant.weight_unit-}}",
    "inventory_quantity":{{-variant.inventory_quantity-}},
    "option1": {{-variant.option1| json-}},
    "option2": {{-variant.option2| json-}},
    "option3": {{-variant.option3| json-}},
    "options": {{-variant.options| json-}},
    "selected": {%- if variant.selected -%} {{-variant.selected-}} {%- elsif product.selected_or_first_available_variant.id == variant.id -%} true {%- else -%} false {%- endif -%}
    }
    {%- endfor -%}
    ]
    }
    {%- endfor -%}]
    {%- endpaginate -%}
  4. 在代码编辑器中点击 Save。

  5. 回到 Countdown Timer Bar Samita 并打开 Theme integration 页面,让应用识别该模板上的更改。

  6. 打开一个倒计时,将其条件设置为 Collections 并选择一个产品系列,将其保存为 Active,然后在线上店面访问该产品系列中的一个产品。倒计时应会显示。

    也请检查一个不在该产品系列中的产品,它不应显示任何内容。

它是一个 search 模板,以数据而不是网页的形式返回产品信息,其中包括每个产品所属的产品系列,而应用在店面上无法通过其他方式获得这些信息。应用在需要检查产品系列条件时会在后台请求它,买家不会看到它。

  • 按模板分别设置。 更换模板或安装新模板后,也需要在新模板中添加该文件。
  • 名称必须完全一致。 即 samiCountdownsProductsJson,包括大写字母。拼写错误会导致文件永远找不到,且页面上不会有任何错误提示。
  • 只读取,不写入。 该文件不会改变模板的行为或外观。

这对您有帮助吗?