org.paneris.melati.shopping
Class ShoppingTrolley

java.lang.Object
  extended by org.paneris.melati.shopping.ShoppingTrolley
Direct Known Subclasses:
DefaultShoppingTrolley

public abstract class ShoppingTrolley
extends java.lang.Object

A Shopping Trolley stores information in the user's Shopping Trolley.

It does this by storing itself in the session.

For this reason, the constructors are private, and you will be expected always to get the Shopping Trolley using getInstance();

Usage example:

ShoppingTrolley trolley = ShoppingTrolley.getInstance(Melati melati); context.put("trolley", trolley);


Field Summary
protected  java.lang.String address
           
 MelatiShoppingConfig config
           
protected  java.lang.String country
           
protected  java.lang.String county
           
protected  java.lang.String email
           
protected  boolean hasDetails
           
protected  java.util.Locale locale
           
 org.melati.Melati melati
           
protected  java.lang.String message
           
protected  java.lang.String name
           
protected  java.lang.String postcode
           
protected  java.lang.String tel
           
protected  java.lang.String town
           
static double VAT_PERCENT_TIMES_TEN
           
 
Constructor Summary
ShoppingTrolley()
           
 
Method Summary
 java.lang.String abandonURL()
           
 void addItem(ShoppingTrolleyItem item)
          Add an item to the trolley.
abstract  void assertLogin(org.melati.Melati melatiIn)
          Do something to force users to login.
 java.lang.String baseURL()
           
 void configureRequest(org.melati.Melati melatiIn)
          This is done for each request, so anything special that needs to be done can be put in here
abstract  void confirmPayment(org.melati.Melati melatiIn)
          Confirm payment of this trolley.
 java.lang.String confirmURL()
           
 java.lang.String detailsURL()
           
 java.lang.String displayCurrency(double value)
          Format a number in the locale currency.
 java.lang.String displayCurrency(java.lang.Double value)
          Format a number in the locale currency.
 java.lang.String getCountry()
          Get the country.
 java.lang.String getCounty()
          Get the county.
 java.lang.String getDeliveryAddress()
          Get the address.
 java.lang.String getDeliveryDisplay()
          Format the delivery value for display.
