Answer the question
In order to leave comments, you need to log in
How to assign the main category to all products using mysql query?
How to assign the main category to all products using mysql query? The product is assigned categories (several) in which it is shown. All these categories have different nesting. It is necessary to assign to all products the main one from the youngest category. Opencart 2.3 (Russian assembly)
There is such a solution, but it does not work.
UPDATE c_product_to_category p2c0
JOIN (
SELECT p0.product_id,
(SELECT p2c.category_id FROM oc_product p
JOIN oc_product_to_category p2c ON p.product_id = p2c.product_id
JOIN oc_category_path cp ON p2c.category_id = cp.category_id
WHERE p.product_id = p0.product_id
ORDER BY cp.level DESC
LIMIT 1) as cat
FROM oc_product p0) t0
ON t0.cat = p2c.category_id AND p2c0.product_id = t0.product_id
SET main_category = 1
Answer the question
In order to leave comments, you need to log in
Found such a query, but it only assigns a category under a certain id
INSERT INTO oc_product_to_category( product_id, category_id, main_category )
SELECT product_id, '372', '0'
FROM oc_product
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question