Tải bản đầy đủ (.pdf) (5 trang)

PHP 5 e-commerce Development- P35 pptx

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (341.99 KB, 5 trang )

Chapter 5
[ 153 ]
Processing reviews/comments
With a database in place for our product reviews (or page comments), we need
to provide a form for our customers to enter their review, and then process this
submission and save it in the database.
Submission form
The submission form can be quite simple; we will only be collecting the customer's
name, e-mail address, and their review:
<h2>Review this product</h2>
<form action="contentcomment/{ID}" method="post">
<label for="comment_name">Your name</label>
<input type="text" id="comment_name" name="comment_name" />
<label for="comment_email">Your email address</label>
<input type="text" id="comment_email" name="comment_email" />
<label for="comment">Your review</label>
<textarea name="comment" id="comment"></textarea>
<input type="submit" id="savecomment" name="savecomment"
value="Add review" />
</form>
Adding the review
When it comes to saving the review, it is a simple case of sanitizing our data, and
inserting it into the database.
I've not added checks to ensure the page or product exists, and the error checking for
name and e-mail addresses is basic. Ideally, we would want to return the customer to
the contact form, with the invalid elds highlighted.
private function saveComment( $contentID )
{
//We build our insert array of data for the review record.
$insert = array();
$insert['content'] = $contentID;


$insert['authorName'] = strip_tags($this->registry->
getObject('db')->sanitizeData( $_POST['comment_name'] ) );
$insert['authorEmail'] = $this->registry->getObject('db')->
sanitizeData( $_POST['comment_email'] );
$insert['comment'] = strip_tags( $this->registry->getObject('db')->
sanitizeData( $_POST['comment'] ) );
$insert['IPAddress'] = $_SERVER['REMOTE_ADDR'];
$valid = true;
if( $_POST['comment_name'] == '' ||
$_POST['comment_email'] == '' || $_POST['comment'] == '' )
{
$valid = false;
}
This material is copyright and is licensed for the sole use by jackie tracey on 23rd February 2010
953 Quincy Drive, , Brick, , 08724
Enhancing the User Experience
[ 154 ]
If enough information was provided, we insert the review into the database.
if( $valid == true )
{
$this->registry->getObject('db')->
insertRecords( 'content_comments', $insert );
$this->registry->getObject('template')->getPage()->
addTag('message_heading', 'Review added');
$this->registry->getObject('template')->getPage()->
addTag('message_heading', 'Your review has been added');
$this->registry->getObject('template')->
buildFromTemplates('header.tpl.php',
'message.tpl.php',
'footer.tpl.php');

}
Otherwise, we display an error to the customer.
else
{
$this->registry->getObject('template')->getPage()->
addTag('message_heading', 'Error');
$this->registry->getObject('template')->getPage()->
addTag('message_heading', 'Either your name, email address or
review was empty, please try again');
$this->registry->getObject('template')->
buildFromTemplates('header.tpl.php',
'message.tpl.php',
'footer.tpl.php');
}
}
Displaying reviews/comments
What do we need to do to display reviews and comments?
1. Check to see if there are any comments.
2. Display either the comments or a "no comments" template.
3. Check to see if new comments are allowed.
4. Display either the comments form or a "no comments allowed" template.
Displaying and allowing comments is a very generic feature, which we could either
add into our product's controller or in a controller that all of our controllers inherit
from, ensuring all content types have support for it. I'll leave the choice down to you;
however, it would be useful if you chose to use inheritance in order to override it
within the products, so the templates replace the word comments with reviews,
and perhaps have a larger comments box.
This material is copyright and is licensed for the sole use by jackie tracey on 23rd February 2010
953 Quincy Drive, , Brick, , 08724
Chapter 5

[ 155 ]
Combining the two?
e-commerce sites such as Amazon combine these two features: allowing customers to
select a rating when they leave a review and have this rating display alongside their
review. What would be involved in combining the two features?
1. Associate ratings with a review or account for rating reviews when working
out the average rating. We could either extend the ratings table to include a
potential reference to a review, which the review can pull in, or we can store
the ratings along with the reviews and have the product's average rating
calculated by combining both standard ratings, and ratings that were left
with a review.
2. Save a rating at the same time as processing a review.
3. If a review has a rating associated with it, then it should be displayed.
Try it yourself
Once you have decided which of the two methods you
think is best for your particular framework, why not try
combining the two features yourself, should this be a useful
feature for your framework?
Any other experience improvements to
consider?
A fantastic user experience for our customers by no means ends here; there are many
other ways in which we could improve our customers' experience. Let's discuss a
few of them:
Suggest a product: We could allow customers to suggest new products for
our store.
Suggest a related product: We could allow customers to suggest a product
that is related to another product.
Report inaccurate information: We could allow customers to report
inaccurate product information.
Report an inappropriate comment: We could allow customers to bring to

our attention inappropriate comments left on product pages.




This material is copyright and is licensed for the sole use by jackie tracey on 23rd February 2010
953 Quincy Drive, , Brick, , 08724
Enhancing the User Experience
[ 156 ]
Pre-orders: If we looked into registering customers' interest when a product
was out of stock, we could extend and improve this to indicate that a product
is not in stock because it is currently only available for pre-order.
"Feedback about this page": A simple link taking customers to a contact
form to leave feedback about a specic page could be useful, as it could allow
them to inform us that a page is too thin on details, the information is out of
date, or that a link or image is broken and needs to be xed.
Summary
In this chapter we have discussed the advantages of improving the user experience
for our customers, and we have worked to improve their experience by:
Introducing product search and ltering options
Recommending relevant products to our customers
Giving our customers wish lists
Informing our customers when products they are interested in are back
in stock
Allowing customers to rate and review products
We have also discussed how we could extend and enhance these user experience
improvements, which we have implemented, including:
How to improve our search feature
Maintaining multiple wish lists
Maintaining public and private wish lists

Combining the ratings and reviews feature
Now that the user experience is improved, and we have some ideas on how to
further improve it, we can move onto the shopping basket, bringing us one step
closer to being able to trade online using our e-commerce framework.











This material is copyright and is licensed for the sole use by jackie tracey on 23rd February 2010
953 Quincy Drive, , Brick, , 08724
The Shopping Basket
The rst major step in effectively selling products online is the shopping basket, as
this directly leads into the checkout process. In this chapter, you will learn:
How to structure and create a shopping basket
How to manage the contents of the shopping basket
How to deal with a visitor signing up, and transferring their basket to their
user account
The shopping basket should be a relatively easy process, as its function is to store a
collection of products, which customers are intending to purchase, and relate them to
the relevant customer.
Shopping baskets
Shopping baskets are a very important aspect in e-commerce websites, and in most
websites, they are the rst stage in enabling an online purchase. However, there are a

number of other methods that can facilitate e-commerce, including:
One-click payments: An example of these would be a PayPal payment button
on a product view, or Amazon's one-click ordering. One-click payments, such
as PayPal's payment button, take all of their data from the payment processor,
and are generally used on websites with a small selection of products. The
customer clicks on the button on the product page, their payment is processed,
and the payment processor noties the administrator of the product, the
customer, delivery details, and the amount paid—the product and cost data
is dened within the payment button. One-click ordering makes things easier
for the customer, reducing the need to go through an entire payment process;
however, it also has disadvantages—customers can easily order things by
mistake, customers need to be sure their default delivery details are correct
in advance, it isn't easy to add voucher codes without adding more clicks,
and discounts for multiple purchases or bundled shipping can't be taken
into account.




This material is copyright and is licensed for the sole use by jackie tracey on 23rd February 2010
953 Quincy Drive, , Brick, , 08724

×