abstract  double getDeliveryValue()
          You need to provide some mechanism for calculating the delivery value for the order (item delivery values are calculated individually.
abstract  double getDiscountRate()
          If you want to apply a discount to this order, do it here.
 java.lang.String getDiscountRateDisplay()
          Display the discount (if present).
 double getDiscountValue()
          Work out the value of the discout applied to this order (returns a negative value).
 java.lang.String getDiscountValueDisplay()
          Format the discount value for display.
 java.lang.String getEmail()
          Get the email address.
static ShoppingTrolley getInstance(org.melati.Melati melati, MelatiShoppingConfig config)
          Returns the single instance, creating one if it can't be found.
 ShoppingTrolleyItem getItem(java.lang.Integer id)
          Get an item from the trolley.
 java.util.Enumeration getItems()
          Get the items from the trolley.
abstract  java.util.Locale getLocale()
          Get the Locale for this trolley.
 java.lang.String getMessage()
          Get the delivery message.
 java.lang.String getName()
          Get the name.
 java.lang.String getPostcode()
          Get the postcode.
 java.lang.String getTel()
          Get the telephone number.
 double getTotalDeliveryValue()
          The delivery charge for the order is the sum of the charges on the items and an overall charge.
 double getTotalValue()
          Calculate the total value of this order.
 java.lang.String getTotalValueDisplay()
          Format the total order value for display.
 java.lang.String getTotalValuePence()
          Format the total order value in pence, typically ecomerce sites accept the values in pence not pounds.
 java.lang.String getTown()
          Get the town.
 double getValue()
          Calculate the value of the items in the trolley.
 java.lang.String getValueDisplay()
          Format the order value for display.
 java.lang.String getVATDisplay()
          Format the vat value for display.
 double getVATValue()
          Calculate the VAT value of the order.
abstract  boolean hasDelivery()
          Provide a mechanism for working out if this order should include a delivery charge.
 boolean hasDetails()
          Have we entered any personal information.
abstract  boolean hasDiscount()
          Provide a mechanism for working out if this order should include a discount.
abstract  boolean hasVAT()
          Provide a mechanism for working out if this order should include VAT (default should be true).
protected  void initialise(org.melati.Melati melatiIn, MelatiShoppingConfig configIn)
          Private Constructor to build an empty ShoppingTrolley
 void initialise(org.melati.Melati melatiIn, MelatiShoppingConfig configIn, java.lang.Integer id)
          Public Constructor to build a trolley from some id.
 boolean isEmpty()
          Have we got anything in the trolley.
abstract  void load(java.lang.Integer id)
          Load a trolley from something persistent.
static java.lang.String name()
          Return the name of the trolley (for storing in the session).
 ShoppingTrolleyItem newItem(java.lang.Integer id, java.lang.String description, java.lang.Double price)
          Create an item and put it in the Trolley.
static ShoppingTrolley newTrolley(MelatiShoppingConfig config)
           
 java.lang.String paidURL()
           
 void remove(org.melati.Melati melatiIn)
          Remove any trolley from the session.
 void removeItem(ShoppingTrolleyItem item)
          Remove an item from the trolley.
static double roundTo2dp(double num)
           
abstract  void save()
          Save a trolley to something persistent.
 void setCountry(java.lang.String a)
          Set the country.
 void setCounty(java.lang.String a)
          Set the county.
abstract  void setDefaultDetails(org.melati.Melati melatiIn)
          Set the user's detault details into this trolley.
 void setDeliveryAddress(java.lang.String a)
          Set the address.
 void setEmail(java.lang.String a)
          Set the email address.
 void setFromForm(org.melati.Melati melati)
          Set values from form fileds.
 void setLocale(java.util.Locale locale)
          Set the Locale for this trolley.
 void setMessage(java.lang.String a)
          Set the delivery message.
 void setName(java.lang.String a)
          Set the name.
 void setPostcode(java.lang.String a)
          Set the postcode.
 void setTel(java.lang.String a)
          Set the telephone number.
 void setTown(java.lang.String a)
          Set the town.
 java.lang.String updateURL()
           
 java.lang.String viewURL()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

locale

protected java.util.Locale locale

address

protected java.lang.String address

name

protected java.lang.String name

tel

protected java.lang.String tel

town

protected java.lang.String town

county

protected java.lang.String county

country

protected java.lang.String country

postcode

protected java.lang.String postcode

message

protected java.lang.String message

email

protected java.lang.String email

hasDetails

protected boolean hasDetails

VAT_PERCENT_TIMES_TEN

public static final double VAT_PERCENT_TIMES_TEN
See Also:
Constant Field Values

config

public MelatiShoppingConfig config

melati

public org.melati.Melati melati
Constructor Detail

ShoppingTrolley

public ShoppingTrolley()
Method Detail

initialise

protected void initialise(org.melati.Melati melatiIn,
                          MelatiShoppingConfig configIn)
Private Constructor to build an empty ShoppingTrolley


initialise

public void initialise(org.melati.Melati melatiIn,
                       MelatiShoppingConfig configIn,
                       java.lang.Integer id)
                throws org.melati.util.InstantiationPropertyException
Public Constructor to build a trolley from some id.

Throws:
org.melati.util.InstantiationPropertyException

remove

public void remove(org.melati.Melati melatiIn)
Remove any trolley from the session.


getInstance

public static ShoppingTrolley getInstance(org.melati.Melati melati,
                                          MelatiShoppingConfig config)
                                   throws org.melati.util.InstantiationPropertyException
Returns the single instance, creating one if it can't be found.

Throws:
org.melati.util.InstantiationPropertyException

newTrolley

public static ShoppingTrolley newTrolley(MelatiShoppingConfig config)
                                  throws org.melati.util.InstantiationPropertyException
Throws:
org.melati.util.InstantiationPropertyException

getLocale

public abstract java.util.Locale getLocale()
Get the Locale for this trolley.


setLocale

public void setLocale(java.util.Locale locale)
Set the Locale for this trolley.


confirmPayment

public abstract void confirmPayment(org.melati.Melati melatiIn)
Confirm payment of this trolley.


load

public abstract void load(java.lang.Integer id)
                   throws org.melati.util.InstantiationPropertyException
Load a trolley from something persistent.

Throws:
org.melati.util.InstantiationPropertyException

save

public abstract void save()
Save a trolley to something persistent.


configureRequest

public void configureRequest(org.melati.Melati melatiIn)
This is done for each request, so anything special that needs to be done can be put in here


assertLogin

public abstract void assertLogin(org.melati.Melati melatiIn)
Do something to force users to login. You could perhaps throw an access poem exception in order to let the servlet generate the login page.


setDefaultDetails

public abstract void setDefaultDetails(org.melati.Melati melatiIn)
Set the user's detault details into this trolley. This is useful if users have already logged in, and we don't want them to reenter their details.


name

public static java.lang.String name()
Return the name of the trolley (for storing in the session).


getItems

public java.util.Enumeration getItems()
Get the items from the trolley.


isEmpty

public boolean isEmpty()
Have we got anything in the trolley.


hasDetails

public boolean hasDetails()
Have we entered any personal information.


getItem

public ShoppingTrolleyItem getItem(java.lang.Integer id)
Get an item from the trolley.


removeItem

public void removeItem(ShoppingTrolleyItem item)
Remove an item from the trolley.


addItem

public void addItem(ShoppingTrolleyItem item)
Add an item to the trolley.


newItem

public ShoppingTrolleyItem newItem(java.lang.Integer id,
                                   java.lang.String description,
                                   java.lang.Double price)
                            throws org.melati.util.InstantiationPropertyException
Create an item and put it in the Trolley.

Parameters:
id -
description -
price -
Returns:
a newly created item in the Trolley
Throws:
org.melati.util.InstantiationPropertyException

getValue

public double getValue()
Calculate the value of the items in the trolley.


getValueDisplay

public java.lang.String getValueDisplay()
Format the order value for display. This value does not include discount or delivery, but does invlude VAT.


getTotalValue

public double getTotalValue()
Calculate the total value of this order.


getTotalValueDisplay

public java.lang.String getTotalValueDisplay()
Format the total order value for display. This value includes discount, delivery and VAT.


getTotalValuePence

public java.lang.String getTotalValuePence()
Format the total order value in pence, typically ecomerce sites accept the values in pence not pounds.


hasDelivery

public abstract boolean hasDelivery()
Provide a mechanism for working out if this order should include a delivery charge.


getDeliveryValue

public abstract double getDeliveryValue()
You need to provide some mechanism for calculating the delivery value for the order (item delivery values are calculated individually.


getTotalDeliveryValue

public double getTotalDeliveryValue()
The delivery charge for the order is the sum of the charges on the items and an overall charge.


getDeliveryDisplay

public java.lang.String getDeliveryDisplay()
Format the delivery value for display.


hasDiscount

public abstract boolean hasDiscount()
Provide a mechanism for working out if this order should include a discount.


getDiscountRate

public abstract double getDiscountRate()
If you want to apply a discount to this order, do it here.


getDiscountValue

public double getDiscountValue()
Work out the value of the discout applied to this order (returns a negative value).


getDiscountRateDisplay

public java.lang.String getDiscountRateDisplay()
Display the discount (if present).


getDiscountValueDisplay

public java.lang.String getDiscountValueDisplay()
                                         throws java.lang.Exception
Format the discount value for display.

Throws:
java.lang.Exception

hasVAT

public abstract boolean hasVAT()
Provide a mechanism for working out if this order should include VAT (default should be true).


getVATValue

public double getVATValue()
Calculate the VAT value of the order. Typically items are priced inclusive of VAT and orders are therefore also inclusive of VAT. If this order is for someone who should not be charged VAT, we need to subtract VAT from the order value.


getVATDisplay

public java.lang.String getVATDisplay()
Format the vat value for display.


setFromForm

public void setFromForm(org.melati.Melati melati)
Set values from form fileds.

Parameters:
melati -

setDeliveryAddress

public void setDeliveryAddress(java.lang.String a)
Set the address.


getDeliveryAddress

public java.lang.String getDeliveryAddress()
Get the address.


setName

public void setName(java.lang.String a)
Set the name.


getName

public java.lang.String getName()
Get the name.


setEmail

public void setEmail(java.lang.String a)
Set the email address.


getEmail

public java.lang.String getEmail()
Get the email address.


setPostcode

public void setPostcode(java.lang.String a)
Set the postcode.


getPostcode

public java.lang.String getPostcode()
Get the postcode.


setTel

public void setTel(java.lang.String a)
Set the telephone number.


getTel

public java.lang.String getTel()
Get the telephone number.


setTown

public void setTown(java.lang.String a)
Set the town.


getTown

public java.lang.String getTown()
Get the town.


setCounty

public void setCounty(java.lang.String a)
Set the county.


getCounty

public java.lang.String getCounty()
Get the county.


setCountry

public void setCountry(java.lang.String a)
Set the country.


getCountry

public java.lang.String getCountry()
Get the country.


setMessage

public void setMessage(java.lang.String a)
Set the delivery message.


getMessage

public java.lang.String getMessage()
Get the delivery message.


displayCurrency

public java.lang.String displayCurrency(double value)
Format a number in the locale currency.


displayCurrency

public java.lang.String displayCurrency(java.lang.Double value)
Format a number in the locale currency.


baseURL

public java.lang.String baseURL()

viewURL

public java.lang.String viewURL()

detailsURL

public java.lang.String detailsURL()

confirmURL

public java.lang.String confirmURL()

abandonURL

public java.lang.String abandonURL()

updateURL

public java.lang.String updateURL()

paidURL

public java.lang.String paidURL()

roundTo2dp

public static double roundTo2dp(double num)


Copyright © 1997-2009 PanEris. All Rights Reserved.