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

PHP 5 e-commerce Development- P49 docx

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 (331.76 KB, 5 trang )

Checkout
We now have only one primary feature left for the checkout and order process, and
this is the payment section. Although this is the last primary feature, there are still
quite a few loose ends to tidy up. In this chapter, you will learn:
How to store delivery addresses
How to manage a default delivery address on a per-customer basis
How to allow customers to select a payment method
How to let customers conrm their order
All of the functionality we are working on in this chapter can be contained nicely
within its own controller: checkout.
Order process review
If we review the order process we discussed in Chapter 7, The Checkout and Order
Process, we have the following process:
1. View the basket
Enter voucher code
Select shipping method
Review cost based on shipping and voucher code
2. Authentication
Log in
Register
Do nothing (if already logged in)
3. Conrm delivery address
4. Select payment method











This material is copyright and is licensed for the sole use by jackie tracey on 23rd February 2010
953 Quincy Drive, , Brick, , 08724
Checkout
[ 224 ]
5. Order conrmation
6. Display payment details
7. Payment made
8. Order processed
As things currently stand, we have the rst section completed:
Viewing the basket—done in Chapter 6, The Shopping Basket
Entering voucher code—done in Chapter 9, Discounts, Vouchers, and Referrals
Selecting the shipping method—done in Chapter 8, Shipping and Tax
Reviewing cost based on shipping and voucher code—done in Chapters 8
and 9
So let's take a look at our shopping basket:
The nal three points—payment details, making payment, and order processing
are to come in the next chapter. The four points in the middle, although not majorThe four points in the middle, although not major
features, still need to be worked into our framework; otherwise, we will not be able
to guide our customers to the point where they can actually make the payment for
their order.




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

Authentication
When the customer has reviewed their basket and made any necessary changes,
we need to allow them to supply their delivery address. Before they can do that;
however, we must consider authentication.
If the customer is logged in, then we can simply send them to the "delivery address"
page, where they will be presented with their default delivery address based on their
user account details. If the customer is not logged in, we need to allow them to either
log in, or enter their details to sign up to the store.
To make this process as seamless as possible, there are a few things we
should consider:
Should the user have to click on a link or a button to view the
registration page?
Should the user have to click on a link or a button to view the login page?
Should we validate the user's e-mail address by sending them an e-mail and
asking them to conrm if it is valid?
The answer to all three of these points is no. If we do any of these things, then we
are creating an unnecessary barrier between the customer and them completing
their order. Some believe that even requiring the customer to create a user account
is a step too far. As we are going to require the customer to make their own account,
we should make this less intrusive by allowing them to enter all of their details on
one page, with only a few additions as opposed to if they were just supplying their
delivery address.
private function authenticationCheck()
{
//First we check that the user is logged in.
if( $this->registry->getObject('authenticate')->isLoggedIn()
== true )
{
// Then we check to see if they have just logged in.just logged in.logged in.
if( $this->registry->getObject('authenticate')->justProcessed()

== true )
{
// As the user has just logged in, we transfer their basket to
// their account.
// store the basket in the user account
$this->basket->transferBasketToUser( $this->registry
->getObject('authenticate')->getUserID() );
// check the basket, to ensure the user has some products
// in their basket after logging in



This material is copyright and is licensed for the sole use by jackie tracey on 23rd February 2010
953 Quincy Drive, , Brick, , 08724
Checkout
[ 226 ]
$this->basket->checkBasket();
}

$this->setDelivery();
return true;
}
else
{
//User is not logged in, so we show them the login/register page.
$this->registry->getObject('template')->
buildFromTemplates('header.tpl.php',
'checkout/loginreg.tpl.php','footer.tpl.php');
$this->registry->getObject('template')->getPage()->
addTag('pagetitle', 'Login or sign up' );

return false;
}
}
Having our customer now able to log in, we now conrm their delivery address
as follows:
This material is copyright and is licensed for the sole use by jackie tracey on 23rd February 2010
953 Quincy Drive, , Brick, , 08724
Chapter 10
[ 227 ]
Delivery address
Firstly, we check to see if the customer is submitting the delivery address form, if
he/she is, then we sanitize the address details and set the delivery address with the
following code:
private function setDelivery()
{
// Checking to see if the set_delivery_address post field has been
// set, indicates that the customer has set their delivery address.
if( isset( $_POST['set_delivery_address'] ) )
{
// save delivery address
// We then call the basket's setDeliveryAddress method, which
// saves the default delivery address. This method takes a series
// of strings as its parameters. These strings are inserted
// directly into the database, so we must sanitize them first,
// using the databases sanitizeData method.
$this->basket->setDeliveryAddress(
$this->registry->getObject('db')->
sanitizeData( $_POST['address_name'] ),
$this->registry->getObject('db')->
sanitizeData( $_POST['address_lineone'] ),

$this->registry->getObject('db')->
sanitizeData( $_POST['address_linetwo'] ),
$this->registry->getObject('db')->
sanitizeData( $_POST['address_city'] ),
$this->registry->getObject('db')->
sanitizeData( $_POST['address_postcode'] ),
$this->registry->getObject('db')->
sanitizeData( $_POST['address_country'] ));
// Once the delivery address is updated, we then redirect the
// customer to the payment method page.
$this->registry->redirectUser('checkout/select-payment-method/',
'Delivery address saved', 'Your delivery address has been
saved', false );

}
else
{
// If the customer has not just entered their delivery details,
// we display the form using the default delivery details.
$this->registry->getObject('template')->
buildFromTemplates('header.tpl.php',
'checkout/delivery.tpl.php','footer.tpl.php');
$address = $this->basket->getDeliveryAddress();
if( ! empty( $address ) )
{
$this->registry->getObject('template')->getPage()->
This material is copyright and is licensed for the sole use by jackie tracey on 23rd February 2010
953 Quincy Drive, , Brick, , 08724

×