Score:0

I can't get rid of duplicates in products view

pw flag

I tried everything. I reduced the number of fields. I set the Query settings to distinct. Product: Variations (variations:delta) is also set to 0.

When I search by SKU I get duplicates. SKU Search is exposed filter for admins.

This is the generated query:

SELECT DISTINCT "commerce_product_field_data"."created" AS "commerce_product_field_data_created", "commerce_product_field_data"."product_id" AS "product_id", "commerce_product_variation_field_data_commerce_product__variations"."variation_id" AS "commerce_product_variation_field_data_commerce_product__vari", "taxonomy_term_field_data_commerce_product__field_catalog"."tid" AS "taxonomy_term_field_data_commerce_product__field_catalog_tid", DATE_FORMAT((DATE_ADD('19700101', INTERVAL commerce_product_field_data.created SECOND) + INTERVAL 7200 SECOND), '%Y%m%d') AS "commerce_product_field_data_created_day"
FROM
{commerce_product_field_data} "commerce_product_field_data"
LEFT JOIN {commerce_product__variations} "commerce_product__variations" ON commerce_product_field_data.product_id = commerce_product__variations.entity_id AND commerce_product__variations.deleted = '0'
LEFT JOIN {commerce_product_variation_field_data} "commerce_product_variation_field_data_commerce_product__variations" ON commerce_product__variations.variations_target_id = commerce_product_variation_field_data_commerce_product__variations.variation_id
LEFT JOIN {commerce_product__field_catalog} "commerce_product__field_catalog" ON commerce_product_field_data.product_id = commerce_product__field_catalog.entity_id AND commerce_product__field_catalog.deleted = '0'
INNER JOIN {taxonomy_term_field_data} "taxonomy_term_field_data_commerce_product__field_catalog" ON commerce_product__field_catalog.field_catalog_target_id = taxonomy_term_field_data_commerce_product__field_catalog.tid
WHERE ("commerce_product_field_data"."status" = '1') AND ("commerce_product__variations"."delta" = '0')
ORDER BY "commerce_product_field_data_created_day" DESC
LIMIT 500 OFFSET 0

I don't know how else to ask this question. I did lots of research. Nothing helps. The duplicates are keep on showing up.

thaidrupaler avatar
pw flag
and this is the screenshot of view https://snipboard.io/L7Ybk5.jpg
thaidrupaler avatar
pw flag
https://snipboard.io/l32gqp.jpg is the second part of view
thaidrupaler avatar
pw flag
I want to give us admins many options to filter out products...search by SKU, title, select only specific categories etc. But each time there are annoying duplicates in view results.
Score:1
it flag

I can't tell how you've configured the View to add DISTINCT to the query, but just looking at the query, it's clear that this will return every distinct combination of far too many variable items. Even the fact that created timestamp is in there is likely enough to always return everything ... unless literally every combination of product + variation + catalog term + etc. was created on the same day.

At the end of the day, this isn't a "remove duplicates from Views results" problem so much as a "how to configure a better View" problem. I'm not sure that's appropriate for Drupal Answers, tbh.

thaidrupaler avatar
pw flag
I would just want to list products, category, SKU, title and price without duplicates. Is this possible? You are saying that Query Distinct is the problem? I disable Distinct Query under advanced view and when I search for SKU I get each product listed twice again
it flag
I'm saying the way the DISTINCT clause is being added to the query is the problem. Can you satisfy your criteria by making this a View of product variations, perhaps? I don't see in your list any information that must come from the product itself, and even if you did need a field from the parent product, there is a single value reference field from the variation -> product you could join through. No duplicates that way.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.