Get model3d file URL

Solved

Get model3d file URL

pzagor2
Tourist
3 1 0

Hello.

 

In my theme liquid file, I'm trying to get my model model3d (.glb) file URL. I can get the file ID by doing. 

 

 
var glbModelFileUrl = "{{ product.metafields.custom.canopy_model.value['3d_model_file'] }}";
//Reulst: gid://shopify/Model3d/idofmymodel
var glbModelFileUrl = "{{ product.metafields.custom.canopy_model.value['3d_model_file'] | file_url }}";
//Using this gives me this error: Cannot apply file_url to a 3D model, not supported.
var glbModelFileUrl = "{{ product.metafields.custom.canopy_model.value['3d_model_file'].sources[0].url }}";
//this gives empty string

 I can't figure out how to get the URL. I have the file attached to the product object in my metaobject. 

 

Accepted Solution (1)

pzagor2
Tourist
3 1 0

This is an accepted solution.

I was able to get the URL with 

 

window.model3dUrl = "{{ product.metafields.custom.canopy_model.value['3d_model_file'].value.sources[0].url}}";

 

@marcuswebexp Thank you for taking the time and helping. 

View solution in original post

Replies 5 (5)

marcuswebexp
Shopify Partner
19 2 2

HI @pzagor2 ,

 

Try assigning the object to a variable in liquid first like so:

{% assign glbModelFile = product.metafields.custom.canopy_model.value['3d_model_file'] %}

 

Then, try accessing the file url with that variable inside the output tag.

{{ glbModelFile| file_url }}

 

Let me know if this works.

 

If this was useful, a Like or marking it as a Solution is appreciated. Need more help? Feel free to reach out anytime using the email address/phone number in my signature.

 

Myles Marcus | Web & Automation Specialist @ Marcus Web Experts LLC
Email: myles@marcuswebexperts.com
Phone: 858-208-3379
Your satisfaction is our top priority. If you don’t feel like you’re getting value, you don’t pay. It’s that simple.
pzagor2
Tourist
3 1 0

Thank you for the suggestion, but unfortunately I get the same error: 

Cannot apply file_url to a 3D model, not supported.

 

marcuswebexp
Shopify Partner
19 2 2

@pzagor2 Can you send me your 3D model here so I can try uploading it on my end and troubleshooting it?

Myles Marcus | Web & Automation Specialist @ Marcus Web Experts LLC
Email: myles@marcuswebexperts.com
Phone: 858-208-3379
Your satisfaction is our top priority. If you don’t feel like you’re getting value, you don’t pay. It’s that simple.

pzagor2
Tourist
3 1 0

This is an accepted solution.

I was able to get the URL with 

 

window.model3dUrl = "{{ product.metafields.custom.canopy_model.value['3d_model_file'].value.sources[0].url}}";

 

@marcuswebexp Thank you for taking the time and helping. 

marcuswebexp
Shopify Partner
19 2 2

Hi @pzagor2 ,

 

No problem. Happy to help!

Myles Marcus | Web & Automation Specialist @ Marcus Web Experts LLC
Email: myles@marcuswebexperts.com
Phone: 858-208-3379
Your satisfaction is our top priority. If you don’t feel like you’re getting value, you don’t pay. It’s that simple.