Add trigger to automatically calculate subtotal price of cart
This commit is contained in:
parent
11491a0e43
commit
633955d95f
16
shop.sql
16
shop.sql
@ -130,4 +130,18 @@ begin
|
|||||||
where id = old.cart_id;
|
where id = old.cart_id;
|
||||||
end;
|
end;
|
||||||
//
|
//
|
||||||
delimiter;
|
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 ;
|
Loading…
x
Reference in New Issue
Block a user