-- P5-824
BEGIN;

-- =============================================================================
-- Associate products with color categories instead of keywords
-- =============================================================================
INSERT  INTO product_category (product_id, category_id)
SELECT  product_id,
        vc.id
  FROM  product_keyword pk
  JOIN  keywords k ON pk.keyword_id = k.id
  JOIN  v_categorytree vc
    ON  vc.path LIKE 'root/colors/%'
   AND  name = REPLACE(REPLACE(value, '&', 'and'), 'multicolor', 'multi color')
 WHERE  keyword_id IN (SELECT keyword_id FROM keyword_type WHERE type_id = 1);

END;
