diff --git a/shop.sql b/shop.sql index b085cde..2cbea62 100644 --- a/shop.sql +++ b/shop.sql @@ -130,4 +130,18 @@ begin where id = old.cart_id; end; // -delimiter; \ No newline at end of file +delimiter; + +delimiter // +create trigger calculate_price_subtotal +before insert on cart_item +for each row +begin + set new.price_subtotal = ( + select new.count * p.price_pc + from product p + where p.id = new.product_id + ); +END; +// +DELIMITER ; \ No newline at end of file