Jump to content

How to set "default category" in the CSV import file?


Recommended Posts

My shop has a 3 level category structure

 

Top Level - All Products (Cat ID 2)

Second Level - Wodgets (Cat ID 3), Widgets (Cat ID 4)

Third Level - Left Handed Wodgets (Cat ID 5), Right Handed Wodgets (Cat ID6), Left Handed Widgets (Cat ID 7) and Right Handed Widgets (Cat ID 8).

 

Now I want my Right Handed Widgets to appear in the category list page

for all three levels i.e. whether I click on the menu link for All Products, Widgets or Right Handed Widgets.

 

So in the CSV file which uploads the data to my database I show the category numbers

as (2, 4, 8).

 

So far so good.

 

BUT....

 

I have noticed that in some circumstances the breadcrumb for my individual Right Handed Widget doesn't show the complete bread crumb trail down through the hierarchy.

 

I discovered that in the "Info" tab for each product in the BO you are supposed to chose the default category.

 

But according to Rocky (in this thread http://www.prestashop.com/forums/topic/76789-solvedlink-problem-breadcrumb-and-dc/ ) it isn't possible to set the default category via the CSV file.

 

So how can it be done?

I don't want to click on every single product in the BO to change it.

 

The only other alternative I can think of is to go into the "products table" in the database via phpMyAdmin and manually change the value of the default category there.

Not something I enjoy doing either.

 

Is there supposed to be a better way?

Is this a flaw in PrestaShop CSV import functionality?

Link to comment
Share on other sites

Have you tried doing your default category in reverse? default_cat,4,2 Or just leaving the whole breadcurmb trail out all toget and just entering the default category. Each SEEMS like it might work, but every shop I have done so far, I erase the breadcrumb file, so I have never worked with it.

Link to comment
Share on other sites

Well it seems to me that the breadcrumb is a useful feature so I'd like to keep it.

 

Haven't tried changing the order of the category numbers.

I was hoping there might be some documentation on this or perhaps some of the PrestaShop officianados might know.

Link to comment
Share on other sites

I decided to fix this by running an update query through phpMyAdmin.

Here it is:

 

UPDATE ps_product SET id_category_default = 3 WHERE id_product < 11;
UPDATE ps_product SET id_category_default = 4 WHERE id_product > 10 AND id_product < 21;

 

Change the values of the id_category_default and the id_product as appropriate.

 

This still feels like a bug or more accurately an omission from the PrestaShop CSV import routine.

Maybe an opportunity for somebody to create a simple module to handle this a bit better?

Link to comment
Share on other sites

I believe I figured this out.

 

When you import a CSV file and there are multiple categories for any given product, what PrestaShop does is

choose the lowest integer value that it finds and designates that to be the default category.

 

It's a strange set up. If any thing it would have made more sense I think to set the highest integer as the default

category since category hierarchies are usually created with the more generic categories first (therefore get low integer category IDs) whereas most people would probably want the more specific, lower order categories as their defaults.

It seems like the CSV import script has got it back the front.

 

Bug report notification?

 

Again, I think there should be a better way in the CSV import routine to specific a default category for each product.

  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...

NOTE:

If you set all your default categories correctly using the SQL query above, be aware of one thing.

 

If you do any SUBSEQUENT csv file import, (even if you set the "Categories" column to "Ignore this column") the database

will reset the default category according to it's own wonky logic as described above.

 

SO...

I recommend that you save your SQL query as a .txt file somewhere handy so that you can copy and paste it into phpMyAdmin to re-run it later on.

Link to comment
Share on other sites

  • 2 weeks later...

I decided to fix this by running an update query through phpMyAdmin.

Here it is:

 

UPDATE ps_product SET id_category_default = 3 WHERE id_product < 11;
UPDATE ps_product SET id_category_default = 4 WHERE id_product > 10 AND id_product < 21;

 

Change the values of the id_category_default and the id_product as appropriate.

 

This still feels like a bug or more accurately an omission from the PrestaShop CSV import routine.

Maybe an opportunity for somebody to create a simple module to handle this a bit better?

 

Hi,

import tool works differently for me.

Default category is the first in the list of column Categories(x,y,z)!!

Are you sure, you've tried this?

For me it works perfectly

Link to comment
Share on other sites

Hi,

import tool works differently for me.

Default category is the first in the list of column Categories(x,y,z)!!

Are you sure, you've tried this?

For me it works perfectly

 

Yes, but is "x" always a lower integer value than "y" and "z"?

If so, it doesn't disprove what I explained before.

Link to comment
Share on other sites

  • 4 months later...

Hi,

import tool works differently for me.

Default category is the first in the list of column Categories(x,y,z)!!

Are you sure, you've tried this?

For me it works perfectly

 

can you give example please!! i'm still not get it with how to set default categories with csv!! please :mellow:

Link to comment
Share on other sites

  • 7 months later...

I think, this is not good consideration from prestashop developers. I have same problem, actually uploaded 50k products from csv and really in category column "CATEGORIES (X,Y,Z)" means

 

X = DEFAULT CATEGORY, but its bad. Default category should be automatically deepest one, it means Z.

 

Actually i dont know, how to change on all products, because its so many and also categories and subacategories is very many.

 

SQL query is not effective on so many products, categories and subcategories.

 

How to do ?

Link to comment
Share on other sites

  • 2 weeks later...

I read the .csv files as "(x,y,z)" when I imported the .csv with all the categories, it just created NEW categories: X, Y, Z. Like TWD, I wanted all the products (if that is my understanding) to go to ALL Products, then essentially into their prospective subcategory. Stupid me, thought that maybe it had something to do with the commas since I'm using Comma delimited, etc. So I thought I would try and few things in test .csv but not am rethinking that I'm in over my head! As per the (limited) instructions, you would think that you are to use: Cat1,Cat2,Cat3 or using spaces: Cat1, Cat2, Cat3.

 

So, now I'm reading about breadcrumbs.....guess I'll just load and go and painstakingly change each product's category to include the ones I want. Presta directions...gotta love 'em (especially for tech-less newbies!)

Link to comment
Share on other sites

  • 1 month later...
  • 8 months later...

I am half illiterate in programming (can only read stuff, but not write), but I suppose I found the problematic line in the AdminImportController.php code for the x,y,z issue (we want z to be default instead of x):
 
$product->id_category_default = isset($product->id_category[0]) ? (int)$product->id_category[0] : '';

 

It seems '0' is the counter for the top category (x) since the list of categories in the import file would usually start from top to down (x, y, z... and not z, y, x,..). I can imagine the problem would be solved if we would command it to take the max number built in $product->id_category[].

 

So, maybe anyone less illiterate than me could tell me if the following syntax would work?
 
$product->id_category_default = isset($product->id_category[0]) ? (int)$product->id_category[max($product->id_category[])] : '';

 

 

Or kindly suggest the necessary corrections.... :-)

 

