To set the deepest category assigned to the product as the default you need to do:
- Open your database (for example by phpMyAdmin)
- I suggest you create backup of your database for safety (export data and structure)
- Open SQL tab and perform these queries (change ‘ps_’ to your prefix):
123456789101112131415161718192021222324252627282930313233UPDATE `ps_product_shop` SET `id_category_default` = (SELECT `ps_category`.`id_category`FROM `ps_category`JOIN `ps_category_product` ON (`ps_category_product`.`id_category` = `ps_category`.`id_category`)WHERE `ps_category_product`.`id_product` = `ps_product_shop`.`id_product`ORDER BY `ps_category`.`level_depth` DESC, `ps_category`.`id_parent` DESCLIMIT 1);UPDATE `ps_product` SET `id_category_default` = (SELECT `ps_category`.`id_category`FROM `ps_category`JOIN `ps_category_product` ON (`ps_category_product`.`id_category` = `ps_category`.`id_category`)WHERE `ps_category_product`.`id_product` = `ps_product`.`id_product`ORDER BY `ps_category`.`level_depth` DESC, `ps_category`.`id_parent` DESCLIMIT 1); - Done! 🙂
hello Mateusz
is just what I am looking for, as I can do to assign products with different categories to a single
of products category a, b, c, d, e
to category f
thanks for sharing code