Jump to content
Alexander.X

[Free script] Mass move Products and Categories between categories

Recommended Posts

While I was worked on my e-store, I'ev found that there are no free and simple tools that allows just move products between categories, and move categories under another parent.

 

Yes, there are some mass-editing modules, but...

anyway, I've reinvented my own little wheel, and I've decided to share it with your :)

 

This is just a tiny prototype for now, but it is enough for my purposes (and I sure it works and not doing nothing undesired).

I have an idea of a complete universal tool that will integrate itself to ANY list of ANY entites (even to custom lists based on AdminController, created by other modules), but... lets see if there are any demand of this :)

 

So, if you will like this, it could be a reason to work for me :) If you will not - thats ok, it helped me already, and that could be anough :)

 

So, your are wellcome

https://github.com/AlexandrKhurs/mea/tree/master/01.prototype.override

 

(or direct link to download archive_

https://github.com/AlexandrKhurs/mea/archive/master.zip

Edited by Alexander.X (see edit history)
  • Like 1

Share this post


Link to post
Share on other sites

This is very interesting, but I get an error while trying to use it, maybe you also overriden the Category class and forgot to include the file?

Fatal error: Call to undefined method Category::getPath() in /home/admin/domains/greenmouse.pl/public_html/ps16/override/controllers/admin/AdminProductsController.php on line 76

Share this post


Link to post
Share on other sites

Well, thanks to Daresh, one more issue fixed (the issue caused an error in very specific situation).

Now script should work more stable.

 

Any new feedback is wellcome. :)

Edited by Alexander.X (see edit history)

Share this post


Link to post
Share on other sites

One more issue fixed: added a protection against moving category under itself or it's child/subchild category.

If you use script on your production - it's highly recommended to update to avoid an accidental damage category hierarchy by creating hierarchy loops.

Share this post


Link to post
Share on other sites

My customer is using this script and he somehow makes loops. Is it possible to attach a category this way:

A -> B -> C -> A

 

Or is it blocked?

 

(the loop that he made may be with the previous version of the script, but I'm not sure)

Share this post


Link to post
Share on other sites

As I posted some days ago, it was able before, but I've added protection against such loops in last update. Does your customer use updated version?

 

One more issue fixed: added a protection against moving category under itself or it's child/subchild category.

If you use script on your production - it's highly recommended to update to avoid an accidental damage category hierarchy by creating hierarchy loops.

Share this post


Link to post
Share on other sites

And one more thing: the updated version (and the most of PrestaShop core code) uses the built-in subtree detection method to detect if the selected "new parent" category belongs to category's subtree or not. This method assumes that nleft/nright node boundaries are consistent and actual at any time.  In most cases, if categories hierarchy is updated via Category::add / update methods - the node numbers are recalculated just after changes are made, and you even dont have to know about this. BUT if third-side code adds/updated categories directly vie SQL-query - the node numbers structure could stay inconsistent for some time, until the Category add/update is called and node numbers are recalculated. So, in theory, if numbers was broken, and my (or any) script is used just after that (before any changes via Category::add/update) - subtree detection may mistake.

 

There is a neglible probability of this case, but you could try to inspect all code to be sure that there are no _DB_PREFIX . 'category' INSERT/UPDATE/DELETE operations out of the Category class.

 

But, to be honest, much more possible that loops are created by older version of script.

Share this post


Link to post
Share on other sites

Hi, this it's simple what I need for categories, but I get this error when I try to move them: "You do not have permission to edit this."

 

do you know why? i'm using ps 1.7.1

 

thanks!

 

EDIT:

it works good if I comment the access error:  // if ($this->tabAccess['edit'] !== '1')  ...

Edited by nirmuc (see edit history)

Share this post


Link to post
Share on other sites

hello,

i get this error  Call to undefined method Category::getPath() 

how can i resolved

THANKS

Share this post


Link to post
Share on other sites

hello.

This issue was discussed and fixed at the begining of this topic.
The key is to copy /override/classes/Category.php to the same directory on your server.

If you used latest version, and have this file in appropriate place - maybe you just didnt rebuild class index?
Try just to delete /cache/class_index.php file to force PrestaShop rebuild the classes structure index and to make it see all new overrides.

Share this post


Link to post
Share on other sites
On 18.08.2017 at 2:47 PM, nirmuc said:

Hi, this it's simple what I need for categories, but I get this error when I try to move them: "You do not have permission to edit this."

 

do you know why? i'm using ps 1.7.1

 

thanks!

 

EDIT:

it works good if I comment the access error:  // if ($this->tabAccess['edit'] !== '1')  ...

 

Hi. Sorry for missing your question.

Well, this is a built-in permissions mechanism.
If it doesnt allow you to edit categories (moving category under another - is kind of editing too) - it means that you dont have such permissions.
Same for ptoducts...

To check it - try to move it under another category via classic way (open, change category, save)... would it allow you to save changes?

Share this post


Link to post
Share on other sites
13 hours ago, Alexander.X said:

hello.

This issue was discussed and fixed at the begining of this topic.
The key is to copy /override/classes/Category.php to the same directory on your server.

If you used latest version, and have this file in appropriate place - maybe you just didnt rebuild class index?
Try just to delete /cache/class_index.php file to force PrestaShop rebuild the classes structure index and to make it see all new overrides.

hello alexander,

i use ps 1.6 , and i solve the error with adding:

include_once (_PS_OVERRIDE_DIR_ .'classes/'.'Category.php');

in the AdminProductsController.php

Share this post


Link to post
Share on other sites
On 30.01.2018 at 10:51 AM, amine said:

hello alexander,

i use ps 1.6 , and i solve the error with adding:

include_once (_PS_OVERRIDE_DIR_ .'classes/'.'Category.php');

in the AdminProductsController.php

 

hmmm... it's a dirty hack, and since you changed core files - you've started to create the problems that will meet you once you'll decide to upgrade your store engine to the latest version. You should fix issue that causes the override mechanism disfunction instead... But if you are not going to upgrade it at all - it's okay, dirty hack could be solutions too :)

 

