An Ember Ecosystem
For Spree Commerce

spree-ember-checkouts

Extends Ember.Mixin

Provides Current Order and Checkout Functionality to the Spree service. This mixin is applied to the Spree service when spree-ember-checkouts initializes, therefore all functionality described here is available like so:

this.spree.addToCart(variantModel, 5);

Methods

Show Private Methods

_createNewOrder

private

Will attempt to create a new Order for the checkout user, and save the orderId and guestToken to the Spree service, so that it will persist across page refreshes. It will also initiate the state machine for the current order.


Returns:

Ember.RSVP.Promise:

A promise that resolves to the newly created Spree Order.

_restoreCurrentOrder

private

A method called in the spree-ember-checkouts initializer after the Checkouts mixin is applied to the Spree service, to initialize functionality in this mixin.


Returns:

Boolean:

Always resolves to true.

_saveLineItem

(
  • variant
  • quantity
  • order
)
private

An internal method for saving Line Items. If it is called for a variant that is already in the current order, it will add to the corresponding Line Item's quantity, otherwise it will create a new Line Item for that variant.

Parameters:

  • variant Ember.Object

    A class of the variant model

  • quantity Integer

    A quantity for the lineItem

  • order Ember.Object

    The corresponding order


Returns:

Ember.RSVP.Promise:

A promise that resolves to the newly created or updated lineItem object.

addToCart

(
  • variant
  • quantity
)

Adds a lineItem to the currentOrder. If there is no Current Order, Spree Ember will request a new order from the server, and set it as the Current Order on the Spree service.

Parameters:

  • variant DS.Model

    A class of the variant model

  • quantity Integer

    Optional, A quantity for the Line Item.


Returns:

Ember.RSVP.Promise:

A promise that resolves to the newly saved Line Item.

clearCurrentOrder

Clears the current order and any reference to it.


Returns:

Boolean:

Always returns true.

Properties

Show Private Properties

checkouts

Ember.Service

A reference to the Stateful Checkouts service.


currentOrder

DS.Model

A reference to the Current Order. It is only set twice in this code, once on Application initialization (in the case it was persisted), and once when a new order is created through the internal method _createNewOrder.


Default: null

guestToken

String

The token used to Authenticate the current user against the current order. Persisted to local storage via spree-ember-core/mixins/storable. This property is sent to the Spree server via the header X-Spree-Order-Token.


Default: null

orderId

String

The user's Current Order number, persisted to local storage via spree-ember-core/mixins/storable. This property is sent to the Spree server via the header X-Spree-Order-Id.


Default: null

Events

Show Private Events

addToCartFailed

Triggered whenever a Line Item is created or updated.


Event Payload
  • error Error

    The returned Server Error.

advanceCurrentOrderFailed

Triggered when the advanceCurrentOrder call fails.


Event Payload
  • error Error

    The returned Server Error.

checkoutStateDidChange

Triggered whenever the Current Order changes State.


Event Payload
  • order DS.Model

    The Current Order.

currentOrderDidComplete

Triggered whenever the Current Order reached it's "Complete" State.


Event Payload
  • order DS.Model

    The Current Order.

didAddToCart

Triggered whenever a Line Item is created or updated.


Event Payload
  • lineItem DS.Model

    The newly updated lineItem object

didAdvanceCurrentOrder

Triggered when the advanceCurrentOrder call succeeds.


Event Payload
  • currentOrderPromise Ember.RSVP.Promise

    A promise that resolves to the Current Order

didClearCurrentOrder

Triggered whenever a new Order is created for the checkout user.


didCreateNewOrder

Triggered whenever a new Order is created for the checkout user.


Event Payload
  • order DS.Model

    The newly created order object

didSaveCurrentOrder

Triggered when the _saveCurrentOrder call succeeds.


Event Payload
  • currentOrderPromise Ember.RSVP.Promise

    A promise that resolves to the Current Order

newOrderCreateFailed

Triggered whenever a new Order is created for the checkout user.


Event Payload
  • error Object

    The returned Server Error.

saveCurrentOrderFailed

Triggered when the _saveCurrentOrder call fails.


Event Payload
  • error Error

    The returned Server Error.

serverError

A generic event triggered whenever a Spree Server request fails.


Event Payload
  • error Object

    The error object returned from the Spree Server.