Liquid code to find out duplicate products by handled and show only which have lesser price

Topic summary

A Shopify developer needs to identify duplicate products with the same title but different vendors, and display only the lowest-priced variant on their website.

Current Challenge:

  • Multiple products share the same title but differ in SKU, price, handle, and vendor
  • Static handle assignment works, but dynamic implementation in product template files fails
  • Goal is to automatically show the cheapest option when duplicates exist

Proposed Solution:
Another user suggests filtering products by matching title, then sorting by price to select the lowest:

{% assign productTitle = product.title %}
{% assign allProductsWithSameTitle = collection['all'].products | where: "title", productTitle %}
{% assign sortProductsByPrice = allProductsWithSameTitle | sort: "price" %}
{% assign lowestPriceProduct = sortProductsByPrice | first %}

Status: The discussion appears to be ongoing, with the original poster seeking help to implement this dynamic filtering logic in their Liquid template code.

Summarized with AI on November 23. AI used: claude-sonnet-4-5-20250929.

How to compare the handle for all products ?
Loop through entire collection which includes all the products

{% assign entireproducts = collections[‘entire-collection’].products %}
{% assign entireproducts = collections[‘entire-collection’].products %}
{% assign available_products = 0 %}

{% for product in entireproducts %}
{% assign available_products = available_products | plus: 1 %}

{% for variant in product.variants %}

{% endfor %}

Can you please explain it more ?

I have duplicate products which offer same size or different size products with same title but vendors is different. I want to display products which ever cheaper in my website. So my website will always display products from one vendor only ( Which ever cheaper ). In product details page i want to check this logic to find the same title products from different vendors. I tried the below code . When i given the handle statically then it is showing other vendor products finely. I want to make it dynamic. Can anybody help me on this.

Now i want to display the lowest price product if available.

Product is having different sku,handle, price but title is same.

Please help me to show lowest price product.

{% assign some_handle = product.handle %} {% assign custom_product = all_products[some_handle] %}

i tried this code in product_template.liquid file but it is not working as expected.

Hi @Samruddhi
I think you can do like this

{% assign productTitle = product.title %}

{% assign allProductsWithSameTitle = collection['all'].products  | where: "title", productTitle  %}
{% assign productsSortByPrice = allProductsWithSameTitle  | sort: "price"  %}
{% assign lowesePriceProduct = productsSortByPrice | first %}

Thanks!