reggi / shopify

Just a place to track issues and feature requests that I have for shopify
3 stars 1 forks source link

Filter img_url returns string when no image is present #1

Open reggi opened 9 years ago

reggi commented 9 years ago

If you attempt to pull the img_url from a shopify object that doesn't have an image you get a url back. I would expect to get a null or false.

Note: for the img_url filter you can pass the entire object collection or collection.image.src.

Native Behavior

If you attempt to get the img_url from any kind of variable you get a string back

{% assign image = collections["non-existant"] | img_url: "master" %} {{ image | json }} <br>
{% assign image = collections["with-no-image"] | img_url: "master" %} {{ image | json }} <br>
{% assign image = "string" | img_url: "master" %} {{ image | json }} <br>
{% assign image = false | img_url: "master" %} {{ image | json }} <br>
{% assign image = true | img_url: "master" %} {{ image | json }} <br>
{% assign image = null | img_url: "master" %} {{ image | json }} <br>
{% assign image = 1 | img_url: "master" %} {{ image | json }} <br>
{% assign image = 0 | img_url: "master" %} {{ image | json }} <br>

All will return back "//cdn.shopify.com/s/assets/admin/no-image-master.gif"

Here's a empty img_url with all the sizes.

{% assign collection = collections["wallets"] %}
{% assign image = collection | img_url: "pico" %} {{ image | json }} <br>
{% assign image = collection | img_url: "icon" %} {{ image | json }} <br>
{% assign image = collection | img_url: "thumb" %} {{ image | json }} <br>
{% assign image = collection | img_url: "small" %} {{ image | json }} <br>
{% assign image = collection | img_url: "compact" %} {{ image | json }} <br>
{% assign image = collection | img_url: "medium" %} {{ image | json }} <br>
{% assign image = collection | img_url: "large" %} {{ image | json }} <br>
{% assign image = collection | img_url: "original" %} {{ image | json }} <br>
{% assign image = collection | img_url: "1024x1024" %} {{ image | json }} <br>
{% assign image = collection | img_url: "2048x2048" %} {{ image | json }} <br>
{% assign image = collection | img_url: "master" %} {{ image | json }} <br>

This is the output

"//cdn.shopify.com/s/assets/admin/no-image-pico-45246d2894367ad3f32f0b8f56797f22.gif" 
"//cdn.shopify.com/s/assets/admin/no-image-icon-c095c3e7dc28d85bca016df7b7af51e5.gif" 
"//cdn.shopify.com/s/assets/admin/no-image-thumb-4842b6739367ae7daa031635e0de7472.gif" 
"//cdn.shopify.com/s/assets/admin/no-image-small-6f0bd443a4e4354aeddc8f3abebe320b.gif" 
"//cdn.shopify.com/s/assets/admin/no-image-compact-8c2cb5306d417d791c797aaf07637494.gif" 
"//cdn.shopify.com/s/assets/admin/no-image-medium-4842b6739367ae7daa031635e0de7472.gif" 
"//cdn.shopify.com/s/assets/admin/no-image-large-8c2cb5306d417d791c797aaf07637494.gif" 
"//cdn.shopify.com/s/assets/admin/no-image-1024x1024-c0f29e6aad70d979586599f6f0cc5f66.gif" 
"//cdn.shopify.com/s/assets/admin/no-image-1024x1024-c0f29e6aad70d979586599f6f0cc5f66.gif" 
"//cdn.shopify.com/s/assets/admin/no-image-2048x2048-1037fc8423a4283e3701e5cf3888d282.gif" 
"//cdn.shopify.com/s/assets/admin/no-image-master.gif" 

So the only consistent thing is no-image.


Working example of URLS returned

Here's an example of everything going right, a collection with a image present.

"//cdn.shopify.com/s/files/1/0031/5352/collections/Victore_collection_wide_300_pico.jpg?v=1420743353" 
"//cdn.shopify.com/s/files/1/0031/5352/collections/Victore_collection_wide_300_icon.jpg?v=1420743353" 
"//cdn.shopify.com/s/files/1/0031/5352/collections/Victore_collection_wide_300_thumb.jpg?v=1420743353" 
"//cdn.shopify.com/s/files/1/0031/5352/collections/Victore_collection_wide_300_small.jpg?v=1420743353" 
"//cdn.shopify.com/s/files/1/0031/5352/collections/Victore_collection_wide_300_compact.jpg?v=1420743353" 
"//cdn.shopify.com/s/files/1/0031/5352/collections/Victore_collection_wide_300_medium.jpg?v=1420743353" 
"//cdn.shopify.com/s/files/1/0031/5352/collections/Victore_collection_wide_300_large.jpg?v=1420743353" 
"//cdn.shopify.com/s/files/1/0031/5352/collections/Victore_collection_wide_300_1024x1024.jpg?v=1420743353" 
"//cdn.shopify.com/s/files/1/0031/5352/collections/Victore_collection_wide_300_1024x1024.jpg?v=1420743353" 
"//cdn.shopify.com/s/files/1/0031/5352/collections/Victore_collection_wide_300_2048x2048.jpg?v=1420743353" 
"//cdn.shopify.com/s/files/1/0031/5352/collections/Victore_collection_wide_300.jpg?v=1420743353" 

You can see the path URL is a little different for the missing images too.

reggi commented 9 years ago

collection.image returns null if there's no image present. It's not ideal because it relies on using a conditional that has nothing to do with the variable that we need and it's object specific.

{% assign image_avail = collection.image %}
{% assign image = collection | img_url: "master" %}
reggi commented 9 years ago

This was originally posted here https://github.com/Shopify/liquid/issues/497

notrealdev commented 1 year ago

This bug featured still here?

assign file_url = 'image.png' | file_url // always return string.

if file_url
    echo 'This image file is true' // always print this line, lol.
else
    echo 'No image'
endif
HandHugs commented 9 months ago

Yes this is still a problem. There is currently no way to check if the file called by file_url or file_img_url actually exists :(