Can Importing duplicate products cause records to be deleted?

  • Posts: 16
  • Thank you received: 4
2 years 9 months ago #339573

-- HikaShop version -- : 4.4.5
-- Joomla version -- : 4.1.0
-- PHP version -- : 8.0.15

My goal was just to update the quantity for existing products using text area import. From a previous hikashop export, I pasted in the product_code and product_quantity columns containing about 400 entries into the text area import. Note, at the time of the import, I didn't realize that some of these entries were duplicates.

The import updated some records and for others it deleted the existing database record and created a new one.

I compared a previously saved export file with one done after this import and verified that some product_id rows were missing (deleted from the database), and a new product_id created with same product_code and updated quantity. But of course, all my other product data for that record was lost.

Though, I didn't intend to have duplicate import rows, I'm curious why that would cause the import to delete records with existing product_code and create a new one.

I just want to figure out the cause so I can avoid this in the future.

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
2 years 9 months ago #339593

Hi,

There is no DELETE mysql query on the hikashop_product in the code of the import system.
However, there is a REPLACE mysql query.
This allows the system to replace the data in the database with the data from the CSV file when there and if not insert a new product entry:
dev.mysql.com/doc/refman/8.0/en/replace.html
This avoids having to run first a mysql query to check if the products are already there or not, and then, having to run an update query for each entry. That would several reduce the amount of products that could be processed at once.

There is also a mechanism to load the product data in the database and fill the data from the CSV so that when the REPLACE runs, you don't loose the data already in there for the product.

But if you have several times the same product in the CSV file, that might lead to an unexpected behavior with the data of the products already in the database being lost.

The best though would be to use a mass action with a filter "import from the CSV" when you want to update data with partial information. This is less optimized as it load and save each product one by one. It wont' change much in terms of speed for only 400 products (I'm talking about optimization when importings tens of thousands of products at once), but it will avoid the possibility of loosing product data as it will use a normal UPDATE query, not a REPLACE one.

Last edit: 2 years 9 months ago by nicolas.
The following user(s) said Thank You: cwpstech

Please Log in or Create an account to join the conversation.

  • Posts: 16
  • Thank you received: 4
2 years 9 months ago #339624

I think I learned what's happening. As part of my trial, I originally imported 10,000 products with product_msrp but not price_value. So now whenever I try and add just product_code and price_value through the import (Text Area) it deletes my original product_id and creates a new one for that product.

I experience the same result when I try to import from a CSV file. It deletes my original product_id and creates a new record with a new product_id

FYI, when I try and reload the CSV after the price_value has been created, it does see it as an existing record and no longer creates a new one.

I don't want to lose all the other field data on the existing products. What is the best method for mas importing the price_value to my existing products?

Last edit: 2 years 9 months ago by cwpstech.

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
2 years 9 months ago #339645

Hi,

I don't want to lose all the other field data on the existing products. What is the best method for mas importing the price_value to my existing products?

The best though would be to use a mass action with a filter "import from the CSV" when you want to update data with partial information.

You can do so via the menu System>Mass actions.

Please Log in or Create an account to join the conversation.

  • Posts: 16
  • Thank you received: 4
2 years 8 months ago #339669

I tested the "CSV products" filter in mass actions and that imported the record successfully w/o creating a new one. Thank you for the suggestion.

The following user(s) said Thank You: nicolas

Please Log in or Create an account to join the conversation.

Time to create page: 0.050 seconds
Powered by Kunena Forum