BUG REPORT: Deleted Metafield Images still Pulling to Storefront

Solved

BUG REPORT: Deleted Metafield Images still Pulling to Storefront

DMT-Mat
Shopify Partner
20 3 15

Pretty sure this is a bug, a client has asked for a simplified system to display an image for product swatches.

 

All working as intended until you clear the image from the metafield from the product, which should stop displaying the image, however the image stays - outputting the value of the field still displays the media GID for the image, so it seems the value isn't actually being cleared from the product metafield data.

 

Simplified code example:

{% for swatch in product.metafields.swatches.products.value %}
  {% assign swatch_img = swatch.metafields.swatches.image %}
  <a class="swatch" href="{{ swatch.url }}">
    <span style="{%- if swatch_img -%}background-image: url('{{ swatch_img | img_url: '30x30' }}');{%- endif -%}background-color: {{ swatch.metafields.swatches.colour }}"></span>
  </a>
{% endfor %}

 

I'll add some validation as a workaround, but assuming this isn't intended.

Need expert help with your Shopify Website? Message me or contact the team.
Accepted Solution (1)

DMT-Mat
Shopify Partner
20 3 15

This is an accepted solution.

When I refreshed the product page in the admin, the image had reappeared in the image metafield, so seems that it is not always correctly saved when you delete it.

 

Re-deleted and re-saved the product sorted it 😅

Need expert help with your Shopify Website? Message me or contact the team.

View solution in original post

Replies 2 (2)

DMT-Mat
Shopify Partner
20 3 15

This is an accepted solution.

When I refreshed the product page in the admin, the image had reappeared in the image metafield, so seems that it is not always correctly saved when you delete it.

 

Re-deleted and re-saved the product sorted it 😅

Need expert help with your Shopify Website? Message me or contact the team.
kinful
Shopify Partner
4 0 1

We are having this same exact issue.  The solution noted here does work eventually, but it's really not a great solution and for sure a bug in the backend. 

When we go to clear the metafield and click "save" the metafield shows as empty (which we want it to be), but it's still populated on the front-end.  We can see that the metafield is still being populated even though it's clear (and saved) on the backend.  

The only solution is to reload the product in the backend a couple times. Then add a new value and clear it again.  It's somewhat a shot in the dark each time.