Home Web-development PHP 5 E-commerce Development

PHP 5 E-commerce Development

By
books-svg-icon Book
Subscription
$10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
BUY NOW $10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
Subscription
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
  1. Free Chapter
    PHP e-commerce
About this book

The popularity of online shopping has increased dramatically over the past few years. There are plenty of options available if you not are planning to build your own e-commerce solution but sometimes it's better to use your own solutions. It may be easy to find an e-commerce system but when it comes to extending it or using it you might come across a lot of difficulties.

This book will show you how to create your own PHP framework that can be extended and used with ease, particularly for e-commerce sites. Using this framework you will be able to display and manage products, customize products, create wish-lists, make recommendations to customers based on previous purchases, send email notifications when certain products are in stock, rate the products online, and much more.

This book helps you build a Model-View-Controller style framework, which is then used to put together an e-commerce application. The framework contains template management, database management, and user authentication management. With core functionality in place, e-commerce-focused features are gradually added to the framework including products, categories, customizable products with different variations and customer input, wish-lists, recommendations, the shopping basket, and a complete order process.
 
At the end of the book, you will have an e-commerce architecture that will take you from viewing or searching for products, and adding them to your basket, through the checkout process and making payment for your order, to your order being dispatched. Focus is placed on flexibility, so that the framework can be extended as the needs of a particular store change, as illustrated by one of the appendices, which goes through the process of modifying the store to sell downloadable products, as well as physical ones.

Supplementary information, such as how to market and promote an online store, as well as take regular backups and perform maintenance is also covered, ensuring you have every chance of success with you own e-commerce framework backed store.

Publication date:
January 2010
Publisher
Packt
Pages
356
ISBN
9781847199645

 

Chapter 1. PHP e-commerce

Welcome to building a PHP e-commerce framework! During the course of this book we are going to build a flexible e-commerce framework using PHP, which can be extended and modified for the purposes of any e-commerce site.

In this chapter, you will learn:

  • The business logic behind e-commerce

  • Why (and when) you should use your own system over an existing product

  • The benefits of a "framework"

  • About existing e-commerce sites and products

 

e-commerce: Who, what, where, why?


e-commerce, or electronic commerce, is the sale and purchase of goods or services through electronic means. In our case, this electronic means is the Internet. There are so many different applications of e-commerce on the Internet, including:

  • Online shops selling products, such as Amazon, or the online counterparts to Brick 'N Mortar stores

  • Online auctions, such as eBay

  • Online services/web services such as BaseCamp, or subscription-based websites

An overview of e-commerce

e-commerce is an incredibly popular way of doing business, so let's look at who is using e-commerce and what they are using it for.

eBay

According to eBay's website, there are approximately 84 million active users of eBay, with users trading more than $1,900 worth of goods each second. That means 84 million of us are using eBay to buy and sell goods, either as a business sustaining a regular turnover, or to try and make a little extra cash by selling unwanted or unneeded things knocking about the house.

eBay is a social e-commerce site, operating as an online auction house, whereby they don't actually sell anything themselves, but instead allow their community of users to not only buy but also sell through their site. This not only illustrates the popularity of e-commerce, but also that there is money to be made in providing a stage for low (and high) volume online purchases.

Amazon

With revenue of over $19 billion in 2008, Amazon is one of the most popular e-commerce sites on the Internet. Research in early 2009 indicated that it was the favorite retailer for both video and music in the UK.

Brick 'N Mortar stores

Large, established Brick 'N Mortar stores such as Wal-Mart, Tesco, and Borders use online shops to sell the products they generally keep in store. With the likes of Wal-Mart and Tesco, customers often book a delivery timeslot for their groceries to be delivered. They also offer more than what is available in store, which they can easily bolt on for the convenience of their customers. With online retail, sellers are not confined to what they can stock on the shelves, but what they can store in their distribution warehouses.

Smaller, niche-based Brick 'N Mortar stores use online selling as a way to target their products to a wider audience, without the limitation of their existing physical presence.

Service-based companies

Companies such as 37signals are setting up online applications (such as Project Management tool, BaseCamp) with monthly subscription models. Other examples of such sites include large file distribution websites (allowing you to "e-mail" large files using a third-party website) and premium features on certain websites, for example Get Satisfaction.

Why use e-commerce?

The popularity of online shopping has increased dramatically over the past few years. Not only does it provide the convenience of allowing customers to shop in the comfort of their own home, it also allows businesses to trade on a global marketplace, targeting even more potential customers. Because everything is done electronically, e-commerce stores can also help generate recurring revenue, by recommending new products to customers based on previous purchases, and by keeping them up to date with the store's catalog.

 

Rolling out your own framework


Throughout the course of this book, we are going to build a framework of our own, using PHP, as opposed to making use of an existing product. Sometimes, it is more appropriate to use existing solutions; sometimes it is better to use your own solutions. As you are reading this book, hopefully you know why you want to create your own framework. However, let's look at why we are going to create ours.

