URL issue - in url it's coming variant id instead of handle

URL issue - in url it's coming variant id instead of handle

BlackBox
Visitor
1 0 0

I have created a metaobject for the color swatch, which contains the following fields: 1. Color Name, 2. Color Hex Code, 3. Product (for linking to the swatch). I have populated all the details, and everything seems to be set up correctly. I have successfully connected the namespace and key of the metafield. However, I'm facing an issue with the product URL: instead of showing the product handle, it displays the product variant ID. How can I fix this?


Here's the code of mine for your reference it might be issue in my code please check once.


{% if product.metafields.custom.color_swatches != blank %}
<div class="product-color-swatches" {{ block.shopify_attributes }}>
{% for color_swatch in product.metafields.custom.color_swatches.value %}
{% assign color_name = color_swatch.color_name | remove: '["' | remove: '"]' | strip %}
{% assign color_hex = color_swatch.color_hex_code | remove: '["' | remove: '"]' | strip %}
{% assign product_link_parts = color_swatch.product | split: '/' %}
{% assign product_handle = product_link_parts.last %}

<a href="/products/{{ product_handle }}" class="color-swatch-link">
<span class="color-swatch" style="background-color: {{ color_hex }};">
<span class="color-name">{{ color_name }}</span>
</span>
</a>
{% endfor %}
</div>
{% endif %}

Replies 0 (0)