Processing the incoming URL within our registry object
index.php
.htaccess file
Configuration file
What about e-commerce?
An e-commerce registry?
Summary
Products and Categories
What we need
Product information
Category information
Structuring content within our framework
Pages
Content
Versioning
Building products, categories, and content functionality into our framework
Database
Content
Content types
Content versions
Products
Categories
Pages within our framework
Model
View
Controller
Products
Model
View
Controller
Categories
Model
View
Controller
Some thoughts
Product and category images
Routing products and categories
Featured products
Embedding products
Summary
Product Variations and User Uploads
Giving users choice
Simple variants
How could this work?
Combinations of variants
How will this work?
High-level overview
Database structure
Template switching
Templates
A look back at simple variants
Giving users control
How to customize a product?
Uploads
Custom text
Maintaining uploads
Security considerations
Database changes
Extending our products table
Template switching
Shopping basket preparation
Stock control
Product variations
Product customizations
Basket templates
Product subtotals
Summary
Enhancing the User Experience
Juniper Theatricals
The importance of user experience
Search
Finding products
Search box
Controlling searches with the products controller
Search results
Improving searches
Filtering products
Product attributes
Filter options
Processing filter requests
Displaying filtered products
Improving product filtering
Providing wish lists
Creating the structure
Saving wishes
Wish-list controller
Add to wish list
Viewing a wish list
Controller changes
Wish-list view
Purchases
Gift purchases
Self purchases
Improving the wish list
Recommendations
Related products
Controlling the related products
Viewing the related products
E-mail recommendations
Help! It's out of stock!
Detecting stock levels
Changing our controller
Out of stock: a new template bit
Tell me when it is back in stock please!
Stock alerts database table
More controller changes
It is back!
Giving power to customers
Product ratings
Saving a rating
Viewing ratings
Product reviews
Processing reviews/comments
Displaying reviews/comments
Combining the two?
Any other experience improvements to consider?
Summary
The Shopping Basket
Shopping baskets
Our basket
Per-page basket
Considerations for our shopping basket
Creating a basket
When to build a user's basket
Basket database
Basket contents
Viewing the basket
checkBasket method
The controller
Adding products
An addProduct method
The controller
A note on etiquette
Adding customizable products
Changing our basket database
Viewing the basket
Changing the model
The controller
Adding product variants
A new database table
Model changes
The controller
Editing quantities
From visitor to a user
The transferToUser function
Performing the transfer
Cleaning the basket
Expired contents
Displaying the basket on every page
Functionality
Summary
The Checkout and Order Process
Some examples
Amazon
Limitations
Useful features
eBay
Interesting points of note
Play.com
Interesting points of note
The process
The basket
Voucher codes
Shipping method
An overview
Authentication
Why should we authenticate the user at this stage?
Login
Register
Do nothing
Delivery address
Payment method
Offline payment method
Off-site payment method
On-site payment method
Confirmation
Payment details
Payment made
Order processed
Other points of note
Summary
Shipping and Tax
Shipping
Shipping methods
Shipping costs
Product-based shipping costs
Weight-based shipping costs
To think about: location-based shipping costs
Shipping rules
Free shipping
Capped shipping
Tracking
Integrating shipping costs into the basket
Shipping methods and a default
Calculating shipping costs based on products
Calculating shipping costs based on product weights
Considering shipping rules, and adjusting prices accordingly
Tax
Separately calculating tax values
To think about: location-based tax costs
A look at our basket now
Summary
Discounts, Vouchers, and Referrals
Discount codes
Discount codes data
Discount codes database
Discount codes functionality
Reducing the number of codes available
Purchasable voucher codes
Existing functionality
Discount codes
Product variations
Required additional functionality
Referrals
Database changes
New table: referrers
Changes
Functionality
Checkout process consideration
Summary
Checkout
Order process review
Authentication
Delivery address
Payment method
Confirmation
Storing orders in the database
Orders table
Order statuses
Order items
Order item attributes
Payment methods
Summary
Taking Payment for Orders
Taking payment
Our payment system
Taking payment online
PayPal
The payment button
Processing payment to update the order
Direct with a credit/debit card
Storing card details
Not storing card details
Other payment gateways
Payment gateway tips
Taking payment offline
Summary
User Account Features
User account area
Changing details
Changing password
Changing default delivery address
Viewing orders
Listing orders
Query
Viewing an order
Order model
Cancelling an order
Order model additions
Controller code
Expansion
Summary
Administration
Dashboard
Products and categories
Products
Creating a product
Editing a product
Categories
Creating a category
Editing a category
Deleting a category
Orders and customers
Orders
Updating an order
Dispatch note
Refunds
Customers area
Listing customers
A customer's orders
Miscellaneous
Shipping
Creating a shipping method
Voucher codes
Creating a voucher code
Summary
Deploying, Security, and Maintenance
Deploying
Hosting accounts and domain names
Hosting providers
Domain name registrars
Manual deployment
Setting up the database
Uploading our store
Settings
Automated deployment
Security
Server security
Software
Securing the site with a firewall
Passwords
SSL/TLS
CAPTCHA
Maintenance
Backing up and restoring
Using cPanel
Using the command line (SSH)
Summary
Marketing, SEO, and Customer Retention
Marketing sites and stores powered by our framework (and other sites for that matter)
Online advertising
Buying advertising space
Pay-per-click advertisements
Advertisement networks provided by search engines
Newsletter advertising
A word of warning: search engine penalization
Newsletters
Marketing materials
Affiliate marketing
Social marketing
Viral marketing
Twitter
RSS with FeedBurner
Search engine optimization
On-site SEO
Headings
Links
Up-to-date content
Meta tags
Sitemap and webmaster tools
Off-site SEO
Customer retention
Newsletters
Social features
Coupons and voucher codes
Summary
Interacting with Web Services
Google products
Adding the feed to the Google merchant center
Setting an update schedule
Creating the feed
Product feed controller
Other useful link
Alternative—Google Base Data API
Others
Google Analytics
Signing up
Tracking e-commerce
Add transaction
Add item
Track transaction
Further reading
Other services
Amazon
eBay.com
More to come
Summary
Downloadable Products
Extending products
Extending the payment and administration areas
Access database
Providing access
Rescinding access
Centralized download area
What else is needed?
Summary
Cookbook
Authentication reminders
Help! I forgot my password!
Generate the reset key, update the user record, and e-mail the customer
Reset the password
Help! I forgot my username!
E-mailing customers
Integrating Campaign Monitor
Integrating reCAPTCHA
On the registration page
When processing the registration
Tweeting about happy customers
Other uses
Summary
Index
Nội dung
Planning our Framework [ 48 ] This is particularly useful when working in the model or controller with a single row of results from a query. We may wish to convert them to template tags; this function facilitates that, and allows us to prex the tags, which helps eliminate naming conicts. /** * Convert an array of data into some tags * @param array the data * @param string a prefix which is added to field name to create * the tag name * @return void */ public function dataToTags( $data, $prefix ) { foreach( $data as $key => $content ) { $this->page->addTag( $key.$prefix, $content); } } We set the title of a page directly to the page object. However, this needs to be inserted directly into the template, as this function takes the title value and inserts it between the title tags within the template itself. /** * Take the title we set in the page object, and insert them * into the view */ public function parseTitle() { $newContent = str_replace('<title>', '<title>' . $this->page->getTitle(), $this->page->getContent() ); $this->page->setContent( $newContent ); } Finally, when we have nished assigning template variables, new templates need to be inserted into a template and so on. We need to call the various replace and parse functions. This method consolidates these calls, so we simply call it from our framework. Our completed view is now ready to be sent to the user's browser. /** * Parse the page object into some output * @return void */ public function parseOutput() { This material is copyright and is licensed for the sole use by jackie tracey on 23rd February 2010 953 Quincy Drive, , Brick, , 08724 Chapter 2 [ 49 ] $this->replaceBits(); $this->replaceTags(); $this->parseTitle(); } } ?> Let's take a look at the code for page.class.php. Our page object makes it easier to encapsulate the data and templates that we have compiled during the framework's execution to create the appropriate nalized view for the customer. It stores information such as the title of the page, the template variables and their corresponding data values, the contents of various templates, and any template bits we wish to insert into the others. <?php /** * Page object for our template manager * * @author Michael Peacock * @version 1.0 */ class page { // page elements // page title private $title = ''; // template tags private $tags = array(); // tags which should be processed after the page has been parsed // reason: what if there are template tags within the database // content, we must parse the page, then parse it again for post // parse tags private $postParseTags = array(); // template bits private $bits = array(); // the page content private $content = ""; /** * Create our page object */ function __construct() { } /** This material is copyright and is licensed for the sole use by jackie tracey on 23rd February 2010 953 Quincy Drive, , Brick, , 08724 Planning our Framework [ 50 ] * Get the page title from the page * @return String */ public function getTitle() { return $this->title; } /** * Set the page title * @param String $title the page title * @return void */ public function setTitle( $title ) { $this->title = $title; } /** * Set the page content * @param String $content the page content * @return void */ public function setContent( $content ) { $this->content = $content; } /** * Add a template tag, and its replacement value/data to the page * @param String $key the key to store within the tags array * @param String $data the replacement data (may also be an * array) * @return void */ public function addTag( $key, $data ) { $this->tags[$key] = $data; } /** * Get tags associated with the page * @return void */ This material is copyright and is licensed for the sole use by jackie tracey on 23rd February 2010 953 Quincy Drive, , Brick, , 08724 Chapter 2 [ 51 ] public function getTags() { return $this->tags; } /** * Add post parse tags: as per adding tags * @param String $key the key to store within the array * @param String $data the replacement data * @return void */ public function addPPTag( $key, $data ) { $this->postParseTags[$key] = $data; } /** * Get tags to be parsed after the first batch have been parsed * @return array */ public function getPPTags() { return $this->postParseTags; } /** * Add a template bit to the page, doesnt actually add * the content just yet * @param String the tag where the template is added * @param String the template file name * @return void */ public function addTemplateBit( $tag, $bit ) { $this->bits[ $tag ] = $bit; } /** * Get the template bits to be entered into the page * @return array the array of template tags and template * file names */ public function getBits() { This material is copyright and is licensed for the sole use by jackie tracey on 23rd February 2010 953 Quincy Drive, , Brick, , 08724 Planning our Framework [ 52 ] return $this->bits; } /** * Gets a chunk of page content * @param String the tag wrapping the block * ( <! START tag > block <! END tag > ) * @return String the block of content */ public function getBlock( $tag ) { preg_match ('#<! START '. $tag . ' >(.+?) <! END '. $tag . ' >#si', $this->content, $tor); $tor = str_replace ('<! START '. $tag . ' >', "", $tor[0]); $tor = str_replace ('<! END ' . $tag . ' >', "", $tor); return $tor; } public function getContent() { return $this->content; } } ?> Extending the template management object We could extend our template management object and page object to make things easier or more powerful should we wish. Some examples include: Making it possible to password protect pages Restricting access to pages based on permissions Making it easy to add CSS and JavaScript les into the page Easily adding some onLoad JavaScript to the page's <body> tag E-mail sending Most sites require the need to send e-mails. This is even more so the case with e-commerce sites, as they will need to send e-mails to conrm purchases, conrm dispatches, and to inform customers when products they were interested in are back in stock. • • • • This material is copyright and is licensed for the sole use by jackie tracey on 23rd February 2010 953 Quincy Drive, , Brick, , 08724 . 2010 953 Quincy Drive, , Brick, , 08724 Chapter 2 [ 49 ] $this->replaceBits(); $this->replaceTags(); $this->parseTitle(); } } ?> Let's take a look at the code for page.class .php. Our. licensed for the sole use by jackie tracey on 23rd February 2010 953 Quincy Drive, , Brick, , 08724 Planning our Framework [ 50 ] * Get the page title from the page * @return String */ public. and is licensed for the sole use by jackie tracey on 23rd February 2010 953 Quincy Drive, , Brick, , 08724 Chapter 2 [ 51 ] public function getTags() { return $this->tags; } /** * Add