Prev | Current Page 466 | Next

Emilian Balanescu and Cristian Darie

"Beginning PHP and MySQL E-Commerce: From Novice to Professional, Second Edition"


The procedure receives three parameters: inCartId, inProductId, and inAttributes. It first determines
whether the product already exists in the shopping cart by looking for cart_id, product_id, and
attributes. If this combination exists in the shopping_cart table, it means the visitor already has the
product in its shopping cart, so you update the existing quantity by adding one unit. Otherwise, shopping_
cart_add_product creates a new record for the product in shopping_cart with a default quantity of 1.
The NOW() MySQL function is used to retrieve the current date to populate the added_on field.
3. Execute the following code, which creates the shopping_cart_update stored procedure in your
tshirtshop database:
-- Create shopping_cart_update_product stored procedure
CREATE PROCEDURE shopping_cart_update(IN inItemId INT, IN inQuantity INT)
BEGIN
IF inQuantity > 0 THEN
UPDATE shopping_cart
SET quantity = inQuantity, added_on = NOW()
WHERE item_id = inItemId;
ELSE
CALL shopping_cart_remove_product(inItemId);
END IF;
END$$
The shopping_cart_update stored procedure updates the quantity of one item. This stored procedure is
called when the visitor clicks the Update button in the shopping cart page and is called once for each item
that needs to be updated.
The procedure receives two parameters: inItemId and inQuantity. If inQuantity is zero or less,
shopping_cart_update is smart enough to remove the mentioned item from the shopping cart.


Pages:
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478
Prince lion przeszycia łódź tłumacz niemieckiego opony przemysłowe Apartamenty Novalja