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.9 app/assets/javascripts/spree/api/storefront/cart.js
spree_api-4.1.15 app/assets/javascripts/spree/api/storefront/cart.js
spree_api-4.2.7 app/assets/javascripts/spree/api/storefront/cart.js
spree_frontend-4.3.3 app/assets/javascripts/spree/api/storefront/cart.js
spree_api-4.2.6 app/assets/javascripts/spree/api/storefront/cart.js
spree_frontend-4.3.2 app/assets/javascripts/spree/api/storefront/cart.js
spree_frontend-4.4.0 app/assets/javascripts/spree/api/storefront/cart.js
spree_frontend-4.3.1 app/assets/javascripts/spree/api/storefront/cart.js
spree_frontend-4.3.0 app/assets/javascripts/spree/api/storefront/cart.js
spree_frontend-4.3.0.rc3 app/assets/javascripts/spree/api/storefront/cart.js
spree_frontend-4.3.0.rc2 app/assets/javascripts/spree/api/storefront/cart.js
spree_frontend-4.3.0.rc1 app/assets/javascripts/spree/api/storefront/cart.js
spree_api-4.2.5 app/assets/javascripts/spree/api/storefront/cart.js
spree_api-4.1.14 app/assets/javascripts/spree/api/storefront/cart.js
spree_api-4.0.8 app/assets/javascripts/spree/api/storefront/cart.js
spree_api-4.2.4 app/assets/javascripts/spree/api/storefront/cart.js
spree_api-3.7.14.1 app/assets/javascripts/spree/api/storefront/cart.js
spree_api-4.2.3.1 app/assets/javascripts/spree/api/storefront/cart.js
spree_api-4.1.13.1 app/assets/javascripts/spree/api/storefront/cart.js
spree_api-4.0.7.1 app/assets/javascripts/spree/api/storefront/cart.js