Any useful contribution would be highly appreciated and rewarded with many very kindly thankful words!

Link to comment
Share on other sites

  • 5 months later...

I decided to fix this by running an update query through phpMyAdmin.

Here it is:

 

UPDATE ps_product SET id_category_default = 3 WHERE id_product < 11;
UPDATE ps_product SET id_category_default = 4 WHERE id_product > 10 AND id_product < 21;
Change the values of the id_category_default and the id_product as appropriate.

 

This still feels like a bug or more accurately an omission from the PrestaShop CSV import routine.

Maybe an opportunity for somebody to create a simple module to handle this a bit better?

 

Hi All,

In addition to the above code, you should update ps_product_shop --> id_category_default as well in the same way. If not - your changes will not appear at back-office --> products -->associations and the URL of the concrete product would still have wrong "category name" included.

Cheers!

Link to comment
Share on other sites

  • 1 year later...

I just did it SUCCESSFULLY :)

 

You need to place the number of your default category at first place. For example, among (x,y,z ) z is the default category then in CSV file, under category column, write this (z,x,y) .

 

As you can see, z is the first category, prestashop will make it default category.

Link to comment
Share on other sites

  • 1 month later...

I just did it SUCCESSFULLY :)

 

You need to place the number of your default category at first place. For example, among (x,y,z ) z is the default category then in CSV file, under category column, write this (z,x,y) .

 

As you can see, z is the first category, prestashop will make it default category.

 

 

But what if Z is supposed to be nested under X and Y - does it still do that? 

 

I think if you import it using X,Y,Z - it creates the category X, with subcategory Y, with subcategory Z and labels X as the default.

 

Your way - (I think) creates category Z, with subcategory X and subcategory Y.

 

Which way did it turn out for you?

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