Model for cart functionality. Creates a CartModel class with payment, shipping, and product helper methods.
module:models/CartModel
The cart class
Classes
Methods
(inner) CartModel/addAddressToAddressBook(addressToAdd)T
Adds the given address to the address book of the cart.
Parameters:
Name | Type | Description |
---|---|---|
addressToAdd |
module:models/TransientAddressModel~TransientAddressModel |
The address to add. |
(inner) CartModel/addBonusProduct(bonusDiscountLineItem, product, selectedOptions) → {dw.order.ProductLineItem}T
Adds a bonus product to the cart associated with the specified BonusDiscountLineItem. The function creates and returns a ProductLineItem by assigning the specified Product and Quantity to the cart. The function adds the new ProductLineItem to the default shipment. The product parameter must be one of the products associated with the BonusDiscountLineItem or the process fails. The process does not validate if the number of bonus products exceeds the maximum allowed by the bonus discount. This is the job of application logic. The function always creates a new product line item, regardless of the value of the site preference 'Add Product Behavior'.
Parameters:
Name | Type | Description |
---|---|---|
bonusDiscountLineItem |
dw.order.BonusDiscountLineItem |
Line item representing an applied BonusChoiceDiscount in the basket. The product must be in the bonus product list of this discount. |
product |
dw.catalog.Product |
The product that is to be added to the basket. |
selectedOptions |
dw.util.ArrayList |
Product option array of optionName/optionValue pairs. |
Returns:
The newly created product line item.
(inner) CartModel/addCoupon(couponCode) → {dw.system.Status}T
Validates the supplied coupon code and if the coupon code is valid, applies the coupon code to the basket. While applying the coupon code the function adds a new CouponLineItem to the basket, based on the supplied coupon code. The coupon code gets set at the CouponLineItem.
A coupon code can be invalid for the following reasons:
- The coupon code was already added to the basket.
- A coupon code of the same coupon is already in basket. Adding a single coupon code of this coupon is sufficient to enable a promotion. Adding another coupon code of the same coupon does not make sense, since the promotion is already enabled by the previously added code.
- The number of redemptions of this coupon code is 1 and the code was already redeemed.
- The number of redemptions of this coupon code is > 1 and the maximum numbers of redemptions of this coupon code was already reached. The calculation of the redemptions is based on the number of redemptions of this coupon code in past plus the number of redemptions of other coupon codes of the same coupon in the past.
- The maximum number of times this coupon can be redeemed per customer was already reached.
- The maximum number of times this coupon can be redeemed by a customer within a given time period was already reached. The calculation of the redemptions is based on the the number of redemptions of this coupon code in past plus the number of redemptions of other coupon codes of the same coupon in the past.
- The coupon code is unknown to the system.
- The coupon is not enabled.
- There exists no active promotion to which the coupon is assigned.
Status: The status object representing a detailed result of the operation. The status property (Status.status) is set to 0 if the coupon was successfully applied or 1 otherwise.
The code property (Status.code) is set to one of the following values:
- "OK" = The coupon was applied to the basket.
- CouponStatusCodes.COUPON_CODE_ALREADY_IN_BASKET = Indicates that coupon code was already added to the basket.
- CouponStatusCodes.COUPON_ALREADY_IN_BASKET = Indicates that another code of the same MultiCode/System coupon was already added to basket.
- CouponStatusCodes.COUPON_CODE_ALREADY_REDEEMED = Indicates that code of MultiCode/System coupon was already redeemed.
- CouponStatusCodes.COUPON_CODE_UNKNOWN = Indicates that coupon not found for given coupon code or that the code itself was not found.
- CouponStatusCodes.COUPON_DISABLED = Indicates that coupon is not enabled.
- CouponStatusCodes.REDEMPTION_LIMIT_EXCEEDED = Indicates that number of redemptions per code exceeded.
- CouponStatusCodes.CUSTOMER_REDEMPTION_LIMIT_EXCEEDED = Indicates that number of redemptions per code and customer exceeded.
- CouponStatusCodes.TIMEFRAME_REDEMPTION_LIMIT_EXCEEDED = Indicates that number of redemptions per code, customer and time exceeded.
- CouponStatusCodes.NO_ACTIVE_PROMOTION = Indicates that coupon is not assigned to an active promotion.
Parameters:
Name | Type | Description |
---|---|---|
couponCode |
String |
The code of the coupon to add. |
Returns:
The "Status" object containing details of the add to cart action.
- Type
- dw.system.Status
(inner) CartModel/addProductItem(pid, quantity, productOptionModel)T
Adds a product to the cart and recalculates the cart. By default, when a bundle is added to cart, all its child products are added too, but if those products are variants then the code must replace the master products with the selected variants that are passed in the HTTP params as childPids along with any options.
Parameters:
Name | Type | Description |
---|---|---|
pid |
String |
ID of the product that is to be added to the basket. |
quantity |
Number |
The quantity of the product. |
productOptionModel |
dw.catalog.ProductOptionModel |
The option model of the product that is to be added to the basket. |
(inner) CartModel/addProductListItem(productListItem, quantity)T
Adds a product list item to the cart and recalculates the cart.
Parameters:
Name | Type | Description |
---|---|---|
productListItem |
dw.customer.ProductListItem |
The product list item whose associated product is added to the basket. |
quantity |
Number |
The quantity of the product. |
(inner) CartModel/calculate() → {dw.system.Status}T
Triggers the cart calculation by executing the hook 'dw.ocapi.shop.basket.calculate'.
Returns:
Returns OK if cart when the cart is recalculated.
- Type
- dw.system.Status
(inner) CartModel/calculatePaymentTransactionTotal() → {boolean}
Calculates the total amount of an order paid for by gift certificate payment instruments. Any remaining open amount is applied to the non-gift certificate payment instrument, such as a credit card. Note: this script assumes that only one non-gift certificate payment instrument is used for the payment.
Returns:
false in the case of an error or if the amount of the transaction is not covered, true otherwise.
- Type
- boolean
(inner) CartModel/checkInStoreProducts()T
Checks the in-store quantity of all product line items against the store inventory in case the product line item's quantity was updated. If the store inventory does not have as many of the item in stock as is being purchased, the product line item is converted from in-store pickup to home delivery.
(inner) CartModel/consolidateInStoreShipments() → {boolean}T
Scans the basket and consolidates items that are going to the same store. It also creates shipments with shipment type and method for the rest of checkout.
Returns:
true if there is a home delivery found in the basket, false otherwise.
- Type
- boolean
(inner) CartModel/createGiftCertificatePaymentInstrument(giftCertificate) → {dw.order.PaymentInstrument}T
Creates a gift certificate payment instrument from the given gift certificate ID for the basket. The method attempts to redeem the current balance of the gift certificate. If the current balance exceeds the order total, this amount is redeemed and the balance is lowered.
Parameters:
Name | Type | Description |
---|---|---|
giftCertificate |
dw.order.GiftCertificate |
The gift certificate. |
Returns:
The created PaymentInstrument.
(inner) CartModel/createOrder() → {dw.order.Order}T
Creates an Order based on the cart. If the order is created successfully, it has status CREATED. Once the order is created, the cart is removed from the session and marked for removal.
If the order is not created successfully the function returns null, if any of the following conditions are encountered:
- any of the totals (net, gross, tax) of the basket is N/A
- any of the product items is not available
- any campaign-based coupon in the basket is invalid (see dw.order.CouponLineItem.isValid())
- the basket represents an order being edited, but the order has been already been replaced by another order
- the basket represents an order being edited, but the customer associated with the original order is not the same as the current customer
The function decrements inventory for all products contained in the order. This means the 'reserve inventory for order' functionality must not be subsequently called. The function redeems all coupons contained in the order.
If the cart contains product or gift certificate line items associated with product list items, the function updates the purchase of the product list items. For example, if the basket contains an item added from a gift registry, the purchase history of the respective gift registry item is updated.
Returns:
The created order in status CREATED or null if an error occured.
- Type
- dw.order.Order
(inner) CartModel/createShipmentShippingAddress(shipmentID) → {dw.order.OrderAddress}T
Creates a shipping address for the shipment with the given shipment ID.
Parameters:
Name | Type | Description |
---|---|---|
shipmentID |
String |
The ID of the shipment to create the shipping address for. |
Returns:
The created shipping address.
(inner) CartModel/determineUniqueShipmentID(baseID) → {String}
Determines a unique shipment ID for shipments in the current cart and the given base ID. The function appends a counter to the base ID and checks the existence of the resulting ID. If the resulting ID is unique, this ID is returned; if not, the counter is incremented and checked again.
Parameters:
Name | Type | Description |
---|---|---|
baseID |
String |
The base ID. |
Returns:
Calculated shipment ID.
- Type
- String
(inner) CartModel/get(parameteropt) → {module:models/CartModel~CartModel}
Gets a new instance for the current or a given basket.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
parameter |
dw.order.Basket |
<optional> |
The basket object to enhance/wrap. If NULL the basket is retrieved from the current session, if existing. |
Returns:
(inner) CartModel/getAddressBookAddresses() → {dw.util.ArrayList}
Returns all addresses of the cart's address book. The addresses are stored as a JSON objects in a custom attribute named 'sessionAddressBook'.
Returns:
An ArrayList containing a addresses of the addresses stored in the carts address book.
- Type
- dw.util.ArrayList
(inner) CartModel/getApplicableShippingMethods(address) → {dw.util.Collection}
Retrieves the list of applicable shipping methods for a given shipment and a full or partial shipping address. A shipping method is applicable if it does not exclude any of the products in the shipment, and does not exclude the specified address.
Parameters:
Name | Type | Description |
---|---|---|
address |
module:models/TransientAddressModel~TransientAddressModel |
The address to get the applicable shipping methods for. |
Returns:
The list of applicable shipping methods for the default shipment and the given address.
- Type
- dw.util.Collection
(inner) CartModel/getBonusDiscountLineItemByUUID(lineItemUUID) → {dw.order.BonusDiscountLineItem}
Returns the bonus discount line item of the cart having the given UUID.
Parameters:
Name | Type | Description |
---|---|---|
lineItemUUID |
String |
The UUID of the bonus discount line item. |
Returns:
The bonus discount line item or null if not found.
(inner) CartModel/getBundledProductLineItemByPID(bundleLineItem, pid) → {dw.order.ProductLineItem}
Searches a bundle line item for a product line item with a specific product ID.
Parameters:
Name | Type | Description |
---|---|---|
bundleLineItem |
dw.order.ProductLineItem |
The bundle product line item, which contains two or more product line items. |
pid |
String |
The product identifier of the product line item to find. |
Returns:
The product line item or null if not found.
(inner) CartModel/getGiftCertIdList() → {dw.util.ArrayList}
Creates a list of gift certificate ids from gift certificate payment instruments.
Returns:
The list of gift certificate IDs.
- Type
- dw.util.ArrayList
(inner) CartModel/getNewBonusDiscountLineItems(previousBonusDiscountLineItems) → {dw.order.BonusDiscountLineItem}
Checks to see if a new bonus discount line item was created by providing a list of 'previous' discount line items.
Parameters:
Name | Type | Description |
---|---|---|
previousBonusDiscountLineItems |
dw.util.Collection |
Baseline collection of bonus discount line items. |
Returns:
The newly created bonus discount line item.
(inner) CartModel/getNonGiftCertificateAmount() → {dw.value.Money}
Calculates the amount to be paid by a non-gift certificate payment instrument based on the given basket. The function subtracts the amount of all redeemed gift certificates from the order total and returns this value.
Returns:
The amount to be paid by a non-gift certificate payment instrument.
- Type
- dw.value.Money
(inner) CartModel/getPhysicalShipments() → {dw.util.ArrayList}
Determines the physical shipments of the current cart. Physical shipments are shipments that contain at least one product line item. A shipment that contains only gift certificates is not a physical shipment. Product line items marked for in-store pickup are also not considered physical shipments.
Returns:
List of physical shipments.
- Type
- dw.util.ArrayList
(inner) CartModel/getProductLineItemByUUID(lineItemUUID) → {dw.order.ProductLineItem}
Returns the product line item of the cart with a specific UUID.
Parameters:
Name | Type | Description |
---|---|---|
lineItemUUID |
String |
The UUID of the line item. |
Returns:
The product line item or null if not found.
(inner) CartModel/goc() → {module:models/CartModel~CartModel}
Gets or creates a new instance of a basket.
Returns:
(inner) CartModel/initAddressBook(customer)T
Loads customer addresses and shipment addresses and stores them into the session address book attribute of the cart, if they are available and configured in Business Manager.
Parameters:
Name | Type | Description |
---|---|---|
customer |
dw.customer.Customer |
The customer to load the addresses from. |
(inner) CartModel/preCalculateShipping(shippingMethod) → {Object}
Updates the shipping method of the given shipment. If a shipping method ID is given, the given shipping method is used to update the shipment.
Parameters:
Name | Type | Description |
---|---|---|
shippingMethod |
dw.order.ShippingMethod |
A shipping method. |
Returns:
Returns the following object:
"shippingExclDiscounts" : this.getShippingTotalPrice(),
"shippingInclDiscounts" : this.getAdjustedShippingTotalPrice(),
"productShippingCosts" : productShippingCosts,
"productShippingDiscounts" : productShippingDiscounts,
"shippingPriceAdjustments" : priceAdjArray,
"shippingPriceAdjustmentsTotal" : priceAdjTotal,
"surchargeAdjusted" : adustedSurchargeTotal,
"baseShipping" : baseShipping,
"baseShippingAdjusted" : baseShippingAdjusted
- Type
- Object
(inner) CartModel/removeBonusDiscountLineItemProducts(bonusDiscountLineItem)T
Deletes all the products associated with a bonus discount line item.
Parameters:
Name | Type | Description |
---|---|---|
bonusDiscountLineItem |
dw.order.BonusDiscountLineItem |
The bonus discount line item to remove the product line items for. |
(inner) CartModel/removeEmptyShipments()T
The function removes all empty shipments of the current cart.
(inner) CartModel/removeExistingPaymentInstruments(uuid) → {dw.order.GiftCertificate|null}
Gets a gift certificate line item.
Parameters:
Name | Type | Description |
---|---|---|
uuid |
String |
UUID of the gift certificate line item to retrieve. |
Returns:
giftCertificate object with the passed UUID or null if no gift certificate with the passed UUID exists in the cart.
- Type
- dw.order.GiftCertificate | null
(inner) CartModel/removeExistingPaymentInstruments(method)T
Determines if the cart already contains payment instruments of the given payment method and removes them from the basket.
Parameters:
Name | Type | Description |
---|---|---|
method |
String |
Name of the payment method. |
(inner) CartModel/removeGiftCertificatePaymentInstrument(giftCertificateID)T
Removes a gift certificate payment instrument with the given gift certificate ID from the basket.
Parameters:
Name | Type | Description |
---|---|---|
giftCertificateID |
String |
The ID of the gift certificate to remove the payment instrument for. |
(inner) CartModel/removePaymentInstruments(paymentInstruments)T
Deletes multiple payment instruments.
Parameters:
Name | Type | Description |
---|---|---|
paymentInstruments |
dw.util.Collection |
The payment instruments to remove. |
(inner) CartModel/separateQuantities(pli, quantityLineItems) → {dw.util.ArrayList}
Creates a new QuantityLineItem helper object for each quantity of a ProductLineItem, if one does not already exist. It does not create QuantityLineItems for products using in-store pickup as the shipping method.
Parameters:
Name | Type | Description |
---|---|---|
pli |
dw.order.ProductLineItem |
The ProductLineItem. |
quantityLineItems |
dw.util.ArrayList |
The existing QuantityLineItems. |
Returns:
A list of separated QuantityLineItems.
- Type
- dw.util.ArrayList
(inner) CartModel/updateAddressBookAddress(addressToUpdate)T
Updates the given address in the cart's address book.
Parameters:
Name | Type | Description |
---|---|---|
addressToUpdate |
module:models/TransientAddressModel~TransientAddressModel |
The address to update. |
(inner) CartModel/updateGiftCertificateShipments()T
Cleans the shipments of the current basket by putting all gift certificate line items to single, possibly new, shipments, with one shipment per gift certificate line item.
(inner) CartModel/updateLineItem(lineItem, product, quantity, productOptionModel)T
Replaces the current product of the specified product line item with the specified product.
By default, when a bundle is added to a cart, all its child products are added as well. However, if those products are variants then the master products must be replaced with the selected variants that get passed in the CurrentHttpParameterMap.childPids as comma separated list of pids of the bundled products that are variations and any options.
Parameters:
Name | Type | Description |
---|---|---|
lineItem |
dw.order.ProductLineItem |
The product line item to replace. |
product |
dw.catalog.Product |
The new product. |
quantity |
Number |
The quantity of the product line item after replacement. |
productOptionModel |
dw.catalog.ProductOptionModel |
The option model of the product to add to the basket. |
(inner) CartModel/updateShipmentShippingMethod(shipmentID, shippingMethodID, shippingMethod, shippingMethods)T
Sets the shipping method of the given shipment to the passed method. The list of allowed shipping methods may be passed in as a parameter. If not, then it is retrieved using ShipmentShippingModel.getApplicableShippingMetods(). If the passed shipping method is not in this list, then the function uses the default shipping method. If the default shipping method is not in the list, the function uses the first method in the list.
Parameters:
Name | Type | Description |
---|---|---|
shipmentID |
String |
The ID of the shipment to update the shipping method for. |
shippingMethodID |
String |
The ID of the shipping method to set for the shipment. |
shippingMethod |
dw.order.ShippingMethod |
The shipping method to set for the shipment. |
shippingMethods |
dw.util.Collection |
The list of applicable shipping methods. |
(inner) CartModel/validateForCheckout() → {dw.system.Status|Boolean}
Implements a typical shopping cart checkout validation. Some parts of the validation script are specific to the reference application logic and might not be applicable to our customer's storefront applications. However, the shopping cart validation script can be customized to meet specific needs and requirements.
This function implements the validation of the shopping cart against specific conditions in the following steps:
- validate that total price is not N/A
- validate that all products in the basket are still in site catalog and online
- validate that all coupon codes in the basket are valid
- validate that the taxes can be calculated for all products in the basket (if ValidateTax input parameter is true)
Returns:
-
BasketStatus
- Type
- dw.system.Status
-
EnableCheckout
- Type
- Boolean
(inner) CartModel/validatePaymentInstruments(customer, countryCode, amount) → {dw.util.Collection|dw.util.Collection}
Verifies whether existing non-gift-certificate payment instrument methods or cards are still applicable. Returns the collection of valid and invalid payment instruments.
Parameters:
Name | Type | Description |
---|---|---|
customer |
dw.customer.Customer |
The current customer. |
countryCode |
String |
The country code. |
amount |
Number |
The payment amount. |
Returns:
-
ValidPaymentInstruments - The collection of valid payment instruments.
- Type
- dw.util.Collection
-
InvalidPaymentInstruments - The collection of invalid payment instruments.
- Type
- dw.util.Collection