new CartComponent()

Description

The CartComponent provides ways to work with the cart, for example, adding lines, getting the cart summary, and applying promotions. It also exposes before and after events for several methods, for example, beforeAddLine and afterAddLine.

Get an instance of this component by calling container.getComponent("Cart").

Members


CART_VIEW :String

Description

Name of the cart main view. Please use this name to reference views in methods like addChildView, addToViewContextDefinition, etc


CART_MINI_VIEW :String

Description

Name of the mini-cart main. Please use this name to reference views in methods like addChildView, addToViewContextDefinition, etc


WIZARD_VIEW :String

Methods


addLine( data ) → {Deferred}

Description

Adds a line to the cart.

    container.getComponent('Cart').addLine({
			        line: {
			            quantity: 1, 
			            item: {
			                internalid: 8058
			            }
			        }
			    }).then(function() 
			  {alert(Utils.translate('Item added.'))});
Parameters
Name Type Description
data AddLine
Returns

Returns a Deferred object. If the promise is resolved, the line is added to the cart.


addLines( lines ) → {Deferred}

Description

Adds multiple lines to the cart.

Parameters
Name Type Description
lines AddLines
Returns

Returns a Deferred object. If the promise is resolved, the lines are added to the cart. See CartComponent#addLine.


getLines() → {Deferred.<Array.<Line>>}

Description

Gets the lines in the cart.

Returns

Returns a Deferred object. If the promise is resolved, it returns the lines in the cart (an array of Line). Otherwise, the promise returns the rejected state.


removeLine( internalid ) → {Deferred}

Description

Removes a line from the cart. Returns a Deferred object in the resolved state if it was successful, or the rejected state if it failed.

Parameters
Name Type Description
internalid String

The ID of the line to remove.

Returns

Returns a Deferred object. If the promise is resolved, it indicates the operation was successful.


updateLine( line ) → {Deferred}

Description

Updates a line in the cart.

Parameters
Name Type Description
line Line
Returns

Returns a Deferred object. If the promise is resolved, it returns the Line. Otherwise, the promise returns the rejected state.


getSummary() → {Deferred}

Description

Gets a summary of the cart.

Returns

Returns a Deferred object. If the promise is resolved, it returns a Summary. If the promise is rejected, it returns an error.


submit() → {Deferred}

Description

Submits the order.

var cart = container.getComponent("Cart");
			cart.submit();
			
Returns

Returns a Deferred object. If the promise is resolved, it returns a ConfirmationSubmit. If the promise is rejected, it returns an error.


addPayment( data )

Description

Adds a payment method.

Parameters
Name Type Description
data PaymentMethod

getPaymentMethods() → {Deferred}

Description

Gets the payment methods on the order.

Returns

Returns a Deferred object. If the promise is resolved, it returns an array of PaymentMethod. If the promise is rejected, it returns an error.


addPromotion( The )

Description

Applies a promotion to the cart.

Parameters
Name Type Description
The Object

promotion code (promocode) of the promotion.


removePromotion( data ) → {Deferred}

Description

Removes a promotion from the cart.

Parameters
Name Type Description
data Object
Returns

getPromotions() → {Deferred}

Description

Gets the promotions (promotion codes) in the cart.

Returns

Returns a Deferred object. If the promise is resolved, it returns an array of Promotion. If the promise is rejected, it returns an error.


estimateShipping( locationData )

Description

Gets the estimated shipping costs.

Parameters
Name Type Description
locationData Object

The postcode and country.


removeShipping()

Description

Removes the shipping method from the order.


clearEstimateShipping()

Description

Clears the shipping estimation from the order.


getAddresses() → {Deferred}

Description

Gets all addresses of the order.

Returns

Returns a Deferred object. If the promise is resolved, it returns an array of Address. If the promise is rejected, it returns an error.


getShipAddress() → {Deferred}

Description

Gets the shipping address of the order.

Returns

Returns a Deferred object. If the promise is resolved, it returns a Address. If the promise is rejected, it returns an error.


getBillAddress() → {Deferred}

Description

Gets the billing address of the order.

Returns

Returns a Deferred object. If the promise is resolved, it returns a Address. If the promise is rejected, it returns an error.


getShipMethods() → {Deferred}

Description

Gets the shipping methods of the order.

Returns

Returns a Deferred object. If the promise is resolved, it returns an array of ShipMethod. If the promise is rejected, it returns an error.


getShipMethod() → {Deferred}

Description

Returns the selected shipping method of the order

Returns

Returns a Deferred object. If the promise is resolved, it returns a ShipMethod. If the promise is rejected, it returns an error.


setChildViewIndex( view_id, placeholder_selector, view_name, index ) → {void}

Description

Changes the position of a child view inside a container.

Parameters
Name Type Description
view_id string

The identifier of the view of the current component that contains the child view whose position will be changed.

placeholder_selector string

The identifier of a location in the specified view (view_id) where the child view will be added.

view_name string

The identifier of a view in the placeholder.

index number

The index of the child view's position.

Returns

Returns null if the operation is successful. Otherwise, it throws an exception.

Throws
Details

addChildViews( view_id, child_views ) → {void}

Description

Adds one or more child views to an existing view. The existing view must already be in the DOM and must have the 'data-view' HTML attribute.

The addChildViews method is flexible, but more complex than addChildView. Use the simpler addChildView where possible.

EXAMPLE

checkout.addChildViews(
			    checkout.WIZARD_VIEW
			    , {
			        'Wizard.StepNavigation':
			        {
			            'CheckoutView':
			            {
			                childViewIndex: 1
			            ,   childViewConstructor: function ()
			                {
			                    return new CheckoutExtensionView({checkout:checkout});
			                }
			            }
			        }
			    }
			);
Parameters
Name Type Description
view_id string

The identifier of the view of the current component to which the child views will be added.

child_views object
Returns

Returns null if the operation is successful. Otherwise, it throws an exception.

Throws
Details

addChildView( view_id, childViewConstuctor ) → {void}

Description

Adds a child view to an existing View which is already appended in the DOM with the given data-view HTML attribute.

EXAMPLE

checkout.addChildView('Wizard.StepNavigation', function () {
			    return new CheckoutExtensionView({checkout:checkout});
			});
Parameters
Name Type Description
view_id string

The identifier of the view of the current component to which the child view will be added.

childViewConstuctor SimpleChildViewConstructor

The identifier of the location in the specified view (view_id) where the child view will be added.

Returns

Returns null if the operation is successful. Otherwise, it throws an exception.

Throws
Details

removeChildView( view_id, placeholder_selector [, view_name ] ) → {void}

Description

Removes a child view from a view.

Parameters
Name Type Attributes Description
view_id string

The identifier of the view of the current component from which the child view will be removed.

placeholder_selector string

The identifier of the location in the specified view (view_id) from which the child view will be removed.

view_name string <optional>

The identifier of the view to be removed.

Returns

Returns null if the operation is successful. Otherwise, it throws an exception.

Throws
Details

addToViewContextDefinition( view_id, property_name, type, callback ) → {void}

Description

Adds a property to the UI context of a view to extend interaction with its template.

Parameters
Name Type Description
view_id string

The identifier of the view of the current component to which the context property will be added.

property_name string

The name of the property.

type string

The type of the property. The value returned by the callback function must be of the same type.

callback function

A function that sets the value of the property (property_name).

Returns

Returns null if the operation is successful. Otherwise, it throws an exception.

Throws

removeToViewContextDefinition( view_id, property_name ) → {void}

Description

Removes a property from the UI context of a view.

Parameters
Name Type Description
view_id string

The identifier of the view of the current component from which the context property will be removed.

property_name string

The name of the property.

Returns

Returns null if the operation is successful. Otherwise, it throws an exception.

Throws

addToViewEventsDefinition( view_id, event_selector, callback ) → {void}

Description

Adds an event handler to an event in a view.

Parameters
Name Type Description
view_id string

The identifier of the view of the current component to which the event handler will be added.

event_selector string
callback function

The event handler function to call when the specified event occurs.

Returns

Returns null if the operation is successful. Otherwise, it throws an exception.

Throws

removeToViewEventsDefinition( view_id, event_selector ) → {void}

Description

Removes an event handler from an event in a view.

Parameters
Name Type Description
view_id string

The identifier of the view of the current component to which the event handler will be added.

event_selector string
Returns

Returns null if the operation is successful. Otherwise, it throws an exception.

Throws

Events


beforeUpdateLine

Description

Cancelable event triggered before a line in the cart is updated. See CancelableEvents.


afterUpdateLine

Description

Event triggered after a line in the cart is updated.

Properties
Type Description
boolean

beforeRemoveLine

Description

Cancelable event triggered before a line in the cart is removed. See CancelableEvents.

Properties
Type Description
boolean

afterRemoveLine

Description

Event triggered after a line in the cart is removed.

Properties
Type Description
boolean

beforeEstimateShipping

Description

Cancelable event triggered before getting shipping esimates for the cart. See CancelableEvents.

Properties
Type Description
boolean

afterEstimateShipping

Description

Event triggered after shipping estimates retrieved.

Properties
Type Description
boolean

beforeClearEstimateShipping

Description

Cancelable event triggered before clearing shipping estimates for the cart. See CancelableEvents.

Properties
Type Description
boolean

afterClearEstimateShipping

Description

Event triggered after shipping estimates are cleared.

Properties
Type Description
boolean

beforeAddPromotion

Description

Cancelable event triggered before a promotion is applied to the cart. See CancelableEvents.

Properties
Type Description
boolean

afterAddPromotion

Description

Event triggered after a promotion is applied to the cart.

Properties
Type Description
boolean

beforeRemovePromotion

Description

Cancelable event triggered before a promotion is removed from the cart. See CancelableEvents.

Properties
Type Description
boolean

afterRemovePromotion

Description

Event triggered after a promotion is removed fromt the cart.

Properties
Type Description
boolean

beforeAddPayment

Description

Cancelable event triggered before a payment method is added to the order. See CancelableEvents.

Properties
Type Description
boolean

afterAddPayment

Description

Event triggered after a payment method is added to the order.

Properties
Type Description
boolean

beforeSubmit

Description

Cancelable event triggered before the order is submitted. See CancelableEvents.

Properties
Type Description
boolean

afterSubmit

Description

Event triggered after the order is submitted.

Properties
Type Description
boolean

beforeAddLine

Description

Cancelable event triggered before a line is added to the cart. See CancelableEvents.

Properties
Type Description
boolean

afterAddLine

Description

Event triggered after a line is added to the cart.

Properties
Type Description
boolean