PHP
  Home arrow PHP arrow Page 12 - Building an E-Commerce Site Part 3: Catalogs and Shopping Carts
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
PHP

Building an E-Commerce Site Part 3: Catalogs and Shopping Carts
By: Ying Zhang
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 48
    2000-06-08


    Table of Contents:
  • Building an E-Commerce Site Part 3: Catalogs and Shopping Carts
  • Assumptions and Requirements
  • Overview of The Process
  • MyMarket Shopping Experience
  • The Product Catalog
  • The Shopping Cart
  • Payment Processing
  • Step 1: Database Changes
  • Step 2: Extracting the New Scripts
  • Step 3: General Script Changes from Tutorial 2
  • Step 4: New Shopping Scripts
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Building an E-Commerce Site Part 3: Catalogs and Shopping Carts - Conclusion
    ( Page 12 of 12 )

    So there you have it, we've built a functional e-commerce site (well, except for the payment processing and order fulfillment parts). Hopefully you have learned a thing or two about how an e-commerce site works. We've built a toy system that is suitable for teaching / learning. To turn it into something you can sell things with is your job :)

    Here are some things to consider:

    Site Security

    When you are accepting payment or expecting the customer to enter in sensitive information, you site should be secure. Note that having SSL does not make your site "secure". Read up on SSL and what it does for you. A good resource is the modSSL homepage: http://www.modssl.org/

     

    Shipping Calculation

    If you are shipping physical goods, you need to include of shipping cost calculations in your totals. There are lots of pre-built PHP scripts that will help you calculate this, for example:

     

    Tax Calculation

    Tax sucks, but you have to deal with it. Some extra considerations for tax is that your customer can potentially be located anywhere in the world, so find out what tax rules apply and implement that accordingly.

     

    Database Considerations
    In this series, we have been using the MySQL database. We used it because MySQL is fast, easy to setup, and it is offered by most web hosting companies. For the purposes of this tutorial it was great, but it is not (at this point in time) suitable for real e-commerce use. The reason is that MySQL currently lacks a lot of features:

    Transactions
    MySQL currently does not support transactions. Transactions are used to make ensure that a series of statements either all get processed or don't get processed at all -- basically all or nothing. Why is this important? Let's consider a simple banking example. You transfer $500 from one bank account into another:
    1. - $500 from account A
    2. + $500 to account B
    Step 1 processes successfully, but something bad happens between step 1 and 2. Where is your money now -- you just lost $500!! This is clearly not acceptable, we need to be able to confidently say that steps 1 and 2 must all process successfully, or none of it can process at all.

    Enter the concept of transactions. With transactions, we would be able to do this:
    1. BEGIN TRANSACTION
    2. - $500 from account A
    3. + $500 to account B
    4. END TRANSACTION
    Now steps 1 to 4 are treated as one atomic operation. If anything fails between steps 1 to 4, the entire operation is aborted and we revert back to the way things were before we started. The worst that can happen here is that the money doesn't get transferred, but at least you will not lose $500.

    So where does this come in with MyMarket? There are many places where we do multiple operations that should be treated as one atomic operation, for example when we add a new product. The steps are:
    1. INSERT the new product into the database and get the new product_id
    2. INSERT entries in the products_categories table for each category the product belongs to
    Let's say that step 1 processed successfully, but step 2 does not. We will now have a product with no categories attached to it, and you won't know how to fix things because you don't know what state your database is in.

    Anyhow, the point is MySQL currently does not support transactions and you definitely need it for an e-commerce site.

    Other Missing Features
    There are also a number of other features missing from MySQL, but you can rework your scripts around this:
    1. Sub-selects
    2. UNIONs
    3. and more...
    Once you become comfortable with the way the scripts work, a good exercise would be to move to a more powerful database. Some good candidates are:

    Postgres (http://www.postgresql.org)
    This is an Open-Source database that has a lot of features, including Transactions, Sub-selects, etc. There is good PHP support for PostgreSQL, and it is very simple to port dblib.php to use Postgres -- basically search and replace the mysql_ functions with pg_.

    SQL Server (http://www.microsoft.com/sql)
    If you use PHP in Windows, SQL Server is a natural choice for a database. It's obviously not free, but since you're running in a Windows environment money probably isn't an issue right :). All kidding aside, there is good PHP support for SQL Server. To port dblib.php to use SQL Server, basically search and replace the mysql_ functions with mssql_.

    Oracle (http://www.oracle.com)
    I don't have experience with PHP+Oracle, but there is PHP support for Oracle. Looking at the Oracle functions, it would seem that porting dblib.php is not as straight forward as with the above databases.

    Other E-Commerce Solutions

    Now that you know the basics of how to build your own e-commerce site, you should take a look to see how some of the other ones are built. There are lots of Open-Source shopping carts and that sort of thing, for example:

    So that concludes this 3 part series. Hope you enjoyed reading it! Happy programming!



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

       

    PHP ARTICLES

    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek