Home arrow PHP arrow Page 10 - Building an E-Commerce Site Part 3: Catalogs and Shopping Carts

Step 3: General Script Changes from Tutorial 2 - 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!

TABLE OF CONTENTS:
  1. Building an E-Commerce Site Part 3: Catalogs and Shopping Carts
  2. Assumptions and Requirements
  3. Overview of The Process
  4. MyMarket Shopping Experience
  5. The Product Catalog
  6. The Shopping Cart
  7. Payment Processing
  8. Step 1: Database Changes
  9. Step 2: Extracting the New Scripts
  10. Step 3: General Script Changes from Tutorial 2
  11. Step 4: New Shopping Scripts
  12. Conclusion
By: Ying Zhang
Rating: starstarstarstarstar / 50
June 08, 2000

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

We’ve made a few changes since tutorial 2. A new library was added, a bunch of shopping related scripts, and more.

application.php

Now loads up the shopping cart library (lib/cart.php) and initializes the shopping cart if it hasn't already been initialized.

index.php

The index page now lists the on-special items on the right of the screen. You mark an item as being on special from the administrative product manager screens (which have also been modified to accomodate this new feature).

admin/products.php

The products administration screen has been modified to handle the on-special flag. This is the first time we are dealing with checkboxes, they are wierd to deal with when processing HTML forms because they behave a bit differently from the other form input types. They are defined when checked, and undefined otherwise. This forces your scripts to check for the existence of form variable instead of checking for it's value.

admin/orders.php

This is a new administrative function to show the orders that have taken place on the system. It is a simple listings of the orders with the ability to see the order details.

admin/users.php

Fixed a bug from part 2, every user you created got the password $password due to quoting problems. Thanks to the people who pointed it out :)

lib/cart.php

This file contains the declaration of the Cart class. If you are new to objects in PHP, take a moment to look at how it is written. The session variable $SESSION["cart"] is an instance of this Cart class.

lib/mymarket.php

Added some new functions:

  • err2()
    Like the original err() function, except it prints the market >> instead of <<.
  • get_category_tree()
    Returns the category navigation tree as a string.
  • print_category_tree()
    Calls get_category_tree() and prints the result.
  • get_cart_items()
    Returns a handler ($qid) of a database query with the id, name, and unit price of all the items in the shopping cart.
  • chop_ccnum()
    Returns parts of a credit card number so that it is safe to display without giving out the customer's credit card number.
  • save_orderinfo()
    Used in the order confirmation screen, this function saves the customer's order information (which includes contact information and credit card information) into the session temporarily.
  • load_orderinfo()
    The counter part to save_orderinfo(), this will retrieve the customer's order information from the session.
  • clear_orderinfo()
    Clears out the customer order information saved in the session, this is called once the orderinfo was successfully retrieved by load_orderinfo(). Together, these three functions are responsible for passing sensitive order information between the purchase and payment processing scripts.
  • Like the original err() function, except it prints the market instead of .Returns the category navigation tree as a string.Calls get_category_tree() and prints the result.Returns a handler () of a database query with the id, name, and unit price of all the items in the shopping cart.Returns parts of a credit card number so that it is safe to display without giving out the customer's credit card number.Used in the order confirmation screen, this function saves the customer's order information (which includes contact information and credit card information) into the session temporarily.The counter part to save_orderinfo(), this will retrieve the customer's order information from the session.Clears out the customer order information saved in the session, this is called once the orderinfo was successfully retrieved by load_orderinfo(). Together, these three functions are responsible for passing sensitive order information between the purchase and payment processing scripts.

templates/header.php

The standard header template has been modified to show the shopping cart summary. So throughout the site, the user will always know their shopping cart summary.



 
 
>>> More PHP Articles          >>> More By Ying Zhang
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: