Introduction
This chapter provides a simple shopping cart application that highlights the topics covered in the previous chapters, namely database interaction, session management, and form processing.
This shopping cart contains features that I would consider to be a bare minimum. You should add additional features as you see fit, making sure to be conscious of security issues surrounding the user's credit cards and personal information.
Features of the Shopping Cart
This shopping cart was designed to be easy to use, easy to administer, and easy to set up. It has several features that I have found have frustrated many users of some of the existing shopping carts that are available.
Simple Shopping Interface
This shopping cart provides a simple interface, shown in Figure 5-1, for users. They can browse through different categories of items with a single mouse click. All categories can be accessed from a dropdown menu at the top of the page.
Figure 5-1. The Shopping Interface
When users select a category, all of the items in that category appear on the page. If they know what they want, they can simply click on the "Add" button to add an item to their cart. Each click of the "Add" button adds one of the items; multiple clicks mean multiple items are added.
If users wish to find out more information on a specific item, they can click on the item name. This presents users with a more detailed view of the item, as well as a picture of the item if one is provided for them to look at.
Once again, they can click the "Add" button to add one or more items to their cart; multiple clicks mean multiple items.
Users are also presented with a link to return to the category that they were just browsing, or they can choose a new category from the dropdown list at the top of the page.
Another feature that makes the shopping cart simple is the cart interface. Users are able to see their cart and the items it contains on each page that they are on while shopping. A running total of the cost of their purchases is also displayed.
Users have the option to remove items from their cart by clicking the "Remove" button next to an item. Each click removes one unit of the item, until there are no more items.
Users also have the option to modify "bulk" quantities of items in their cart by clicking on the bulk-modification link in the cart. This presents users with text-entry fields next to each one of the items that they can use to specify the exact quantity of an item in their cart. This saves users from clicking "Add" 50 times if they want 50 units of a particular item.
Finally, there is a "Check Out" link that appears whenever there are items in the user's cart. Clicking "Check Out" brings the users to a standard checkout form where they enter Name, Address, Credit Card Information, etc.
Simple Administration and Management Interfaces
The shopping cart also comes with simple administration and management interfaces. One interface is used to manage the categories and inventory of the store (see Figure 5-2), while the other manages orders (see Figure 5-3).
Figure 5-2. The Category and Inventory Management Interface
Figure 5-3. The Order Management Interface
To manage the categories and inventory of the store, you use the dbmanage.php script. This script contains the following:
Add a Category— Allows you to add a category.
Add an Item— Allows you to add an item within a category.
Display Inventory— Allows you to display all the items in the store.
Edit Items in a Specific Category— Allows you to edit or delete items within one specific category.
Edit All Categories— Allows you to edit or delete existing categories. If you delete a category, then all inventory items associated with that category are also deleted.
To manage the order received from the shopping cart, you use the administration script. The script contains the following:
View All Orders— View all orders regardless of their state.
View Open Orders— View orders that are in the (default) open status.
View Shipped Orders— View orders that have been shipped.
View Backorder Orders— View orders that have been placed on backorder.
View Hold Orders— View orders that have been placed on hold.
You are able to change the state of any of the orders from any of the order status screens. Changing states causes an email to be sent to the customer notifying him or her of the state change. You can also optionally add a tracking number to the email so that a customer can check the ship status of the package with your shipping company.
Setting It Up
Setting up this shopping cart is fairly straightforward, but keep in mind the initial setup is not secure, and you must also customize the checkout form so that it correctly interfaces with your credit card authorization service. This shopping cart has been designed with the Authorize.net (www.authorize.net) credit card authorization service in mind, but may work with other credit card authorization services.
Before using this script, you should thoroughly test it!
The general layout of the installation is shown in Table 5-1:
Table 5-1. Directory Structure for the Shopping Cart FOLDER
CONTAINS
Top Level
cart.php
checkout.php
finishorder.php
admin directory
images directory
include directory
Admin Directory[a]
admin.php
dbmanage.php
Images Directory
add.gif
remove.gif
any images for products
Include Directory
cart_inc.php
[a] This directory must be password protected!
Once you have the scripts installed and your database set up, the next thing you need to do is go into the dgmanage.php page and add a category. Once you have created a category, you can create a few items. If you add a picture to the item, place the image file in the directory that you defined for IMAGE_URL.
Once you have a minimum of one category and one item, you can test out the script.
Tuesday, July 14, 2009
Advanced PHP for Web Professionals By Christopher Cosentino Chapter 5
Posted by Mr Procces at 8:38 AM
Labels: PHP, Web Applications, Web Development, Web Programming
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment