Jump to content

[SOLVED] CSV Importing categories.csv creating its own auto-increment ID's. Not my own ID numbers


Recommended Posts

If categories_import.csv file (ps sample file) has to assigning its own auto-increment ID's, so why there is an ID column in the categories_import.csv file, I don't understand.

 

Could someone advice to me, if there is a way to assign my own ID numbers to my categories and sub-categories without auto-increment?

Edited by Peda (see edit history)
Link to comment
Share on other sites

Hi,

same problem also for me.

 

I've found that the problem isn't in the import code, but in the "global" save method.

Now, i use a temporary workaround, an override of class "ObjectModel".

 

Code causing problem autoincrement : /classes/ObjectModel.php ; method : add ; rows : 460-462

  // Database insertion
 if (isset($this->id))
  unset($this->id);

 

In the override file : /override/classes/ObjectModel.php I've copied the entire method and then simply commented the 2 rows.

 

I'm thinking to use this workaround only for the import step, I don't know if it may cause other problems.

 

I hope this will be useful.

 

Best regards

Link to comment
Share on other sites

Thank you Xchriz. I will try your solution now.

 

The worst part of this issue is: I have 50 000 products, 19 000 sub-categories.

 

Ok I import the categories.csv by prestashops auto ID method, then start to preparing the products.csv.

In the products.csv file the 4th column is Categories (x,y,z...) column.

I am preparing this column with my own category ID's.

Like this: 67452, 67456, 67472, 67451, 67075, 67079, 67081, 67082 (Detailed image at below)

 

After this, while importing the product.csv, prestashop looks for its own auto-increment ID's in the 4th column (Categories (x,y,z...) column) of product.csv file.

How can I prepare again this categories column (50 000 rows) in products.csv according to prestashops auto-increment ID's?

 

Products.csv screenshot

d7tsf.jpg

Edited by Peda (see edit history)
  • Like 1
Link to comment
Share on other sites

If you use the above workaround, it is Global.

That means all creations of prestashop entities are involved, therefore also all kind of CSV imports...

 

If you import the categories with your old/original ID, you can then import products with your old/original ID and its related old/original IDs of categories.

 

My English is not so good, i hope i've explained it

Link to comment
Share on other sites

Hi,

 

It's not a bug sad.gif

It exist 3 posibilities when importing categories:

  • "id_category" is empty : we add this category with auto incrementation
  • "id_category" isn't empty :

  • if "id_category" exist in your the table category, we update this category
  • if "id_category" not exist in your the table category, we add this category

In your case, the "id_category" doesn't exist. Well, we add this category !

 

Best regards,

Loïc.

Link to comment
Share on other sites

Yes, but this behavior is not suitable to this scenario :

I've a highly customized old prestashop (1.3) so ti perform the upgrade i've decided to build a new clean installation of PS 1.5.

I need to import old data into the new system BUT i need to preserve the old primary-keys.

The import procedure if the category doesn't exists in db will always create a new primary-key,

for a given csv like :

 

ID;categoryname

10;alfa

20;beta

30;gamma

 

the import's result will be

3;alfa

4;beta

5;gamma

 

And this is a very big problem, especially because i need to maintain the associations between categories and products.

 

Br,

Chris

  • Like 1
Link to comment
Share on other sites

Hi,

 

It's not a bug

It exist 3 posibilities when importing categories:

"id_category" is empty : we add this category with auto incrementation

"id_category" isn't empty :

if "id_category" exist in your the table category, we update this category

if "id_category" not exist in your the table category, we add this category

In your case, the "id_category" doesn't exist. Well, we add this category !

 

Best regards,

Loïc.

 

Hi Loïc,

 

I think there is still a bug

please see http://forge.prestashop.com/browse/PSCFV-4285

 

when you import categories, prestashop will override the ID's from the csv, this means the sub-categories parent ID numbers aren't correct any more.

This is the same with products & combinaties

If prestashop changes the product ID's given in de product.csv, the main products id's in the combinations file aren't correct any more.

 

Br,

E-raser

Link to comment
Share on other sites

Hi,

 

It's not a bug sad.gif

It exist 3 posibilities when importing categories:

  • "id_category" is empty : we add this category with auto incrementation
  • "id_category" isn't empty :

  • if "id_category" exist in your the table category, we update this category
  • if "id_category" not exist in your the table category, we add this category

In your case, the "id_category" doesn't exist. Well, we add this category !

 

Best regards,

Loïc.

 

Hi, Mr. Loïc

I agree with xchriz and E-raser.

Ok I see, youre right, if the id_category column is empty than lets process it with auto-increment.

But in my category.csv file, the id_category column filled with my own ID's. Its full of my own assigned ID's.

 

And I am using these ID's in my product.csv file in Categories (x,y,z...) column.

So, this way my thousand of products goes to their sub-categories correctly.

 

The result is, I have to use my own category ID's to import my product.csv correctly.

Regards

Edited by Peda (see edit history)
Link to comment
Share on other sites

Il s'agit vraiment d'un sérieux bug! Qui empêche toutes utilisation de la version de Prestashop 1.5.17 du moins pour l'importation de catégorie avec utilisation de son propre ID. Cette erreur et très dommageable et bloc l'utilisation de la dernière version pour l'importation de csv!

La solution proposé plus haut dépanne, mais cela n'es pas digne d'une version stable, car ce problème impacte de façon très large l'utilisation de Prestashop par rapport à l'import de catégorie et de produits via des fichiers csv, ce qui est très souvent utilisé.

Le bug tracker http://forge.prestas...owse/PSCFV-4285 est pris en charge par Loic Lefevre.

Edited by Nelson (see edit history)
Link to comment
Share on other sites

So, me and other users who have to import their bulk .csv files, can not use Ps 1.5 until next version.

This is really painful.

 

If there is a workaround by changing some file/s, please tell. At least, a lot user can use Ps 1.5.

 

Simple suggestion:

I want to use Ps 1.5 for its new technology + performance + new look. For not multi shop.

If I can use my single shop properly and efficiently then I can start to think using multi shop. But not now.

Maybe you can put a radio button option for ID's. So I do not use multi shop, but I can import my .csv files properly.

Regards

  • Like 1
Link to comment
Share on other sites

Hi,

 

I found a temporary work around for importing categories that worked for me:

 

1) fresh install (or make sure in your db ps_category,ps_category_group,ps_category_lang, ps_category_shop has only the default categories (category root & home, ID 1 & 2))

 

2) as xchriz already said, in classes/ObjectModel.php on line 460 change:

 

 

if (isset($this->id))

unset($this->id);

 

to

 

 

// if (isset($this->id))

// unset($this->id);

 

3) import your categories csv, make sure your main categories have category id 2 as parent category

 

4) put classes/ObjectModel.php back to normal

 

I don't know if this will work for products/combinations.

 

Br,

E-raser

Edited by E-raser (see edit history)
  • Like 2
Link to comment
Share on other sites

I have imported a few csv files into 1.5 and the above is true, the ID does auto increment. Another problem I have found is that when I import the products, they don't show under their categories in B/O. I haven't managed to import combinations yet because I don't understand the setup in 1.5 :unsure:

  • Like 1
Link to comment
Share on other sites

Hi,

 

I found a temporary work around for importing categories that worked for me:

 

1) fresh install (or make sure in your db ps_category,ps_category_group,ps_category_lang, ps_category_shop has only the default categories (category root & home, ID 1 & 2))

 

2) as xchriz already said, in classes/ObjectModel.php on line 460 change:

 

 

if (isset($this->id))

unset($this->id);

 

to

 

 

// if (isset($this->id))

// unset($this->id);

 

3) import your categories csv, make sure your main categories have category id 2 as parent category

 

4) put classes/ObjectModel.php back to normal

 

I don't know if this will work for products/combinations.

 

Br,

E-raser

 

This worked for me

  • Like 1
Link to comment
Share on other sites

Hi all,

 

I have added an option which can force your id's for the product import and category import.

Be careful : if you use the multistore with the product sharing, it's preferable to make your imports before activating the multistore.

 

Thanks for your report !

 

Best regards,

Loïc.

Link to comment
Share on other sites

Hi all,

 

I have added an option which can force your id's for the product import and category import.

Be careful : if you use the multistore with the product sharing, it's preferable to make your imports before activating the multistore.

 

Thanks for your report !

 

Best regards,

Loïc.

 

Thank you.

I need to install all again or I can change only some files like "classes/ObjectModel.php"?

Link to comment
Share on other sites

  • 2 weeks later...

