-- Замените {source_product_id}, {category_id}, {new_option_1_id}, {new_option_2_id} на соответствующие значения
-- Создание копий опций для каждого товара в выбранной категории
INSERT INTO oc_product_option (product_id, option_id, value, required)
SELECT p.product_id, po.option_id, po.value, po.required
FROM oc_product_option po
JOIN oc_product p ON po.product_id = {source_product_id}
JOIN oc_product_to_category ptc ON p.product_id = ptc.product_id AND ptc.category_id = {category_id}
WHERE ptc.product_id != {source_product_id};
-- Получение идентификаторов новых опций
SET @new_option_1_id := LAST_INSERT_ID();
SET @new_option_2_id := @new_option_1_id + 1;
-- Обновление значений опций для новых товаров
UPDATE oc_product_option
SET option_id = CASE
WHEN option_id = {new_option_1_id} THEN @new_option_1_id
WHEN option_id = {new_option_2_id} THEN @new_option_2_id
END
WHERE product_id IN (SELECT product_id FROM oc_product_to_category WHERE category_id = {category_id});