Jump to content

Duplicated list of product list, and how to fix it.


Wilfredcy

Recommended Posts

As you can see the file below, the product info is duplicated a few times.

 Here is my SQL query.

SELECT 

a.`id_product`,
b.`name`,
a.`reference`AS `main_sku`,
pa.`reference` AS `sku`,
b.`link_rewrite` AS `url`,
a.`price` AS `price`,
sav.`quantity`,
m.`name` AS `Manufacturer`

FROM `ps_product` a 
LEFT JOIN `ps_product_lang` b ON (b.`id_product` = a.`id_product`) 
LEFT JOIN `ps_stock_available` sav ON (sav.`id_product` = a.`id_product`) 
LEFT JOIN `ps_manufacturer` m ON (a.id_manufacturer = m.id_manufacturer)
LEFT JOIN  `ps_product_attribute` pa ON (pa.`id_product` = a.`id_product`)

WHERE 1 ORDER BY a.`id_product` ASC        

 

duplicate.JPG

Link to comment
Share on other sites

FROM `ps_product` a 
LEFT JOIN `ps_product_lang` b ON (b.`id_product` = a.`id_product`) 
LEFT JOIN `ps_manufacturer` m ON (a.id_manufacturer = m.id_manufacturer)
LEFT JOIN  `ps_product_attribute` pa ON (pa.`id_product` = a.`id_product`)
LEFT JOIN `ps_stock_available` sav ON ((sav.`id_product` = a.`id_product`) AND (sav.id_product_attribute is null OR pa.id_product_attribute = sav.id_product_attribute)

Try this way (not tested) :)

Edited by Rodrigo B Laurindo (see edit history)
Link to comment
Share on other sites

Update:

The problem is solved, thank for the help Rodrigo B Laurindo.

Here is the final code

SELECT 

a.`id_product`,
b.`name`,

a.`reference`AS `main_sku`,
pa.`reference` AS `sku`,
b.`link_rewrite` AS `url`,
a.`price` AS `price`,
sav.`quantity`,
m.`name` AS `Manufacturer`

FROM `ps_product` a 
LEFT JOIN `ps_product_lang` b ON ((b.`id_product` = a.`id_product`) AND (b.id_lang = "1"))
LEFT JOIN `ps_manufacturer` m ON (a.id_manufacturer = m.id_manufacturer)
LEFT JOIN  `ps_product_attribute` pa ON (pa.`id_product` = a.`id_product`)
LEFT JOIN `ps_stock_available` sav ON ((sav.`id_product` = a.`id_product`) AND (sav.id_product_attribute is null OR pa.id_product_attribute = sav.id_product_attribute))


WHERE 1 ORDER BY a.`id_product` ASC 

 

Link to comment
Share on other sites

Try this:

SELECT

a.`id_product`,
b.`name`,

a.`reference`AS `main_sku`,
pa.`reference` AS `sku`,
b.`link_rewrite` AS `url`,
a.`price` AS `price`,
sav.`quantity`,
m.`name` AS `Manufacturer`

FROM `ps_product` a 
LEFT JOIN `ps_product_lang` b ON ((b.`id_product` = a.`id_product`) AND (b.id_lang = "1"))
LEFT JOIN `ps_manufacturer` m ON (a.id_manufacturer = m.id_manufacturer)
LEFT JOIN  `ps_product_attribute` pa ON (pa.`id_product` = a.`id_product`)
LEFT JOIN `ps_stock_available` sav ON ((sav.`id_product` = a.`id_product`) AND (coalesce(sav.id_product_attribute,0) = 0 OR pa.id_product_attribute = sav.id_product_attribute))


WHERE 1 ORDER BY a.`id_product` ASC 

 

Link to comment
Share on other sites

Of course it is duplicating 🤔

SELECT

a.`id_product`,
b.`name`,

a.`reference`AS `main_sku`,
pa.`reference` AS `sku`,
b.`link_rewrite` AS `url`,
a.`price` AS `price`,
sav.`quantity`,
m.`name` AS `Manufacturer`

FROM `ps_product` a 
LEFT JOIN `ps_product_lang` b ON ((b.`id_product` = a.`id_product`) AND (b.id_lang = "1"))
LEFT JOIN `ps_manufacturer` m ON (a.id_manufacturer = m.id_manufacturer)
LEFT JOIN `ps_product_attribute` pa ON (pa.`id_product` = a.`id_product`)
LEFT JOIN `ps_stock_available` sav ON ((sav.`id_product` = a.`id_product`) AND ((coalesce(sav.id_product_attribute,0) = 0 and (pa.id_product_attribute is null))
OR (pa.id_product_attribute = sav.id_product_attribute)))


WHERE 1 ORDER BY a.`id_product` ASC

 

Link to comment
Share on other sites

Hi, it work, THANK YOU

The code:

SELECT 

a.`id_product`,
b.`name`,

a.`reference`AS `main_sku`,
pa.`reference` AS `sku`,
b.`link_rewrite` AS `url`,
a.`price` AS `price`,
sav.`quantity`,
m.`name` AS `Manufacturer`

FROM `ps_product` a 
LEFT JOIN `ps_product_lang` b ON ((b.`id_product` = a.`id_product`) AND (b.id_lang = "1"))
LEFT JOIN `ps_manufacturer` m ON (a.id_manufacturer = m.id_manufacturer)
LEFT JOIN  `ps_product_attribute` pa ON (pa.`id_product` = a.`id_product`)
LEFT JOIN `ps_stock_available` sav ON ((sav.`id_product` = a.`id_product`) AND (coalesce(sav.id_product_attribute,0) = 0 OR (pa.id_product_attribute is null)) OR (pa.id_product_attribute = sav.id_product_attribute))

WHERE 1 ORDER BY a.`id_product` ASC   

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...