PHP 5 e-commerce Development- P40 pptx

5 51 0
PHP 5 e-commerce Development- P40 pptx

Đang tải... (xem toàn văn)

Thông tin tài liệu

The Shopping Basket [ 178 ] Cleaning the basket Shopping baskets need to be emptied, but this should be done only when: The customer wants to empty their basket The customer conrms an order The basket contents are old and are not tied to a customer account Expired contents We could create a function to empty a user's basket, upon their request. However, this can't be used for the instance of expired contents, as it isn't tied to a specic user; we need to purge any data in the basket table that has expired. We need to do this, because after a certain period of time, the customer won't be able to see the products in their basket anyway, as they may have a new IP address from their Internet Service Provider, or they may have initiated a new session, and so their session ID will not be the same. Essentially, these are orphaned products in the basket—and need to be removed to keep the database up to date, and free of redundant data. Displaying the basket on every page Most e-commerce websites display a small shopping basket on each page, often at the top of the page or the side of the page, reminding the customer how many products are in their basket, the cost of the contents of their basket, and providing a link for them to view their basket in detail and checkout their order. To display the basket on each page we will need: An empty basket template le, so that if the customer has no products in the basket, the page accurately reects that with a suitable message. A basket template le, which displays the number of products in the customer's basket, the cost of the order, and a link allowing the customer to proceed to the checkout process. A template tag in our main templates, where the basket can be inserted; when the basket is checked, the appropriate basket or empty basket will be inserted where this template tag is. Something in our framework to link into the basket on each page, not only when the basket controller is called directly. Without this, the customer would only see the basket if they visited the basket page. • • • • • • • This material is copyright and is licensed for the sole use by jackie tracey on 23rd February 2010 953 Quincy Drive, , Brick, , 08724 Chapter 6 [ 179 ] Functionality Within our framework, we could link the basket to each page, by calling the controller from our index.php le, but without using the directCall parameter; this would prevent the framework from trying to process the URL and running pre-dened parts of the controller. Instead, we simply call the checkBasket method, import the relevant template, and use the number of products and total cost variables from the model as template tags, and we have a small basket on the page. The following is the code within our index.php le; it simply creates a Basketcontroller object, and then calls the smallBasket method of that object. // basket require_once('controllers/basket/controller.php'); $basket = new Basketcontroller( $registry, false ); $basket->smallBasket(); Within our Basketcontroller, we need to add the smallBasket method to insert the appropriate data and templates into the view. /** * Small basket - prepare small embedded basket * @return void */ The rst thing this needs to do is to check the basket in order to get the number of products and the cost of the baskets contents. As discussed earlier, when we do check the basket, we mark a variable to indicate that, to prevent us from unnecessarily doing this twice. We check to see if we haven't already checked the basket, and if we haven't, we then call the checkBasket function, to prepare the information we need. public function smallBasket() { if( $this->basket->isChecked() == false ) { $this->basket->checkBasket(); } // set our embedded property $this->embedded = true; 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 [ 180 ] If the basket isn't empty then we insert the basket template into the view, and set the appropriate values. // check that the basket is not empty if( $this->basket->isEmpty() == false ) { // basket isn't empty so use the basket template, // and set the numBasketItems and basketCost template variables $this->registry->getObject('template')-> addTemplateBit('basket', 'basket.tpl.php'); $this->registry->getObject('template')->getPage()-> addPPTag('numBasketItems', $this->basket->getNumProducts() ); $this->registry->getObject('template')->getPage()-> addPPTag('basketCost', $this->basket->getTotal()); $this->registry->getObject('template')->getPage()-> addPPTag('shippingCost', $this->basket->getShippingCost()); } If the basket is empty, then we insert the empty basket template. else { // basket is empty - so use the empty basket template $this->registry->getObject('template')-> addTemplateBit('basket', 'basket-empty.tpl.php'); } } Summary In this chapter, we have created our shopping basket, facilitating the rst phase of allowing customers to make a purchase with our framework. We started with support for standard products, and extended it to work with products that customers can customize and products that have variations. Now we can move on to the checkout and order process, as the shopping basket we have developed in this chapter is essentially the rst stage in the order process, and with that in place, we can extend this to allowing customers to place an order and for it to be fullled. This material is copyright and is licensed for the sole use by jackie tracey on 23rd February 2010 953 Quincy Drive, , Brick, , 08724 The Checkout and Order Process Our e-commerce framework is really starting to take shape now, and as we have made steps into facilitating online purchasing, things are starting to get very interesting. The next stage for us is the checkout and order process, which generally has quite a lot of features or requirements that we must take into account. We need to look through what is required of this process, look at how often it is structured, and decide how we should structure our order process. In this chapter, you will learn: About the different processes involved in the checkout and order process How a number of other e-commerce websites, large and small, deal with their checkout and order process How we should structure our checkout and order process Some examples Let us start by reviewing some existing e-commerce websites from the perspective of their checkout and order process, to see how they go about it. We will look at the following stores: Amazon eBay Play.com • • • • • • This material is copyright and is licensed for the sole use by jackie tracey on 23rd February 2010 953 Quincy Drive, , Brick, , 08724 The Checkout and Order Process [ 182 ] Amazon Amazon is one of the most popular online stores available. Let us take a look at the stages involved in its order process: 1. Select products to purchase. 2. Detailed basket displayed on side of each page. 3. Authentication: Login Register Do nothing—already logged in 4. Select delivery address. 5. Select delivery method. 6. Select gift wrapping. 7. Enter payment details. 8. Enter voucher code. 9. Conrm details. 10. Process payment. 11. Order processed. 12. Order dispatched. 13. Happy customer. • • • This material is copyright and is licensed for the sole use by jackie tracey on 23rd February 2010 953 Quincy Drive, , Brick, , 08724 . February 2010 953 Quincy Drive, , Brick, , 08724 Chapter 6 [ 179 ] Functionality Within our framework, we could link the basket to each page, by calling the controller from our index .php le, but. within our index .php le; it simply creates a Basketcontroller object, and then calls the smallBasket method of that object. // basket require_once('controllers/basket/controller .php& apos;); $basket. licensed for the sole use by jackie tracey on 23rd February 2010 953 Quincy Drive, , Brick, , 08724 The Checkout and Order Process Our e-commerce framework is really starting to take shape now, and

Ngày đăng: 07/07/2014, 10:20

Mục lục

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

    An overview of e-commerce

    Brick 'N Mortar stores

    Rolling out your own framework

    When to use an existing package?

    A look at e-commerce sites

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

    Our framework: what is it going to do?

    Our framework: why is it going to do it?

    Designing a killer framework

Tài liệu cùng người dùng

Tài liệu liên quan