Hi everyone, I found a strange issue to do with metafields. My code is very simple so I think it’s an actual Shopify bug.
If any experienced devs can have a look, especially anyone from Shopify, I’d greatly appreciate it!
Context: I want to create some ‘fake’ breadcrumbs on product pages by outputting a list of collections.
I have a product Metafield of the type “Collection (list)”.
I use a simple for loop to output each collection:
{% assign parentsArray = product.metafields.custom.parent_collections.value %}
{% for coll in parentsArray %}
{{ coll.title }}
{% endfor %}
This works fine most of the time. The correct order of the output would be:
- All products
- Winter
- Snowboards
Right?
The bug:
The bug occurs when visiting a product through a collection-aware URL.
A collection-aware URL is a product URL that has the collections/collection-title part of the URL*.*> > For example /collections/snowboards/products/the-collection-snowboard-liquid
Dawn does not use collection-aware URLs anymore, but many other themes do.
To test in Dawn you need to add the collection part to the URL manually.
When visiting through a collection-aware URL, the order of the list is changed. It puts the collection I’m currently visiting at the beginning.
The bug is inconsistent. Sometimes it doesn’t happen, and it can be fixed by refreshing enough times. You need to use an incognito window to replicate it again.
Demo VIDEO: https://youtu.be/nUkxrUAv14c?si=5Jb1fvQ8f1RWyeU6
Demo store (pass: 123): https://mf-list.myshopify.com/collections/snowboards/products/the-complete-snowboard

