dw.order
Class BasketMgr
Object
dw.order.BasketMgr
Provides static helper methods for managing baskets.
Properties
baskets  :  List  (Read Only)
Retrieve all open baskets for the logged in customer.

Restricted to agent scenario use cases: The returned list contains all agent baskets created with createAgentBasket() and the current storefront basket which can also be retrieved with getCurrentBasket(). This method will result in an exception if called by a user without permission Create_Order_On_Behalf_Of or if no customer is logged in the session.

Please notice that baskets are invalidated after a certain amount of time and may not be returned anymore.

currentBasket  :  Basket  (Read Only)
This method returns the current valid basket of the session customer or null if no current valid basket exists.

The methods getCurrentBasket() and getCurrentOrNewBasket() work based on the selected basket persistence, which can be configured in the Business Manager site preferences / baskets section. A basket is valid for the configured basket lifetime.

The current basket, if one exists, is usually updated by the method. In particular the last-modified date is updated. The lifetime of a basket can be extended in 2 ways:

  • The basket is modified in some way, e.g. a product is added resulting in the basket total being newly calculated. This results in the basket lifetime being reset.
  • The basket has not been modified for 60 minutes, then using this method to access the basket will also reset the basket lifetime.

Personal data held inside the basket such as addresses, email addresses and payment settings is associated with the customer to whom the basket belongs. If the basket being updated belongs to a different customer this data is removed. This happens when a registered customer logs in after having previously created a basket as an anonymous customer. After the customer logs out, the previous basket is stored (where applicable) and the method returns null. Personal data is also cleared when the session times out for an anonymous customer.

The following personal data is cleared.

  • product line items that were added from a wish list
  • shipping method
  • coupon line items
  • gift certificate line items
  • billing and shipping addresses
  • payment instruments
  • buyer email
If the session currency no longer matches the basket currency, the basket currency should be updated with Basket.updateCurrency().

Typical usage:

 var basket : Basket = BasketMgr.getCurrentBasket();
 if (basket) {
     // do something with basket
 }
 

Constraints:

  • The method only accesses the basket for the session customer, an exception is thrown when the session customer is null.
  • Method getCurrentOrNewBasket() only creates a basket when method getCurrentBasket() returns null.

currentOrNewBasket  :  Basket  (Read Only)
This method returns the current valid basket of the session customer or creates a new one if no current valid basket exists. See getCurrentBasket() for more details.
storedBasket  :  Basket  (Read Only)
This method returns the stored basket of the session customer or null if none is found. A stored basket is returned in the following situation: - During one visit, a customer-X logs in and receives a basket-A - In a later visit, a second basket-B is created for an anonymous customer who then logs in as customer-X. In this case basket-B is reassigned to him and basket-A is accessible as the stored basket. Now it is possible to merge the information from the stored basket to the active basket.

A stored basket will exist only if the corresponding setting is selected in the Business Manager site preferences' baskets section. A basket is valid for the configured basket lifetime.

Typical usage:

 var storedBasket : Basket = BasketMgr.getStoredBasket();
 var currentBasket : Basket = BasketMgr.getCurrentOrNewBasket();
 if (storedBasket) {
     // transfer all the data needed from the stored to the active basket
 }
 

Constructor Summary
This class does not have a constructor, so you cannot create it directly.
Method Summary
static createAgentBasket() : Basket
Creates a new agent basket for the current session customer.
static createBasketFromOrder(order : Order) : Basket
Creates a Basket from an existing Order for the purposes of changing an Order.
static deleteBasket(basket : Basket) : void
Remove a customer basket.
static getBasket(uuid : String) : Basket
This method returns a valid basket of the session customer or null if none is found.
static getBaskets() : List
Retrieve all open baskets for the logged in customer.
static getCurrentBasket() : Basket
This method returns the current valid basket of the session customer or null if no current valid basket exists.
static getCurrentOrNewBasket() : Basket
This method returns the current valid basket of the session customer or creates a new one if no current valid basket exists.
static getStoredBasket() : Basket
This method returns the stored basket of the session customer or null if none is found.
Methods inherited from class Object
Method Detail
createAgentBasket
static createAgentBasket() : Basket
Creates a new agent basket for the current session customer.

Only 4 open baskets are allowed per customer. If this is exceeded a QuotaExceededException will be thrown.

This method will result in an exception if called by a user without permission Create_Order_On_Behalf_Of or if no customer is logged in the session.

Returns:
the newly created basket for the customer which is logged in

createBasketFromOrder
static createBasketFromOrder(order : Order) : Basket
Creates a Basket from an existing Order for the purposes of changing an Order. When an Order is later created from the Basket, the original Order is changed to status Order.ORDER_STATUS_REPLACED. Restricted to agent scenario use cases: In case a storefront customer is using it the created storefront basket cannot be retrieved via Baskets containing an "orderNumberBeingEdited" are explicitly excluded from the list of baskets that can be retrieved. Responsible for this behaviour (this kind of basket cannot be used as general purpose shopping baskets) - see Basket.getOrderNoBeingEdited() / Basket.getOrderBeingEdited().

