Jump to content
thirty bees forum
  • 0

[Solved, issue request created] Please help: CSV Product Import problem: Moving Category Issue + Product Breadcrumb not updating + Default Category Issue


Acer

Question

Hi I've encountered a bug when trying to move a product to a different category with CSV import.
(On TB 1.1.0 on local Xampp dev, worked before on 1.08)

In short:

  • On initial import, the product is assigned to the correct category and this category is set as the default category - which is correct.
  • The product breadcrumb is also correct: Coffee and Tea -> Tea -> Test Product 1
  • Bug occurs when I try to do a re-import and change the default category, to Coffee (cat id 4) for example, then the following happens:
    • Although the product has been moved to the correct category and is listed in the correct category in both the front-end and back-end,
    • The product breadcrumb incorrectly shows the old path and default category instead of the new one
    • The default category has changed to Root and not the correct category (Coffee)
    • If I log in and change the product's default category manually, then the product's breadcrumb changes to the correct category Coffee and Tea -> Coffee -> Test Product 1
    • From what I recall, this was working in 1.08 where I could re-import the product and move it's category around without any issues. Front-end product breadcrumb would update correctly.
    • Changing the product categories during subsequent imports make no difference and the front-end still displays the old path and default category of the initial 1st import 😞
    • Only after changing the default category manually does the new category reflect in the front-end product breadcrumb
  • Also, I'm not sure why the Home category is not selected if Root (1) is specified...
  • Images below

How do we fix this? Please help!

Screenshot steps:

CSV for initial category import: 5 (tea / default cat), 3 (Tea and Coffee / Parent Cat), 1 (Root):

847422454_initialcsvimport.png.c5b3e7acaf1f56035483aa0efbe64713.png
 

Correct default category (though Home appears to be unselected):

572062160_initialimportproductincorrectcategory.png.796b116290216c9a8f4d9a17970cae47.png
 

Initial import: Breadcrumbs Correct:

1186687257_initialimportcorrectproductbreadcrumb.png.884318bb03bc3bb69a6e5bc41cd8d6d4.png
 

CSV to update / change default category to Coffee: 4 (coffee / default cat), 3 (Tea and Coffee / Parent Cat), 1 (Root):

83705098_updatecsvimport.png.985eca24e41cc4bca5dbbe845439ac43.png
 

Incorrect default category after product import update to change category:

634140768_updatecsvimportincorrectdefaultcategory.png.49aa88553221af2602e18869fb644929.png
 

If I manually change the default category to Coffee, then the product breadcrumb updates and displays the category correctly:
 

1202661854_changedefaultcategorytocoffee.png.579b676b1b44ad3c0f8aa8ec39afa4d3.png
 

Correct product breadcrumb after changing default category manually:
 

1515335090_correctproductbreadcrumbafterchangingrootcategory.png.d67a6d3c905f0f946d35b0715f617cdb.png
 

 

Once again, your help is appreciated in advance. Not sure if I'm doing something wrong?

 

 

Edited by Theo
Link to comment
Share on other sites

23 answers to this question

Recommended Posts

  • 0

IF I understand you good, you have problem on CSV products import but for updating products categorie default only ?

here is the piece of code that I think is doing the thing from AdminImportController.php file :


        // Will update default category if there is none set here. Home if no category at all.
        if (!isset($product->id_category_default) || !$product->id_category_default) {
            // this if will avoid ereasing default category if category column is not present in the CSV file (or ignored)
            if (isset($product->id_category[0])) {
                $product->id_category_default = (int) $product->id_category[0];
            } else {
                $defaultProductShop = new Shop($product->id_shop_default);
                $product->id_category_default = Category::getRootCategory(null, Validate::isLoadedObject($defaultProductShop) ? $defaultProductShop : null)->id;
            }
        }

That means If the product has already a default category assigned, the new import csv will not erase it and keep it, while adding news categories to the product settings.

 

PS: Note that ID cat '1' is Root and Home is '2', so if you want products assign to home use ID 2 instead of 1.

Link to comment
Share on other sites

  • 0

Hi Zen

Thanks for the feedback. Yes, this is what I'm looking for. I will have a look at this code and see if I can figure it out and make it do what I want it to do.
The only thing is: surely what the system doing is a bug? 
Because, unless I'm mistaken, the system should always allow you to update a target product's category and then set this category as default (via CSV Import update)?

 

Link to comment
Share on other sites

  • 0
8 minutes ago, Theo said:

Hi Zen