Anyway, Im glad that this script is useful for you :)

 

Edited by Alexander.X (see edit history)

Share this post


Link to post
Share on other sites

I use newest Prestashop 1.7.5.1 and test module -don't work.

How run this module for new version Prestashop ?

Share this post


Link to post
Share on other sites
Posted (edited)

Hello,

Doesn't work. When choosing "add to category" in the bulk list, there is an error 500, error : Call to undefined method Category::getAllCategoriesName() in override/controllers/admin/AdminProductsController.php on line 79

 

(PS 1.6.0.5)

Edited by St055 (see edit history)

Share this post


Link to post
Share on other sites

Update your store, 1.6.0.5 is very old and buggy.

Share this post


Link to post
Share on other sites
24 minutes ago, Daresh said:

Update your store, 1.6.0.5 is very old and buggy.

Sorry, not possible. So you confirm the problem is because of the PS version?

Share this post


Link to post
Share on other sites

So add the function getAllCategoriesName() from some newer version yo your Category.php file.

Share this post


Link to post
Share on other sites

Function getAllCategoriesName does not exist in Category.php and any elsewhere 😞

Share this post


Link to post
Share on other sites

Yes, you need to add it! Take it from some new version of PS.

Share this post


Link to post
Share on other sites

Oh ok! So I done it. And... It works! Thanks for helping! 🙂

  • Like 1

Share this post


Link to post
Share on other sites

Hello!

Daresh, thanks for helping with problem at 1.6.0.5.
I was surprised to know that getAllCategoriesName was added in later versions  O_0.
Anyway, now we know it :)

Todor Inchovski, And63,
What about bugs in 1.7+ versions - I havent test it (tbh, I even havent checked what was new in this version).
But could you plz post more details of what error messages have you seen when tryied to use this script?
I guess, problem could be solved with copying some obsolete methods from the older version, but I need more information...

Share this post


Link to post
Share on other sites

Just want to say thanks for your great contribution! Works great at 1.6.1.24

Share this post


Link to post
Share on other sites

Hello Alexander, you made a good script !!!
You are a super programmer, in prestop this is a big problem - moving categories and you implemented it!
I somehow ran your script at 1.7.5 (commenting out // if ($ this-> tabAccess ['edit']! == '1') ...) and it worked, but now it doesn’t work at 1.7.6! Let's get in touch and I will thank you, set it up for me please !!
Sincerely, Igor from Novosibirsk

Share this post


Link to post
Share on other sites
On 8/10/2019 at 12:24 PM, Navigator1974 said:

Hello Alexander, you made a good script !!!
You are a super programmer, in prestop this is a big problem - moving categories and you implemented it!
I somehow ran your script at 1.7.5 (commenting out // if ($ this-> tabAccess ['edit']! == '1') ...) and it worked, but now it doesn’t work at 1.7.6! Let's get in touch and I will thank you, set it up for me please !!
Sincerely, Igor from Novosibirsk

Hello Novosibirsk,
May I ask how you made it work on 1.7.5, I've tried, but failed. Your help will be greatly appereciated.
Harry

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More