Why PHP?

PHP is a very popular language, and because it isn't a framework in its own right, we can easily structure our framework out of it, however we wish. The main choice for a programming language is generally down to your own preference.

Most modern web hosts support PHP and MySQL, and while languages like Ruby on Rails are gaining popularity, at the moment hosting for them is not as common. This book assumes that you already have a reasonable understanding of PHP, so hopefully that will also be an important factor in why you want to use PHP; perhaps you need to develop something quickly, and don't want to use a language or platform that is out of your comfort zone.

Why a framework?

Instead of looking to create an e-commerce system, designed to perform all types of e-commerce tasks, we will create a framework. This will make it easy to extend the needs of any e-commerce project with minimal effort. Because we are creating our own framework, it is going to be something we will know and understand very well, meaning that if we do need to extend it or use it, we can do so easily.

While a typical e-commerce system may show products within a browse or search interface, a framework could allow us to integrate products into other areas of a website; for instance, pulling certain categories of product into relevant pages, particularly useful for a website that needs to do more than just sell online. For example, if we were selling books, we could have pages dedicated to certain authors with information, reviews, and other media about the author, and then integrate some of their popular products into the page.

When to use an existing package?

There are already a number of e-commerce systems available, written in various different languages, and sometimes it is more appropriate to use such a product, for example:

  • When you have a tight deadline for a project, and you don't have a framework in place

  • When there are lots of developers on the project; something with more documentation available would probably be more useful, at least initially (unless the framework was developed by most of the developers)

  • When a client has indicated a preference

  • When the features match — if another system has all the features you need and want, and it works in a way you are comfortable with, then it would be more appropriate to use the existing system

Existing products

Of the e-commerce applications that are already available, the following are amongst the most popular:

  • Magento: This is a very modular and flexible e-commerce platform, which is becoming more widespread in its usage.

  • Drupal e-commerce: Drupal is a popular content management system, which is easy to extend and modify. There are two packages of modules, Ubercart and Drupal e-commerce, which add a wealth of e-commerce functionality to the popular CMS.

  • CubeCart: This is a simple-to-use e-commerce solution, available with both free and paid versions.

A look at e-commerce sites

We have already taken a brief look at who is using e-commerce; let's take a more detailed look at some popular e-commerce sites, and see how they work and what features they provide to their users.

iStockphoto

iStockphoto is a popular website for buying and selling stock photography. Photographers can register on the website and submit their photographs for approval. Approved photographs can then be purchased by customers for a number of credits, depending on the size of the photograph and the license they wish to purchase it under.

Features
  • Approval process for sellers: Photographs are approved by iStockphoto before being available for purchase.

  • Flexibility for sellers: Sellers can choose their prices, multiple image sizes, and the licenses they wish to sell the image under.

  • Credits: Because most stock photograph purchases equate to only a few dollars, iStockphoto has a credits system whereby the customers purchase at least $10 of credits, which are assigned to their accounts. These credits are then deducted when they make a purchase.

  • Social: Photographs can be rated and commented on, making the website very social and interactive.

WooThemes

WooThemes is quickly becoming a popular online shop for custom themes, but operates quite differently to most theme-selling websites. Purchases are either a theme package (the theme and accompanying color schemes), or a one-off fee along with a monthly subscription allowing the customer to purchase any themes they wish in a particular month, backed up with reassurances of a minimum number of themes each month.

WooThemes also invites established members of the web design community to create themes for the site, helping to raise the profile of the site and continue their ability to offer quality themes.

Features
  • In-depth knowledge of industry and respected designers to help increase their product offering (not strictly a feature)

  • Two types of purchases, each with two tiers, providing access to different downloads:

    • Recurring payments

    • Membership-based offers

eBay

We discussed earlier, that eBay is an online auction house, but what features does it have to support its business?

Features
  • Powerful search feature to find products

  • Purchase products directly — "Buy it now"

  • Bid for products/express interest in purchasing

  • Make payments and manage orders

Amazon

While Amazon doesn't operate as an online auction house, as eBay does, it still has a number of social aspects to it, including ratings, reviews, and recommendations. It also allows users of the site to sell their own copies of products listed within the store, through the Amazon Marketplace. This market place functionality is also integrated within their main product listing, informing customers that they can also purchase used and new copies of a product, from non-Amazon sellers, through its market place.

Features

On a basic level, Amazon.com provides the following features to its users:

  • Browse and search for products

  • Rate and review products

  • Purchase products

  • Make payments and manage orders

  • Sell products through the Marketplace

Play.com

Play.com operates in a similar way to Amazon: it not only sells products, but also allows users to sell their own items (branded as PlayTrade). One notable difference with Play.com is the categorization of products, which also allows more dynamic categories such as products under a certain amount, or seasonal items (for example, Christmas present ideas).

Features
  • Browse and search for products

  • Rate and review products

  • Purchase products

  • Make payments and manage orders

  • Sell products through PlayTrade

 

