API Docs for: WebTemplate API v2.0
Show:

WTCart Class

The class used to store and order before it reaches the checkout
example:
$cart = new WTCart();

Methods

clear

()

Clear the cart

getDiscount

() Int

Return the discount for the cart

Returns:

Int: The discount in dollars and cents

getFreight

(
  • args
)
Int

Return the freight for the cart

Parameters:

  • args Array

    An associative array containing keys for: country, postcode, weight, quantity, order value, Freight Carrier ID

Returns:

Int: The freight for the cart

getOrder

() WTOrder

Return the current order node object

Returns:

WTOrder: The current order node object

getQuantity

(
  • id
)
Int

Return the quantity of an item in the cart

Parameters:

  • id String

    The id of the item in the cart

Returns:

Int: The quantity of the item in the cart

getTotal

() Int

Return the total price of all the items in the cart (not including discount)

Returns:

Int: The total price of all the items in the cart

getTotalItemCount

() Int

Return the total number of distinct items in the cart

Returns:

Int: The number of distinct items in the cart

getTotalQuantity

() Int

Return the total number of items in the cart

Returns:

Int: The number of items in the cart

getTotalWeight

() Int

Return the total weight of all items in the cart (in grams)

Returns:

Int: The total weight of all items in the cart (in grams)

registerCartDiscountFunction

(
  • function
)
static

Register a custom function to calculate the discount to apply to the cart
The custom function should return the discount in dollars and cents

Parameters:

  • function Function

    The custom function to call when calculating discount

setFromRequest

(
  • [addToCurrent=false]
  • [requestData=null]
)

Add items to the cart from a post request

Parameters:

  • [addToCurrent=false] Object optional

    If an item is already in the cart, add to its quantity instead of replacing it

  • [requestData=null] Object optional

    If set, use this data instead of the data from the post request