Shopping cart appl by hijuney9

VIEWS: 17 PAGES: 29

									        Shopping cart appl.
 Objectives:
  – What makes up a shopping cart appl
  – How to handle the cart
     Datatable

     datastructure
        Our Shopping cart
 For our purposes, we will keep the
  shopping cart very simplistic in its
  handling
 We will only be concerned with the
  add/delete from shopping cart
 Preparing of an ‘invoice’ (amount
  owing, taxes, etc.)
 I am not concerned about a
  customer table.
       Shopping cart model
 Add items to cart
 View cart
 Delete items from cart
 Return to shopping and possibly add more
  items
 Selecting the same item twice, increments
  the quantity (assume a quantity of 1 for
  each selection!)
 Deleting an item, decrements the quantity
  if more than one or deletes entire item
              Simplified database
 At   the very least
  – Product table
        Id

        Description

        Price

        Quantity   on hand
        Etc.

 Couldhave a categories table as well
 and display products based on
 category
           Shopping cart
 Load  database tables into memory
  using dataadapters and datasets
 Actual ‘shopping cart’ can be in a
  table in a dataset, or can be done as
  a data structure
              Using datatables
 Create   datatable in memory
  – It is never updated to the database!
  – Should contain
     productID
     Desc
     Price
     Quantity  ordered
     Bind it to gridview for the cart
     Sequentially process it for the invoice
      amount
         Using datastructures
 Fast and efficient
 Stored in memory

 Datastructure as an object can be
  put in the session as a variable
    Numerous datastructures
 ArrayList
  – Link list in memory
 Queue

 Stack

 Sortedlist (in book – chapter 3)
 Hashtable (my example)
               Hashtable
 Maintained   as a data structure
 Organized based on the hash code of
  the key
 Easier to find a specific record for
  updating, deleting, etc
 All datastructures have classes with
  built-in functionality
               Shopping cart
 Involves   2 classes
  – Product class that describes a shopping
    cart element
  – Shopping cart
     Datastructure   for storing the product class
     objects
  – Shopping cart class
     Must be serializable!!
     Functions to get values, add items, delete
      items, calculate shopping total
                   Shopping cart products
   using System;
   using System.Collections;


             [Serializable]
             public class product
             {
                               public   int _prodno;
                               public   string _desc;
                               public   float _price;
                               public   int _qty;

                               public int prodno
                               {
                                                    get {return _prodno;}
                                                    set {_prodno = value;}
                               }
                               public string desc
                               {
                                                    get {return _desc;}
                                                    set {_desc = value;}
                               }
                               public float price
                               {
                                                    get {return _price;}
                                                    set {_price = value;}
                               }
                               public int qty
                               {
                                                    get {return _qty;}
                                                    set {_qty = value;}
                               }


                               public product()
                               {

                               }
                               public product(int prno, string desc, float price, int qty)
                               {
                                                 _prodno = prno;
                                                 _desc = desc;
                                                 _price = price;
                                                 _qty = qty;
                                 Data structure
   [Serializable]
             public class Shoppingcart
             {
             Hashtable _Orders = new Hashtable();
             public ICollection CartOrders
                            {
                                           get {return _Orders.Values;}
                            }
             public void AddOrder (product order)
                            {
                                           product new_order = (product) _Orders[order._prodno];
                                           if (new_order != null)
                                           {
               // order already exists - increase quantity
                                                         new_order.qty += order.qty;


                                       }
                                       else
             // add new order
                                                     _Orders.Add(order._prodno, order);
                         }
public void RemoveOrder (int prodno)
{
     if(_Orders[prodno] != null)
         {
                product order = (product)_Orders[prodno];
            // check if more than one item ordered - reduce quantity
                  if(order.qty > 1)
                                  order.qty -= 1;
                 else
               // remove whole item
                                   _Orders.Remove(prodno);
          }
                }
                public float TotalCost
                {
                                get
                                {
                                              float total = 0;
                                              foreach (DictionaryEntry entry in _Orders)
                                              {
                                                             product order = (product) entry.Value;
                                                             total += (order.qty * order.price);
                                              }
                                              return total;
                                }

              }
     }
             Sessions
 Session can point to a structure
 Only want one session per
  transaction (user)
 Where and when to create session
  object
 Use of Global.aspx file to manage
  session object
                Sessions
 Global.aspx   file
  – Cause session object to be created
    when user first comes to site
  – Rest of program does not have to worry
    about it, just retrieve it as necessary to
    get/update data
                Global.aspx
   Start session logic…

void Session_Start(object sender,
 EventArgs e)
  {
       Session["MyShoppingCart"] = new
    Shoppingcart();


    }
            Using the session
 Logic   to retrieve/update session….
Shoppingcart cart =
 (Shoppingcart)Session["MyShoppingCart"]
 ;
    if (cart != null)
    {
          Grdcart.DataSource = cart.CartOrders;
         Grdcart.DataBind();
     }
       Processing sequence
 Login   to shop
 Or

 Shop and then login to checkout
 Would probably depend on the
  nature of the business
 Not our decision….
           Shopping cart
 We are doing a very simple one
 Additional info:
  – Picture of product
  – Product details
  – Specifications
  – Shopping cart could have tabs on each
    product for additional info
  – Gridview VS one item per page…
  – Thumbnails -> expand
              Checkout
 When  order is actually processed
 Issues
  – Are items in stock?
  – Do we handle backorders if not?
  – Payment processing
             Backorders
 Some  companies handle backorders
 Some companies simple make you
  re-order at a later date
  – Much simpler processing
           Issues on backorders
 Order technically not complete until fully
  shipped
 Don’t pay in full until everything received
 Business rules set by the company not
  us!!
 Can involve a lot of logic
    –   Tracking backorders
    –   Partial payments
    –   Multiple shipments/invoices
    –   Cancelling backorders
                Checkout
 Payment     processing
 – Credit card handling
    Handle it yourself
    Bureau services
                Checkout
 Handling   it yourself
  – Need an E-Commerce ID (Merchant
    number) from a third party
  – Third party can verify credit card
    numbers
  – Link to the bank to track money
    movement
  – http://www.verisign.com/
  – Can be costly
             Checkout
 Bureau  services -> Paypal
 https://www.paypal.com/

 Good for small companies with small
  transactions (dollar wise)
 Fees for services
        Issues on checkout
 Branch   to Paypal
  – Use a new window so your site does not
    go away!
  – Communications back from Paypal that
    transaction is complete
  – Checkout not complete until you return
    to shopping cart site and confirm….
             Final Steps
 Update  products tables to reflect
  quantities ordered
 Internal transactions to
  shipping/invoicing applications to
  begin that process
             Other options
 Cross-linking   the product catalog
  – Show similar products person might be
    interested in
 Membership    tracking/personalization
  – Member discounts
  – Mail out specials related to past
    purchases
    Using stored procedures
 Code  is hidden behind an extra level
  of security
 Can be executed from any
  programming language using SQL
  commands
 All updates, additions, etc are done
  thru stored procedures in book

								
To top