Post by federicoch » Mon Apr 07, 2014 8:18 am

Hi guys ! i made a procedure function witch allows to hide empty category (without any product on it).
i'm using oc 1.5.6 it's not the best solution but it works


Code: Select all

BEGIN

DECLARE last_id INT;
DECLARE i INT ;


SET i=1;
SELECT MAX(category_id) INTO last_id  FROM category;
/*SELECT last_id;*/-- Muestra cantidad total de categorias
WHILE i < last_id DO -- Inicio de "FOR"

IF NOT EXISTS (SELECT product_id  FROM product_to_category WHERE product_to_category.category_id=i  LIMIT 1) THEN -- if 
IF NOT EXISTS (SELECT parent_id FROM category WHERE category_id=i AND parent_id='0')THEN -- si no es category principal
IF NOT EXISTS (SELECT category_id FROM category WHERE parent_id=i) THEN
UPDATE category SET status='0' WHERE category_id=i;

END IF;
END IF;
ELSE UPDATE category SET status='1' WHERE category_id=i; -- si dio todo posivo por las dudas cambia status a 1
END IF;

SET i =i+1;

END WHILE;
END

Instalation: Create a new Procedure-function in the mysql db with the code

execute it, try it, COMMENT! sorry for my english

Attachments


Newbie

Posts

Joined
Sat May 19, 2012 7:06 am

Post by Wassya » Tue Oct 14, 2014 1:06 am

Hi, would you help. When I used it for the first time it worked, now I run it and nothing happens.

Newbie

Posts

Joined
Tue Oct 14, 2014 1:04 am

Post by Wassya » Thu Oct 16, 2014 3:07 pm

Have modified , now it hides category with 0 quantity products.

Code: Select all

BEGIN

DECLARE last_id INT;
DECLARE i INT ;
DECLARE q INT;

SET i=1;
SELECT MAX(category_id) INTO last_id FROM category;

WHILE i <= last_id DO 

SET @q = (SELECT product.quantity FROM product_to_category INNER JOIN product ON product_to_category.product_id = product.product_id WHERE product_to_category.category_id=i ORDER BY product.quantity DESC LIMIT 1);

IF (SELECT @q > 0) THEN 

UPDATE category SET status='1' WHERE category_id=i;

ELSE UPDATE category SET status='0' WHERE category_id=i; 

END IF;

SET i =i+1;

END WHILE;


END

Newbie

Posts

Joined
Tue Oct 14, 2014 1:04 am
Who is online

Users browsing this forum: No registered users and 4 guests