Post by zastil » Fri Jan 15, 2016 8:49 pm

Please find below some useful mySQL queries for large updates to any data you need to change in bulk.

Use an image in category if no image exists from a product inside that category

Code: Select all

UPDATE oc_category U
INNER JOIN (
SELECT c.category_id, MIN(p2c.product_id) product_id, p.image FROM oc_category c
INNER JOIN oc_category_description cd ON c.category_id = cd.category_id
INNER JOIN oc_product_to_category p2c ON c.category_id = p2c.category_id
INNER JOIN oc_product p ON p2c.product_id = p.product_id
GROUP BY c.category_id
) A ON U.category_id = A.category_id
SET U.image = A.image
WHERE U.image = '' OR U.image IS NULL;
Show top level categories with 0 products

Code: Select all

SELECT cd.name, c.`status` FROM oc_category c
INNER JOIN oc_category_description cd ON c.category_id = cd.category_id
LEFT OUTER JOIN oc_product_to_category p2c ON c.category_id = p2c.category_id
WHERE p2c.product_id IS NULL and c.parent_id > 0
Disable the above categories

Code: Select all

UPDATE oc_category c
INNER JOIN oc_category_description cd ON c.category_id = cd.category_id
LEFT OUTER JOIN oc_product_to_category p2c ON c.category_id = p2c.category_id
SET c.status = 0
WHERE p2c.product_id IS NULL and c.parent_id > 0;
More coming soon
Last edited by zastil on Wed Jan 20, 2016 12:26 am, edited 3 times in total.

Newbie

Posts

Joined
Thu Jun 25, 2015 6:56 pm

Post by IP_CAM » Sat Jan 16, 2016 1:22 am

Good Idea! Do you know, what such routine would DB-Query disable/remove 'required upload' Options/Displays on Product Pages, unfortunately auto-generated by the Auto ProductsGenerator Tool !?
Ernie

My Github OC Site: https://github.com/IP-CAM
5'600 + FREE OC Extensions, on the World's largest private Github OC Repository Archive Site.


User avatar
Legendary Member

Posts

Joined
Tue Mar 04, 2014 1:37 am
Location - Switzerland

Post by zastil » Tue Jan 19, 2016 9:27 pm

Never used that tool before so can't query it my end.

Newbie

Posts

Joined
Thu Jun 25, 2015 6:56 pm
Who is online

Users browsing this forum: No registered users and 2 guests