Thanks for the feedback. Yes, this is what I'm looking for. I will have a look at this code and see if I can figure it out and make it do what I want it to do.
The only thing is: surely what the system doing is a bug? 
Because, unless I'm mistaken, the system should always allow you to update a target product's category and then set this category as default (via CSV Import update)?

 

It is not a bug.. it is a functionnality 🙂 lol

CSV import is good and doing what you want on the first import.. if your product has already a dafault category setup, the csv import will not update that default category assigned, if you want it different you have to change the code.

On my opinion it is totally normal behaviour, better not delete the default category with csv... just adding more is better option I think, it will need maybe a new column to force default category ID to be setup and everybody will be happy then.. have to think about adding it to csv import system.

Link to comment
Share on other sites

  • 0

Good suggestion. However, for me it's a bug, because you should be able to update the product's category on CSV import (which works) and this new category should then be set as default (which doesn't work).
If it doesn't do this, then it prevents you from doing a mass category update on bulk CSV product import... which doesn't help if you want to move 300 products to a different category for example...
or you noticed that with your initial import, the products where being assigned to the incorrect category.
So you go, "no problem, I'll just do a bulk category update with CSV import" only to find that it doesn't work as you expected 😞 

So no, not feature, bug - imo.

Edited by Theo
Link to comment
Share on other sites

  • 0

If your product is already setup, and you upload more infos... would you like theses previous infos to be deleted ?? I don't ! It will kill the shop for most of users.

And When you give categories to add to your product, wich one is the default one ?? the first one ? the last one ?? the one in the middle maybe ?? or by cat ID ordered INC or DESC... who knows : So I tel you again this is not a BUG ! even if it doesn't suits your own needs on that case.. it the best for most users, now you can add one more column for DEFAULT CAT and update the script so it will assign that and remove the old one.

Read the comments in the code, it's only logic.

 

Link to comment
Share on other sites

  • 0

You can use the CSV file to update the product's information. So no, not deleting anything. In terms of the default category, the system already picks the 1st id that you select. So it's sub/parent/root if you specify 5,3,1 (tea,tea & coffee,root).
In terms of functionality, I think it's perfectly reasonable to assume that you should be able to update your product's info - which you can already do without deleting anything.
What I would like to see is that if you have a new category in your import update csv, then the system should replace what's currently there and make it default.
If there is no category specified, it should not delete anything.

Incidentally, I'm not the only one looking for this type of functionally - there appears to be a similar problem (and solution) in PS 1.7 with another user requesting the same thing.
Briefly looking at the code, it appears we may be able to adjust the TB code here to do something similar.

https://github.com/PrestaShop/PrestaShop/issues/10871

Edited by Theo
Link to comment
Share on other sites

  • 0

Like you said, you CAN use the csv to update infos.. but it's not really his purpose, the main goal for csv is to import products on an empty shop, then more options have been added, So you can do whatever you want for that,

In my case, I update default cat by SQL queries, directly on phpmyadmin, so fast and so efficient, I don't bother using csv.

On your github issue it resumes what I said to you :

Solution 1 : Adding a column in import file with default value

or  Solution 2 : Create a checkbox in the form

If this have been really usefull, and used by many.. this will have been done since a long time, but now you are the second to ask it, maybe it will be done soon.

Link to comment
Share on other sites

  • 0

In some cases, administrating a large store, you may want to use CSV import to help with bulk updates. I'm sure that I'm not the only one requesting this.
And looking at that PS 1.7 Github issue - it's more than just two people interested in this... lol

Ideally, I'd like to be able to this on CSV import without having to mess around with SQL queries - as my shop admin users are not very technical in that regard and it's not a good idea to let them play with SQL queries.

However, for my purposes, may I ask you to please share the Query that use to update the default categories?
And it seems that you've had the need to update the default categories in bulk before so...

Edited by Theo
Link to comment
Share on other sites

  • 0

For you only, because you know the results and it fits your needs, here is the modified code :

   // Will update default category with the first new one given. Home if no category at all.
	if (isset($product->id_category[0])) {
            $product->id_category_default = (int) $product->id_category[0];
        } else {
            $defaultProductShop = new Shop($product->id_shop_default);
            $product->id_category_default = Category::getRootCategory(null, Validate::isLoadedObject($defaultProductShop) ? $defaultProductShop : null)->id;
        }

et voilà...  and if we have a button.. or the new column.. then the deleted IF condition will take car of it... So Simple ^^

Link to comment
Share on other sites

  • 0

Thanks for this Zen.

I see the PS 1.7 solution will be integrated into PS. https://github.com/PrestaShop/PrestaShop/pull/10930
The dude there wrote this - it seems compatible and similar to what you wrote - what do you think of his approach to this? Can I use his code or should I use yours?

if (isset($product->id_category[0])) {
        $product->id_category_default = (int)$product->id_category[0];
    } else {
        if (!isset($product->id_category_default) || !$product->id_category_default) {
            $defaultProductShop = new Shop($product->id_shop_default);
            $product->id_category_default = Category::getRootCategory(null, Validate::isLoadedObject($defaultProductShop) ? $defaultProductShop : null)->id;
        }
    }

 

Link to comment
Share on other sites

  • 0

Can't you read and understand the code ?

mine is forcing to modifiy the default cat whenever you upload any csv product file.

the one you show : DOES the same 🙂  But it checks if the default cat is already set or not before changing it if none is provided in the CSV file.

  • Thanks 1
Link to comment
Share on other sites

  • 0

Actually, TB / PHP noob here 🙂 So, learning. It all looked a bit confusing at first - trying to make sense of the code. I guess I'll get there...
So hence this forum posts - to ask super-advanced TB pros for help. Thanks 👍

Edited by Theo
Link to comment
Share on other sites

  • 0

I have tested this solution, using the PS 1.7 variant of the code and can confirm that it's working 🙂 Thanks for the assistance, Zen 🙂

The code has the following effect:
On CSV Import, the product's category is updated, the product's breadcrumb is updated and the "default category" is updated and reflects in the backend 🙂

How to update:

In AdminImportController.php: 
Find:
// Will update default category if there is none set here. Home if no category at all. 

Change code to:  

if (isset($product->id_category[0])) { 

        $product->id_category_default = (int)$product->id_category[0]; 

    } else { 

        if (!isset($product->id_category_default) || !$product->id_category_default) { 

            $defaultProductShop = new Shop($product->id_shop_default); 

            $product->id_category_default = Category::getRootCategory(null, Validate::isLoadedObject($defaultProductShop) ? $defaultProductShop : null)->id; 

        } 

    } 


IMO, I believe this change should be integrated into TB. Similar to what they've done with PS 1.7 on this ticket:
https://github.com/PrestaShop/PrestaShop/issues/10871
https://github.com/PrestaShop/PrestaShop/pull/10930

I will try to create an issue ticket on this module in TB Github - but I'm not sure if this is the best place to make the suggestion or if others agree?

Edited by Theo
Link to comment
Share on other sites

  • 0
4 minutes ago, zen said:

this change can be integrated only if you take into account that not averybody want this to happen ... so remember the 2 points : new column or button to force it .

Understood

Edited by Theo
Link to comment
Share on other sites

  • 0
8 hours ago, Theo said:

Good suggestion. However, for me it's a bug, because you should be able to update the product's category on CSV import (which works) and this new category should then be set as default (which doesn't work).
If it doesn't do this, then it prevents you from doing a mass category update on bulk CSV product import... which doesn't help if you want to move 300 products to a different category for example...
or you noticed that with your initial import, the products where being assigned to the incorrect category.
So you go, "no problem, I'll just do a bulk category update with CSV import" only to find that it doesn't work as you expected 😞 

So no, not feature, bug - imo.

Wouldn't using PresTools be a better solution?   Also I would expect an upload to be that a bulk upload.  Not maintenance tool.

 

Link to comment
Share on other sites

  • 0
On 9/13/2019 at 6:42 PM, Factor said:

Wouldn't using PresTools be a better solution?   Also I would expect an upload to be that a bulk upload.  Not maintenance tool.

Thanks for the suggestion, I'll most certainly checkout PresTools for some of it's features, thanks.

However, the built-in 30Bz CSV Import can be used successfully as a maintenance tool and on many other online store platforms using CSV Import for maintenance is the standard. 
Cool thing with 30Bz, is that the CSV Import tool is actually very effective in this regard and works very well.

I have successfully and extensively tested it to update the following:

  • Product name, SKU, SEO (meta title, keywords), Brand / manufacturer, URL rewrite, Image add/replace, Quantity, Stock, Price, Tax Rules, On Sale, Sale from-to, Tags, Accessories and Product Category, etc.


That being said, as far as I know, it can't do 'product packs' and setting the product category to 'default category' needs a change to be made as per this posts.
All in all, it works well and is sufficient for my purposes regarding catalogue maintenance and update.

 

Edited by Theo
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...