In case a Business Manager user is logged in into the session the basket will be marked as an agent basket. See Basket.isAgentBasket().

The method only succeeds for an Order

  • without gift certificates,
  • status is not cancelled,
  • was not previously replaced and
  • was not previously exported.
Failures are indicated by throwing an APIException of type CreateBasketFromOrderException which provides one of these errorCodes:

Usage:

 var order : Order; // known
 try
 {
   var basket : Basket = BasketMgr.createBasketFromOrder(order);
 }
 catch (e)
 {
   if (e instanceof APIException && e.type === 'CreateBasketFromOrderException')
   {
     // handle e.errorCode
   }
 }
 
Parameters:
order - Order to create a Basket for
Returns:
a new Basket
Throws:
CreateBasketFromOrderException - indicates the Order is in an invalid state.

deleteBasket
static deleteBasket(basket : Basket) : void
Remove a customer basket.

This method will result in an exception if called by a user without permission Create_Order_On_Behalf_Of or if no customer is logged in the session.

Parameters:
basket - the basket to be removed

getBasket
static getBasket(uuid : String) : Basket
This method returns a valid basket of the session customer or null if none is found.

If the basket does not belong to the session customer, the method returns null.

If the registered customer is not logged in, the method returns null.

Restricted to agent scenario use cases: This method will result in an exception if called by a user without permission Create_Order_On_Behalf_Of or if no customer is logged in the session.

The basket, if accessible, is usually updated in the same way as getCurrentBasket().

If the session currency no longer matches the basket currency, the basket currency should be updated with Basket.updateCurrency().

Parameters:
uuid - the id of the requested basket.
Returns:
the basket or null

getBaskets
static getBaskets() : List
Retrieve all open baskets for the logged in customer.

Restricted to agent scenario use cases: The returned list contains all agent baskets created with createAgentBasket() and the current storefront basket which can also be retrieved with getCurrentBasket(). This method will result in an exception if called by a user without permission Create_Order_On_Behalf_Of or if no customer is logged in the session.

Please notice that baskets are invalidated after a certain amount of time and may not be returned anymore.

Returns:
all open baskets

getCurrentBasket
static getCurrentBasket() : Basket
This method returns the current valid basket of the session customer or null if no current valid basket exists.

The methods getCurrentBasket() and getCurrentOrNewBasket() work based on the selected basket persistence, which can be configured in the Business Manager site preferences / baskets section. A basket is valid for the configured basket lifetime.

The current basket, if one exists, is usually updated by the method. In particular the last-modified date is updated. The lifetime of a basket can be extended in 2 ways:

  • The basket is modified in some way, e.g. a product is added resulting in the basket total being newly calculated. This results in the basket lifetime being reset.
  • The basket has not been modified for 60 minutes, then using this method to access the basket will also reset the basket lifetime.

Personal data held inside the basket such as addresses, email addresses and payment settings is associated with the customer to whom the basket belongs. If the basket being updated belongs to a different customer this data is removed. This happens when a registered customer logs in after having previously created a basket as an anonymous customer. After the customer logs out, the previous basket is stored (where applicable) and the method returns null. Personal data is also cleared when the session times out for an anonymous customer.

The following personal data is cleared.

  • product line items that were added from a wish list
  • shipping method
  • coupon line items
  • gift certificate line items
  • billing and shipping addresses
  • payment instruments
  • buyer email
If the session currency no longer matches the basket currency, the basket currency should be updated with Basket.updateCurrency().

Typical usage:

 var basket : Basket = BasketMgr.getCurrentBasket();
 if (basket) {
     // do something with basket
 }
 

Constraints:

  • The method only accesses the basket for the session customer, an exception is thrown when the session customer is null.
  • Method getCurrentOrNewBasket() only creates a basket when method getCurrentBasket() returns null.

Returns:
the current basket or null if no valid current basket exists.

getCurrentOrNewBasket
static getCurrentOrNewBasket() : Basket
This method returns the current valid basket of the session customer or creates a new one if no current valid basket exists. See getCurrentBasket() for more details.
Returns:
the basket, existing or newly created

getStoredBasket
static getStoredBasket() : Basket
This method returns the stored basket of the session customer or null if none is found. A stored basket is returned in the following situation: - During one visit, a customer-X logs in and receives a basket-A - In a later visit, a second basket-B is created for an anonymous customer who then logs in as customer-X. In this case basket-B is reassigned to him and basket-A is accessible as the stored basket. Now it is possible to merge the information from the stored basket to the active basket.

A stored basket will exist only if the corresponding setting is selected in the Business Manager site preferences' baskets section. A basket is valid for the configured basket lifetime.

Typical usage:

 var storedBasket : Basket = BasketMgr.getStoredBasket();
 var currentBasket : Basket = BasketMgr.getCurrentOrNewBasket();
 if (storedBasket) {
     // transfer all the data needed from the stored to the active basket
 }
 

Returns:
the stored basket or null if no valid stored basket exists.