Prev | Current Page 461 | Next

Emilian Balanescu and Cristian Darie

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

Because you work with temporary
shopping carts, even after implementing the customer account system, the visitor isn??™t required
to supply additional information (log in) earlier than necessary.
We use cookies to keep track of shopping carts. When the visitor clicks the Add to Cart
button, the server first verifies whether a shopping cart cookie already exists on the visitor??™s
computer. If it does, the specified product is added to the existing cart. Otherwise, the server
generates a unique cart ID, saves it to the client??™s cookie, and then adds the product to the
newly generated shopping cart.
Storing Shopping Cart Information
You will store all the information from the shopping carts in a single table named
shopping_cart. Follow the next exercise to create the shopping_cart table.
Exercise: Creating the shopping_cart Table
1. Load phpMyAdmin, select your tshirtshop database, and open a new SQL query page.
2. Execute the following code, which creates the shopping_cart table in your tshirtshop database:
-- Create shopping_cart table
CREATE TABLE `shopping_cart` (
`item_id` INT NOT NULL AUTO_INCREMENT,
`cart_id` CHAR(32) NOT NULL,
`product_id` INT NOT NULL,
`attributes` VARCHAR(1000) NOT NULL,
`quantity` INT NOT NULL,
`buy_now` BOOL NOT NULL DEFAULT true,
`added_on` DATETIME NOT NULL,
PRIMARY KEY (`item_id`),
KEY `idx_shopping_cart_cart_id` (`cart_id`)
);
How It Works: The shopping_cart Table
Let??™s look at each field in shopping_cart:
??? item_id is the primary key of the table.


Pages:
449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473