HomePHP Page 11 - Building an E-Commerce Site Part 3: Catalogs and Shopping Carts
Step 4: New Shopping Scripts - PHP
This is the third and final article in a three-part series dealing with using PHP 4 and MySQL to make a comprehensive e-commerce storefront solution. This article covers the shopping cart, payment processing, and database engine considerations, among many other topics. Full source code included!
We've gone over the general script changes, let's go through the product catalog, shopping cart, and purchaseing scripts (collectively called the shopping scripts). These are in the brand new shopping directory.
shopping/index.php
The main shopping index page is our product catalog page. I will display information for the selected level category (remember our discussion way before about what to show when going throught he product catalog -- it is all here in this one file!). If no category is specified, it will start from the top level category.
shopping/product_details.php
This script simply loads up the details for the specified product and displays it on the screen. When a user is viewing the product details page, they can add the product to their shopping cart.
shopping/cart_add.php
This is a very simple script that adds the selected product to the shopping cart. This script is so simple that it does not even display anything, it just adds to the shopping cart and sends the customer back to where they came from.
shopping/cart_view.php
Viewing the shopping cart is a bit more work than adding to the cart. We have to show the customer the contents of their shopping cart. From here, the customer can choose to empty the shopping cart, to update the quantities of the items in the cart, or to make the purchase.
shopping/purchase_now.php
When the user decides to make the purchase, they will go to this script. At this point, we need to have the user log in so that we know who they are (up till this point, we didn't care). This screen prompts the user for their billing information, and to specify and special instructions or comments for the purchase. After the user submits their information, they are asked to confirm the order.
shopping/complete_order.php
The user has filled out their purchase information, and confirmed the order. It is the responsibility of this script to talk to the payment authorization party and try to process they payment. As described earlier, this is the tricky part that requires your attention. I only provide a template of what should happen.