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
Products and Categories [ 68 ] Content versions The actual content of pages and other content types is stored in the content_versions table, which stores versions of the content, and the active version for each content element is referenced directly by the content table. This table requires the following structure: Field Type Description ID Integer (Auto increment, Primary Key) A reference for the framework to refer to different versions Name Varchar The name of the content Title Varchar The page title for the content (shown in the <title> tags of the page) Heading Varchar The heading for the page, commonly displayed within <h1> tags. Content Longtext The actual HTML content for the content (the page, product, or other suitable content type) Metakeywords Varchar The keywords metadata Metadescription Varchar The description metadata eld Metarobots Varchar The robots metadata eld; this could be from a predened list, so we may wish to have a metarobots table, or make this an ENUM eld Author Integer A reference to the user who created this version of the content Timestamp Timestamp The time and date that the version was created The SQL for this table is as follows: CREATE TABLE `content_versions` ( `ID` int(11) NOT NULL auto_increment, `name` varchar(255) NOT NULL, `heading` varchar(255) NOT NULL, `content` longtext NOT NULL, `metakeywords` varchar(255) NOT NULL, `metadescription` varchar(255) NOT NULL, `metarobots` varchar(255) NOT NULL, `author` int(11) NOT NULL, `created` timestamp NOT NULL default CURRENT_TIMESTAMP, PRIMARY KEY (`ID`), KEY `author` (`author`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; This material is copyright and is licensed for the sole use by jackie tracey on 23rd February 2010 953 Quincy Drive, , Brick, , 08724 Chapter 3 [ 69 ] This table should have the following references to foreign keys: ALTER TABLE `content_versions` ADD CONSTRAINT `content_versions_ibfk_1` FOREIGN KEY (`author`) REFERENCES `users` (`ID`) ON UPDATE CASCADE; Products As discussed earlier, products will be represented by extending the revisions table and combining it with a products table. Field Type Description ID Integer (Primary Key, Auto increment) A reference to the entry in the table. Content_version Integer Ties the product version data to a content version, associating relevant elds from that and from its associated record in the content table too. SKU Varchar The stock keeping unit reference for the product. Image Varchar A reference to an image path where the primary image for this product is stored. Weight Int The weight of the product. Featured Boolean If the product is featured. We may wish to use this to display products on the home page, or perhaps in a "featured products" box. The following SQL represents this table: CREATE TABLE `content_types_products` ( `ID` int(11) NOT NULL auto_increment, `content_version` int(11) NOT NULL, `price` float NOT NULL, `weight` int(11) NOT NULL, `SKU` varchar(255) NOT NULL, `stock` int(11) NOT NULL, `image` varchar(255) NOT NULL, `featured` tinyint(1) NOT NULL, PRIMARY KEY (`ID`), KEY `content_version` (`content_version`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; This material is copyright and is licensed for the sole use by jackie tracey on 23rd February 2010 953 Quincy Drive, , Brick, , 08724 Products and Categories [ 70 ] The table needs the following references to foreign keys: ALTER TABLE `content_types_products` ADD CONSTRAINT `content_types_products_ibfk_1` FOREIGN KEY (`content_version`) REFERENCES `content_versions` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE; Categories Categories themselves don't need to extend the data held within the content versions table, so we can use that table as is for categories. Pages within our framework To enable pages within our framework, we need to add a model, controller, and some templates (a view) to it. The model will connect to the database and represent the data contained within a page. The controller will work with the model to lookup the current page, and display it within the view. There is a lot of additional functionality, which we could look at implementing here, such as menu and submenu generation, breadcrumb generation, and so on. However, that is more of a content management system focus, and beyond the scope of this book. Model Our model requires the ability to connect to the database, search for a page given the path of a page, and represent the data of that page. It also needs to inform the framework if the path provided does not represent a page, so that we can generate a "Page not found" error. The constructor The simplest way for us to do this, is to have the constructor perform the page lookup, by passing a page path to it as a parameter. The constructor should then set the values of various properties within the model object to the values from within the database. If a page was not found, it needs to set a particular property to reect this. This material is copyright and is licensed for the sole use by jackie tracey on 23rd February 2010 953 Quincy Drive, , Brick, , 08724 Chapter 3 [ 71 ] Other methods Other methods we need within our model are: isValid(): This method is used by the controller to lookup if the page is valid or not. isActive(): This method is used by the controller to lookup if the page is active or not. isSecure(): This method is used by the controller to determine if the page is secure, and if the visitor is permitted to see the page. getProperties(): This method returns the properties of the page, so they can be integrated with the view. This gives us the following code for our model: <?php // models/pages/model.php class Pagemodel { private $registry; private $valid = false; private $active = true; private $secure = false; private $pageheading; private $title; private $pagecontent; private $metakeywords; private $metadescription; private $metarobots; public function __construct( PHPEcommerceFrameworkRegistry $registry, $urlPath ) { $this->registry = $registry; $urlPath = $this->registry->getObject('db')->sanitizeData ( $urlPath ); $sql = "SELECT c.ID, c.active, c.secure, v.title, v.name, v.heading, v.content, v.metakeywords, v.metadescription, v.metarobots FROM content c, content_types t, content_versions v WHERE c.type=t.ID AND t.reference='page' AND c.path='{$urlPath}' AND v.ID=c.current_revision LIMIT 1"; $this->registry->getObject('db')->executeQuery( $sql ); if( $this->registry->getObject('db')->numRows() != 0 ) { • • • • This material is copyright and is licensed for the sole use by jackie tracey on 23rd February 2010 953 Quincy Drive, , Brick, , 08724 Products and Categories [ 72 ] $this->valid = true; $pageData = $this->registry->getObject('db')->getRows(); $this->active = $pageData['active']; $this->secure = $pageData['secure']; $this->pageheading = $pageData['heading']; $this->title = $pageData['title']; $this->pagecontent = $pageData['content']; $this->metakeywords = $pageData['metakeywords']; $this->metadescription = $pageData['metadescription']; $this->metarobots = $pageData['metarobots']; } } public function isValid() { return $this->valid; } public function isActive() { return $this->active; } public function isSecure() { return $this->secure; } public function getProperties() { $tor = array(); foreach( $this as $field => $value ) { if( !is_object( $value ) ) { $tor[ $field ] = $value; } } return $tor; } } ?> This material is copyright and is licensed for the sole use by jackie tracey on 23rd February 2010 953 Quincy Drive, , Brick, , 08724 . varchar( 255 ) NOT NULL, `heading` varchar( 255 ) NOT NULL, `content` longtext NOT NULL, `metakeywords` varchar( 255 ) NOT NULL, `metadescription` varchar( 255 ) NOT NULL, `metarobots` varchar( 255 ) NOT. `price` float NOT NULL, `weight` int(11) NOT NULL, `SKU` varchar( 255 ) NOT NULL, `stock` int(11) NOT NULL, `image` varchar( 255 ) NOT NULL, `featured` tinyint(1) NOT NULL, PRIMARY KEY (`ID`), . be integrated with the view. This gives us the following code for our model: < ?php // models/pages/model .php class Pagemodel { private $registry; private $valid = false; private $active