use product tags or metafield for this?

Solved

Hi,

I have two questions. first one to understand how metafields are retrieved and second to see which code is faster.

On the product page, which one is correct for product.metafileds.global.material?

1. Shopify uses a for loop for all product metafeilds that contain global, then searches for material, then displays the result.

2. Shopify uses a for loop for all metafields that contain global.material, then displays the result.

3. Shopify retrieves product.metafileds.global.material without a for loop and displays the result.

 

I want to show product material, dimensions, etc. on the product page.

does it make sense to use metafields for each like:

{{ product.metafileds.global.material }}
{{ product.metafileds.global.diemensions }}

OR

use one JSON string metafield that contains all information

OR

use a for loop and if statement for tag in product.tags

{% for tag in product.tags %}
{% assign first_part = tag | split: ":" | first %}
{% if first_part == "material" %}
<tr>
<td>material</td
<td>{{ tag | split: ":" | last }}</td>
<tr>
{% elsif first_part == "dimensions" %}
<tr>
<td>dimensions</td>
<td>{{ tag | split: ":" | last }}</td>
</tr>
.
.
.
{% endif %}
{% endfor %}

I've read everywhere that tags are faster to retrieve than metafields, but since I'm calling a specific metafield rather than using a for loop and an if condition to get the information, isn't a metafield faster to retrieve?

Thank you for taking the time to explain.

-Like and Mark as an Accepted Solution if my reply is helpful
I'm not an expert, these are my own experiences or codes that I gathered from others. I'm using Debut.
I have my own online pet supply store check it out at
PETLANTIS.CA
0 Likes
JHKCreate
Shopify Partner
1962 314 418

This is an accepted solution.

Metafields are just that, fields. There are no loops involved here, just a direct access.

Your #3 solution works, and the code below is what you should use:

{{ product.metafileds.global.material }}
{{ product.metafileds.global.diemensions }}


Let me know if you have other questions! 

- Did we solve your issue? Like & Mark As Solution to help the community
- Should you need any direct help: contact@jhkcreate.com
0 Likes

Thank you so much for the quick answer.

-Like and Mark as an Accepted Solution if my reply is helpful
I'm not an expert, these are my own experiences or codes that I gathered from others. I'm using Debut.
I have my own online pet supply store check it out at
PETLANTIS.CA
0 Likes