Good day
There is an oc_product table with columns
product_id
quantity ,
price .
There is a map_product dependency table: it indicates how much in which product of other goods, i.e. columns
flower - id of the composite item in the oc_product table,
bunch - product id in the oc_product table that is included in this composite,
count - the amount of bunching in the flower.
Tables, in view of the device, are in different databases
I tried to quickly trigger a trigger that will change the price of a composite product when the price of a member of a composite product changes.
For example, this is a composite bouquet of 3 red roses, 5 white, 7 blue.
We changed the price for a blue rose, you need to recalculate the price of a composite bouquet.
Here is the code of the misery that I invented:
DELIMITER $$ CREATE TRIGGER price_change after update ON `cms_flower`.oc_product BEGIN UPDATE `oc_product` SET `price` = (SELECT SUM(`summa`) FROM (SELECT `bunch` * `count` * (SELECT `price` FROM `oc_produc` WHERE `product_id` = (SELECT `bunch` FROM `flower_deliver`.map_product WHERE `flower` = NEW.product_id)) AS `summa` FROM `flower_deliver`.map_product WHERE `flower` = NEW.product_id)) WHERE `product_id` = (SELECT `bunch` FROM `flower_deliver`.map_product WHERE `flower` = NEW.product_id) END$$ DELIMITER ; Issues:
oc_productthe rightoc_product
I do not know how to implement such a trigger due to my inexperience, please help, thanks in advance.