The first and most important is shopping_cart_create_order, which takes the products
from the shopping cart and creates an order with them. The second stored procedure is
shopping_cart_empty, which empties the visitor??™s cart after the order has been placed.
In the following exercise, we??™ll implement these stored procedures starting with shopping_
cart_empty, because it is called from shopping_cart_create_order.
Exercise: Creating the Stored Procedures
1. Use phpMyAdmin to create the stored procedures described in the following steps. Don??™t forget to set the $$
delimiter before executing the code of each step.
2. Execute the following code, which creates the shopping_cart_empty stored procedure in your tshirtshop
database. When a customer places an order, shopping_cart_create_order will call shopping_cart_
empty to delete the products from the customer??™s shopping cart.
-- Create shopping_cart_empty stored procedure
CREATE PROCEDURE shopping_cart_empty(IN inCartId CHAR(32))
BEGIN
DELETE FROM shopping_cart WHERE cart_id = inCartId;
END$$
3. Execute the following code, which creates the shopping_cart_create_order stored procedure in your
tshirtshop database. This stored procedure gets called when the customer decides to buy the products in
the shopping cart and clicks the Place Order button. The role of shopping_cart_create_order is to create
a new order based on the products in the customer??™s shopping cart.
Pages:
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553