Jump to content

duplicated rows in "Stock management"


Anonymous No.2

Recommended Posts

I have many duplicated rows of the same product in the Admin>Catalog>Stocks while in Admin>Catalog>Products I have only one row for the same products.

I have uploaded my products using webservice, could it be the reason/bug?

How to fix these duplicated rows?

SELECT * FROM `ps_stock_available` WHERE `id_product` = 221

returns only one row, but in Admin>Catalog>Stocks there are many rows for this product

I have removed some orphans from ps_stock_available with this SQL, but it did not help

delete FROM `ps_stock_available` WHERE not exists (select p.id_product from ps_product p where p.id_product=ps_stock_available.id_product)

 

Edited by Anonymous No.2
Added "removed some orphans"... (see edit history)
Link to comment
Share on other sites

Searching for duplicate entries

SELECT `id_product`,count(*) as cdup FROM `ps_stock_available` group by `id_product` having cdup>1 

resulted in finding one product which had a non-existent attribute id. I have deleted that line, but it didn't help.

I can see it seems all my products (uploaded via webservice) in Stock management are repeated 11 times. It looks like a wrong SQL join (inner instead of outer) or smth. like that somewhere, but I don't know where to look.

 

Link to comment
Share on other sites

I cannot see an SQL with profiling turned on, instead I have found (after turning on debug) there is an ajax call to /admin..../index.php/api/stocks/

which returns duplicates and there is a column 'combination_id', but I cannot find that column 'combination_id' in the database structure.

{"product_id":195,"combination_id":3500,...}

This lead me to the following SQL, showing products with orphan attributes, if I understand DB structure correctly:

SELECT * FROM `ps_product_attribute` where not exists (select ps_attribute.id_attribute from ps_attribute where ps_product_attribute.id_product_attribute=ps_attribute.id_attribute) ORDER BY `id_product`

Deleting orphans solved the problem. Interesting, some of the demo products also had some non-existent attributes assigned in this table.

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...