Search code examples
shopifyshopify-app

is it possible to store product fields and tie them into liquid templeting?


Is it possible to store fields into variables for individual products to use elsewhere in the code or am I stuck with only API calls?

I'd like to store data for each product into a variables and pass them to the liquid product template to make a dynamic hyperlink for each product.

https://i.sstatic.net/7vPSd.jpg - Example of Embedded App fields to be saved.

https://i.sstatic.net/bxDFT.jpg - Example of product listing.


Solution

  • You can use metafields to store and display custom properties of a product.

    To save a metafield in your app make a request to the Shopify API:

    POST /admin/products/#{id}/metafields.json
    {
      "metafield": {
        "namespace": "test_app",
        "key": "seller_id",
        "value": 123,
        "value_type": "integer"
      }
    }
    

    To get seller_id in the product template:

    {{ product.metafields.test_app.seller_id }}
    

    Metafields are available automatically in the templates.