How to change a default category for all your products in prestashop at once

  (2)

A default category, which a product is assigned to, can be used by external modules, browsers, filters and synchronising systems. If a default category of a product is set incorrectly, you can encounter unexpected problems connected with updating or reaching the product.

Assigning the main category to a product as a default one is the most often issue. If you want to edit default categories of all products in PrestaShop at one, you have to perform the following request on the database used by your store.

NOTICE: The request has been tested on PrestaShop 1.6.1.6.

The request will change the default category of every product to the same one – the one which the product is assigned to the deepest.

UPDATE `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` DESC

LIMIT 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` DESC

LIMIT 1

);

Komentarze (2)
z 2

It works in 1.7.6 thank you so much!

Hi, if I want to change or update the category for some products? I have the list of IDs but those are more than 30k products, maybe could you help me?

Brak wpisów.

PShowBlog Komentarze wpisów