Product variants in search results aren't ordered properly

Product variants in search results aren't ordered properly

Jacob_D
Shopify Partner
10 0 0

So, I'm trying to get products json within my custom template search.data.liquid:

...
{%- for product in search.results -%}
...
{{ product | json }}
...

And I discovered, that variants in products json are ordered differently, than they are ordered in admin dashboard. (For example, in dashboard 'basic' comes first, followed by 'custom' & 'deluxe', and I get ['custom', 'deluxe', 'basic'] in json)
I tried to rearrange them, but that doesn't help.
Sort order is very important in my case. Is there a way to get variants array in correct order?

Replies 3 (3)

NomtechSolution
Astronaut
1245 113 153

In Shopify, the order of variants in the JSON representation of a product is based on the order in which they were created, not their display order in the admin dashboard. If you need to have the variants in a specific order, you can update the variants' positions in the admin dashboard to reflect the desired order.

Here's how you can update the variant order in the admin dashboard:

  1. Go to your Shopify admin dashboard and navigate to the product that contains the variants you want to reorder.

  2. Scroll down to the "Variants" section of the product editing page.

  3. Click on the "Edit variants" button.

  4. You will see a list of variants for the product. You can click and drag each variant to rearrange their order.

  5. Drag the variants into the desired order, placing them according to your preference.

  6. Click the "Save" button to apply the changes.

Once you have updated the variant order in the admin dashboard, the JSON representation of the product's variants should reflect the new order.

Jacob_D
Shopify Partner
10 0 0

My problem is that once I have updated the variant order in the admin dashboard, the JSON representation of the product's variants does not reflect the new order, as I've explained in the opening post.

snapexyz
Shopify Partner
4 0 1

Hey Jacob, 

 

We've just found our website is suffering the same issue. Did you ever find a resolution?

 

Thanks

Adam