Shopify - 变体中的名称为空,但其他键不是

Shopify - name in variant is null, but others keys are not

在我的 Shopify 页面上执行此操作:

{{ product.selected_or_first_available_variant | json }}

给我这个 JSON 输出。

{
    "id": 22061938375,
    "title": "Small / Black",
    "option1": "Small",
    "option2": "Black",
    "option3": null,
    "sku": "LSL2",
    "requires_shipping": true,
    "taxable": true,
    "featured_image": {
        "id": 14987460807,
        "product_id": 6956222919,
        "position": 1,
        "created_at": "2016-06-24T11:03:47+01:00",
        "updated_at": "2016-06-24T18:17:08+01:00",
        "src": "https://cdn.shopify.com/s/files/1/1071/2704/products/Lace1-Black-LS-LifeStyle-Shop-R.jpg?v=1466788628",
        "variant_ids": [
            22061938375
        ]
    },
    "available": false,
    "name": "Long Sleeve Chantilly Lace Shimmy - Small / Black",
    "options": [
        "Small",
        "Black"
    ],
    "price": 8800,
    "weight": 454,
    "compare_at_price": null,
    "inventory_quantity": 0,
    "inventory_management": "shopify",
    "inventory_policy": "deny",
    "barcode": ""
}

如果我这样做:{{ product.selected_or_first_available_variant.id | json }} 我得到:22061938375(正确)。

但是,如果我尝试使用 name 这样的另一个键:{{ product.selected_or_first_available_variant.name | json }} 我得到 null(错误)。

这到底是怎么回事?为什么我只能访问一些键而不是所有键,即使我可以在完整输出中看到它们?这对我来说意义不大。

非常感谢任何帮助。

谢谢!

我认为您的问题是 "name" 实际上不是 variant 的成员。我猜测 JSON 输出中出现的 "name" 是动态生成的。它只是产品标题和变体标题的串联。

为此使用 JSON 过滤器也太过分了。 你可以做到

{{ product.title }} {{ product.selected_or_first_available_variant.title }}

如果您知道该产品有选项或类似内容:

{% assign currVar = product.selected_or_first_available_variant %}
{{ product.title }}{% unless currVar.title contains 'Default' %} {{ currVar.title }}{% endunless %}