categories – What is the best approach to rebuild product category tree completely?

Question

I have a pretty large hierarchical list of product categories (almost 300) which I need to rebuild from scratch. Once the category tree is completed, I need to re-assign all existing products (more than 10 thousands) to the new categories. Since it is definitely not a single-day job, and there are various changes happening to products every day, I prefer doing it on production, instead of building the tree locally and then somehow merging those database changes into production.

The only reasonable approach I can think if is:

  1. Build the new product category tree on production, with a temporary pattern in name/slug (e.g. tmp-my-new-category), while somehow keeping all these tmp- product categories hidden on the front end.
  2. Once the tree is built, I will re-assign all existing products to the new categories (while keeping them in original ones as well), up until this point the customer shouldn’t notice any changes.
  3. When this is done, I delete all old categories completely.
  4. Immediately after step 3 I would run a PHP script that would bulk remove all tmp- substrings from product category slugs. For this, wp_update_term() should work.

With this approach I believe I would end up with little to none “blackout” time (when no categories are visible on the front end), which in combination with caching shouldn’t be a problem at all.

My question is, would this be a correct approach or is there a better way?

(I know this might be considered to be an off-topic question here, but I believe I might get a good, straightforward solution).
Thank you.

0
Kristian Filo 2 months 2021-03-29T05:05:42-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse