Solved

Using media filters on metafield file type

molten_frog
Tourist
10 0 1

Hi,

I have the following:

{% assign product_image = product.selected_or_first_available_variant.metafields.my_fields.image_1 %}
 
According to this link https://shopify.dev/api/liquid/objects/generic-file I should be able to do {{ product_image.media_type }} but this doesn't return anything.
 
Does anyone know if what I am trying to do is possible?
 
Kind regards
Michael
 
 
 
 
Accepted Solution (1)

LitExtension
Shopify Partner
4860 1001 1133

This is an accepted solution.

Hi @molten_frog,

Please change code:

{% assign product_image = product.selected_or_first_available_variant.metafields.my_fields.image_1 %}

=>

{% assign product_image = product.selected_or_first_available_variant.metafields.my_fields.image_1.value %}

Hope it helps!

LitExtension - Shopping Cart Migration Expert
Check out our Shopify migration app to migrate your online store to Shopify

View solution in original post

Replies 5 (5)

LitExtension
Shopify Partner
4860 1001 1133

This is an accepted solution.

Hi @molten_frog,

Please change code:

{% assign product_image = product.selected_or_first_available_variant.metafields.my_fields.image_1 %}

=>

{% assign product_image = product.selected_or_first_available_variant.metafields.my_fields.image_1.value %}

Hope it helps!

LitExtension - Shopping Cart Migration Expert
Check out our Shopify migration app to migrate your online store to Shopify
molten_frog
Tourist
10 0 1

You are an absolute hero. Not the first time you have helped me 🙂

LitExtension
Shopify Partner
4860 1001 1133

Hi @molten_frog,

If you have any difficulty, you can contact me.

Happy to help you.

LitExtension - Shopping Cart Migration Expert
Check out our Shopify migration app to migrate your online store to Shopify
molten_frog
Tourist
10 0 1

Thanks @LitExtension I really appreciate it.

I have uploaded an mp4 to variant_media_1. And similar to the code above I have done the following:

{% assign product_video = product.selected_or_first_available_variant.metafields.my_fields.variant_media_1.value %}
 
However, product_video.media_type returns generic_file rather than video?
LitExtension
Shopify Partner
4860 1001 1133

Hi @molten_frog,

The generic_file object can be returned when a metafield has a file_reference type. If the file_reference is not an image of type JPEG, PNG, or GIF, then it will return a generic_file.

Refer https://i.imgur.com/8iiOqCc.png

Hope it is clear to you.

LitExtension - Shopping Cart Migration Expert
Check out our Shopify migration app to migrate your online store to Shopify