简体   繁体   中英

How can we update or edit meta fields for each product for getting multiple images of each product from shopify?

我们如何更新或编辑每个产品的元字段以从 shopify 获取每个产品的多个图像?

If I understand your question you want to have multiple images per product and set in the metafields of the product which image corresponds to which feature of the product.

I would suggest the following, possibly using a web application or an app that removes any manual intervention:

  • You upload all the pictures of the product using Shopify API (or manually).
  • You create a metafield attribute with a json that contains the map the index of the picture that you upload.
  • In your .liquid file you access pictures with something like product.media[product.metafields.myshop.media_data['front_picture']]

To make an example, let's say you have a product with 4 front and 5 back pictures.

  • You upload all your pictures. Front pictures are first 4 and back are the last ones (this is just an example, they could be mixed).
  • You set your metafield as { "front" : [1,2,3,4],"back" : [5,6,7,8,9]} (NB they don't have to be consequent numbers)
  • In your frontend you can put
    {% for front_index in product.metafields.myshop.media_data.front %}
          <img src="{{ product.media[front_index]| img_url: 'original' }}"/>
    {% endfor %}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM