Sha256: ed345c742a0fabfc39f42dd5cb5d13c7a6854ef49f80f216c38b2b5ee32bfb29

Contents?: true

Size: 1.37 KB

Versions: 77

Compression:

Stored size: 1.37 KB

Contents

//= require spree/api/main

SpreeAPI.Storefront.createCart = function (successCallback, failureCallback) {
  fetch(Spree.routes.api_v2_storefront_cart_create, {
    method: 'POST',
    headers: SpreeAPI.prepareHeaders()
  }).then(function (response) {
    switch (response.status) {
      case 422:
        response.json().then(function (json) { failureCallback(json.error) })
        break
      case 500:
        SpreeAPI.handle500error()
        break
      case 201:
        response.json().then(function (json) {
          SpreeAPI.orderToken = json.data.attributes.token
          successCallback()
        })
        break
    }
  })
}

SpreeAPI.Storefront.addToCart = function (variantId, quantity, options, successCallback, failureCallback) {
  fetch(Spree.routes.api_v2_storefront_cart_add_item, {
    method: 'POST',
    headers: SpreeAPI.prepareHeaders({ 'X-Spree-Order-Token': SpreeAPI.orderToken }),
    body: JSON.stringify({
      variant_id: variantId,
      quantity: quantity,
      options: options
    })
  }).then(function (response) {
    switch (response.status) {
      case 422:
        response.json().then(function (json) { failureCallback(json.error) })
        break
      case 500:
        SpreeAPI.handle500error()
        break
      case 200:
        response.json().then(function (json) {
          successCallback(json.data)
        })
        break
    }
  })
}

Version data entries

77 entries across 77 versions & 2 rubygems

Version Path
spree_api-4.0.1 app/assets/javascripts/spree/api/storefront/cart.js
spree_api-3.7.7 app/assets/javascripts/spree/api/storefront/cart.js
spree_api-4.0.0 app/assets/javascripts/spree/api/storefront/cart.js
spree_api-4.0.0.rc3 app/assets/javascripts/spree/api/storefront/cart.js
spree_api-3.7.6 app/assets/javascripts/spree/api/storefront/cart.js
spree_api-3.7.5 app/assets/javascripts/spree/api/storefront/cart.js
spree_api-4.0.0.rc2 app/assets/javascripts/spree/api/storefront/cart.js
spree_api-4.0.0.rc1 app/assets/javascripts/spree/api/storefront/cart.js
spree_api-4.0.0.beta app/assets/javascripts/spree/api/storefront/cart.js
spree_api-3.7.4 app/assets/javascripts/spree/api/storefront/cart.js
spree_api-3.7.3 app/assets/javascripts/spree/api/storefront/cart.js
spree_api-3.7.2 app/assets/javascripts/spree/api/storefront/cart.js
spree_api-3.7.1 app/assets/javascripts/spree/api/storefront/cart.js
spree_api-3.7.0 app/assets/javascripts/spree/api/storefront/cart.js
spree_api-3.7.0.rc3 app/assets/javascripts/spree/api/storefront/cart.js
spree_api-3.7.0.rc2 app/assets/javascripts/spree/api/storefront/cart.js
spree_api-3.7.0.rc1 app/assets/javascripts/spree/api/storefront/cart.js