V
V
vitaminiby2020-06-22 19:57:57
MySQL
vitaminiby, 2020-06-22 19:57:57

Add additional category to all products in opencart via sql query?

how to assign additional category category_id = 372 to all products

try sql query and get error #1242 - Subquery returns more than 1 row

INSERT INTO `oc_product_to_category` (`product_id`, `category_id`, `main_category`) VALUES ((SELECT product_id FROM oc_product) ,'372','0');

in the query, you need to take the id of all products from the oc_product table and add them to the oc_product_to_category table, while in other columns put down the category in which the product will be and 0, since the product is not added to the main category

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2021-02-19
@8Alfa

As a more common special case: Give all products a Main Category, such as "All Products". Many people want to have a category in which absolutely all products from the store are presented, so that the buyer does not miss anything.
For OpenCart 2.3.0.2
INSERT INTO oc_product_to_category( product_id, category_id)
SELECT product_id, '249'
FROM oc_product

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question