简体   繁体   中英

Shopify Liquid - Related products as specific handles from a metafield

I am trying to use a Shopify metafield with a comma separated list of handles (ie: handle1,handle2) to call specific related products. These related products are displayed on individual product pages. My problem is: I cannot figure out how to get the products from the array to iterate and display.

I am using the Boundless theme, so I am trying to call/display the products in the same manner as a collection page. This may be part of my problem.

My current code calls the actual product on the page instead of the related products for some reason.

Here is my current code:

{% if product.metafields.c_f['Shown With'] %}
 {% assign shownwith = product.metafields.c_f['Shown With'] | split: ',' %}

 {% capture shownwith_items %}
  {% for product in shownwith %}
   {% include 'product-grid-width' with product_image_type: section.settings.product_image_type, product_image_size: section.settings.product_image_size %}
   {% include 'product-grid-item' with product_image_spacing: section.settings.product_image_spacing, vendor_enable: section.settings.vendor_enable %}
  {% endfor %}
 {% endcapture %}

{% endif %}

{% if product.metafields.c_f['Shown With'] %} {% assign shownwith = product.metafields.c_f['Shown With'] | split: ',' %}

{% capture shownwith_items %} {% for relPro in shownwith %}

{% assign product = all_products[srelPro] %}

{% include 'product-grid-width' with product_image_type: section.settings.product_image_type, product_image_size: section.settings.product_image_size %} {% include 'product-grid-item' with product_image_spacing: section.settings.product_image_spacing, vendor_enable: section.settings.vendor_enable %} {% endfor %} {% endcapture %}

{{ shownwith_items}} {% endif %}

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