i'm tried import products with csv on ps 1.5.1 everything success. but the default category products automatic being in Home Category.

 

ID insert this at Categories(x,y,z...) csv -> still can fully understand about this condition.

Example:

already tried this

- Home, iPods iPods, iPods Battery ( success but default category automatic being -Home ), how to made default category is -iPods Battery.

 

and i tried ;

 

- iPods Battery, Home, iPods iPods, iPods Battery ( everything categories is missing with this condition).

 

 

Wishing somebody can give hand to me! thank already searching but nothing. :(

Link to comment
Share on other sites

  • 2 weeks later...

Hi!

 

Related to this thread, ... I'm trying to create Category via Code.

 

$category = new Category(50);

 

... but never assigns id=50 to new Object, only autoincremental value.

 

 

Problem exists, when i assign ID in constructor and ID not exists in database. With this fix... it works for me:

 

ObjectModel.php (@version Release: $Revision: 7499)

Line:217

...
$result = Cache::retrieve($cache_id);
if ($result)
{
  ...
}
...

 

Fix

...
$result = Cache::retrieve($cache_id);
if ($result)
{
  ...
}
else
  $this->id = (int)$id;
...

 

 

It's correct?

 

 

Regards

Edited by Jubri (see edit history)
Link to comment
Share on other sites

  • 2 weeks later...
  • 2 weeks later...

Hello! I have been following this thread and require assistance. My main issue is the inability to use my own product id numbers - they get replaced with an auto-generated number when i do a csv upload. I'm currently running 1.5.0.17 and am wondering if this has been resolved in the latest version 1.5.2? I really need a solution for this. Thanks!

Link to comment
Share on other sites

  • 4 weeks later...

Hello Loic,

 

I have seen in ObjectModel.php that you added "&& !Tools::getValue('forceIDs')"

 

I want to use add method from a script i made myself with ids forced.

 

How can I force this flag in my script??

 

Wich method from Tools do I have to use to put the value in "forceIds" ?

 

I searched a "setValue()" but didn't found it............

 

(you can answer me in french in if you want)

Link to comment
Share on other sites

Im also experiencing the same problem using 1.5.3 when importing products. (importing categories works as intended). That is: even with forced id-s you get auto-increment.

 

 

Also getting the following errors with products :

import replaces categories with "home" (even with the sample csv file that PS provides), so the uploaded products are all in "home" instead of the desired categories/subcategories

Pictures are not uploaded (suprisingly image upload works with category import, but not with products)

Edited by Sippa (see edit history)
Link to comment
Share on other sites

  • 3 weeks later...

Hi. I have the same problem. No only with products, also in categorys. In my cvs i have ID:5, and after importing, appears as 25.

It's so difficult to do something with this, because it makes changes everywhere you use IDs.

But.. anyone know how to "erase all" in order to start again with ID 1? Somebdoy put some cod about truncating, but don't know where to put it.

 

Good bye and thanks

Link to comment
Share on other sites

SOLVED!

 

Finally the solution with CSV products Categories import is here https://github.com/P...f233883e36da2cf

 

Just add to file AdminImportController.php (controllers/admin/AdminImportController.php) before line 1151 :

 

if(isset($info['category']))

$product->category = explode($this->multiple_value_separator, $info['category']);

 

B)

 

P.S. One more - try to use ID's (for example 32,46). When I used categories name, there still have some problem. With ID's everything fine!

Edited by antoniony (see edit history)
Link to comment
Share on other sites

Prestashop 1.5.3.1 has an option to "force ids" when importing.

 

SOLVED!

 

Finally the solution with CSV products Categories import is here https://github.com/P...f233883e36da2cf

 

Just add to file AdminImportController.php (controllers/admin/AdminImportController.php) before line 1151 :

 

if(isset($info['category']))

$product->category = explode($this->multiple_value_separator, $info['category']);

 

B)

 

P.S. One more - try to use ID's (for example 32,46). When I used categories name, there still have some problem. With ID's everything fine!

Link to comment
Share on other sites

  • 3 months later...

Hello, have someone found the setting in V1.5.4.1 to import cat and sub cat?

The example file from the shop are so basic and contains only à few main categories. I startend with it, read many forums and nothing will works on these version, only creating main catogories.

Thnx in advance,

Generaal

Link to comment
Share on other sites

×
×
  • Create New...