问题
I need to mass change product categories. I updated two tables in database: ps_category_product
(changed old id_category) and ps_products
(changed old id_category_default) but in BO product table and webshop I still see old category (home).
When I edit product, select tab associations I see that product is associated with my new caterogy. Only when I save the product by click save button I see that product in properly categories.
I compared two rows in database (product with changed category by mysql query and product changed in BO) and these two look identical.
What am I doing wrong? I was trying clean cache (delete cache/cachefs and smarty/compile), disable all cache options but with no result.
回答1:
To change the category, the following queries must be executed:
Db::getInstance()->execute('UPDATE '._DB_PREFIX_.'category_product SET id_category = NEW_ID_CATEGORY WHERE id_category = OLD_ID_CATEGORY');
Db::getInstance()->execute('UPDATE '._DB_PREFIX_.'product_shop SET id_category_default = NEW_ID_CATEGORY WHERE id_category_default = OLD_ID_CATEGORY AND id_shop = ID_SHOP');
Db::getInstance()->execute('UPDATE '._DB_PREFIX_.'product SET id_category_default = NEW_ID_CATEGORY WHERE id_category_default = OLD_ID_CATEGORY');
Regards
来源:https://stackoverflow.com/questions/44087875/prestashop-change-product-category-in-database