e-commerce: What does it need to do/have?


After looking at some popular e-commerce sites, our store obviously needs some key features. It needs the ability for users to search for and browse products, within different categories. Visitors to the site obviously need to be able to purchase these products, which leads to the need for a shopping basket to store products the visitor intends to purchase and a checkout process to manage delivery details, tax calculations, delivery charge calculations, payment processing, and of course order management for administrators. We will build upon these core features to build a basic feature list for our framework.

The exception with regards to those features is eBay, which forgoes the need for a shopping basket; however, it contains provisions for watching items, automatically bidding for items, and with "Buy it now" making an instant purchase.

Products

We need to have the following product-related features:

  • Finding products: We need the functionality to both browse product listings and search for products to make it easy for customers to find products within our framework.

  • Viewing products: Once customers have found a product that interests them, they obviously need to be able to view the product to find out more about it. This also means we need to take into consideration what type of information is related to products (for example name, price, weight, and so on). Community-orientated aspects link in nicely here too, such as ratings and reviews.

  • Expressing interest in a product: This can be done either by adding a product to a basket, or to an interest list, for future purchase.

Checkout process

The checkout process essentially has the following three features or requirements:

  • Group products into orders (unless it's an auction-style site)

  • Accept and process payment for orders, or accept a note of how payment is going to be made

  • Take delivery details from the customer

General

There are also some other supplementary features the framework will need to implement:

  • Allow the store to be administered

  • Allow customers to manage their orders, and change account information (username, password, default delivery address)

 

Our framework: What is it going to do?


We are going to create a framework that can do anything we need it to. Of course, the exact needs of a project vary from project to project, so we will ensure it has some fundamental features, which we can then extend to whatever we need. The following features will be the minimum that we will have our framework capable of doing:

  • Displaying and managing products

  • Displaying and managing categories of products

  • Embedding products, listings, and categories into other aspects of a website or web application (after all, it is a framework we are creating!)

  • Customizing products such as apparel

  • Searching for products

  • Filtering the product list based on the customers' preferences, such as brand, or other properties

  • Providing wish lists, that is, lists of products that users wish to purchase at some point, or would like someone to purchase for them (including the provision to facilitate gift purchases)

  • Generating recommendations based on previous purchases

  • Sending e-mail notifications when certain products are in stock

  • Publishing ratings and reviews of products

  • Providing a shopping basket to store products and quantities of the products a customer wishes to purchase

  • Calculating shipping cost

    • Based on products and/or their weights

    • Based on delivery address

    • Based on custom rules (for example free shipping to orders over a fixed amount)

  • Tax cost calculations

  • Managing discount codes

  • Managing gift certificates

  • Providing referral discounts

  • Processing payments

  • Allowing customers to manage their account

  • Allowing us and other administrators to manage the store

Along with these features, we are also going to look at the following functionalities:

  • Deploying the framework into a live store environment

  • Backing up and restoring the store

  • Enabling secure connections to the live store using SSL

To illustrate how our framework can be extended to meet the needs of any e-commerce situation, there are three appendices looking at different ways to extend the framework:

  • Web service integration, for services such as Google Product Search

  • Extending our store to support downloadable products

  • Various code snippets in a cook book format, showing how to quickly extend this (and any other framework) to support some specific enhancements

 

Our framework: Why is it going to do it?


Most online stores are there for a particular purpose, either to sell a particular product, or to act as the online division of a Brick 'N Mortar store. Obviously, the point of creating a framework is to easily adapt to any purpose; however, for the purposes of this book, we are going to need a scenario site to create.

Juniper Theatricals

Juniper Theatricals is a fictional Brick 'N Mortar novelty and theatrical supplies store based in Newcastle upon Tyne, UK. They have some customers who place orders over the telephone, or over fax, and have a loyal local base of customers too. When building our framework, we are going to use it as a web presence for this fictional store. Some specific requirements of the store include, in addition to previously discussed features:

  • Customizable products: Apparel.

  • Custom products: User-defined images and text on apparel, perhaps the ability to list these for sale as well.

  • Virtual purchases: Electronic tickets to events.

Because the store has no web presence, the framework needs to work for their entire website, integrating e-commerce functionality where appropriate. Although they are based in the UK, the website is designed to target new customers, primarily in the USA, so the site will use USD as its primary currency.

Let's look at what our framework will look like for our Juniper Theatricals store. Here's an insight to a product view powered by our framework:

And of course, the shopping basket itself:

 

Summary


In this chapter we looked at e-commerce and discussed the reasons for creating our own e-commerce framework in PHP, along with the features our framework is going to support. We also looked at some existing e-commerce setups and discussed the different types of e-commerce stores available on the Internet. Now that we know what we are going to create and why, we are ready to start building the structure and basic functionality of our framework, before adding a wealth of e-commerce functionality.

About the Author
  • Browse publications by this author
PHP 5 E-commerce Development
Unlock this book and the full library FREE for 7 days
Start now