website logo
SupportDashboardAbout SparkLayerSchedule Demo
📘Help Docs
⚙️Tech Docs
Navigate through spaces
⌘K
Introduction
API Authentication
Pricing API
Pricing API Docs
Core API
Core API Docs
Sync Logging API Docs
Purchasing API Docs
JavaScript SDK
Headless
JS SDK Docs
Spark Options
GraphQl
Docs powered by
Archbee
JavaScript SDK

JS SDK Docs



<a name="module_spark">


spark

Attached to window (used as window.spark), when SparkLayer has completed loading and a user is logged in.

  • spark
    • static
      • .isLoggedIn() ⇒ Promise.<boolean>
      • .initialiseRemoteData() ⇒ Promise.<UserData>
      • .switchImpersonatingCustomer(customerId) ⇒ Promise.<UserData>
      • .fetch(query, variables) ⇒ Promise.<Response>
      • .updateCart(input, cartSuccessHandledLocally, cartErrorsHandledLocally) ⇒ Promise.<(null|*)>
      • .externalClearBasket() ⇒ Promise.<void>
      • .getProduct(parentProductId) ⇒ Promise.<Product>
      • .getVariant(parentProductId, variantSku) ⇒ Promise.<ProductVariant>
      • .getPackSizeForVariant(parentProductId, variantSku) ⇒ Promise.<number>
      • .getRrpPriceForVariant(parentProductId, variantSku) ⇒ Promise.<{rrp: (number|null), currencyCode: string}>
      • .getPricingForVariant(parentProductId, variantSku) ⇒ Promise.<{price: number, rrp: number, priceBreaks: Array.<PriceBreaks>, currencyCode: string}>
      • .getPriceForProduct(parentProductId) ⇒ Promise.<{numberOfPrices: number, numberOfPricesExcludingBreaks: number, fromPrice: (number|null), fromPriceExcludingBreaks: (number|null), rrpPrice: (number|null), currencyCode: string, hasPriceBreaks: boolean}>
      • .calculatePricingForVariant(parentProductId, variantSku, qty, qtyAcrossVariants) ⇒ Promise.<{unitPrice: number, rrp: (number|null), totalPrice: (number|null), priceBreakSavingsPercentage: (number|null), hasPriceBreaks: boolean, currencyCode: (string), priceBreaks: (Array.<PriceBreaks>), basePrice: number}>
      • .getCart() ⇒ Promise.<object>
    • inner
      • ~spark : object
      • ~options : object
      • ~display : object
      • ~UserData : Object
      • ~CartItemInput : Object
      • ~UpdateCart : Object
      • ~Price : Object
      • ~PriceBreaks : Object
      • ~Product : Object
      • ~ProductVariant : Object



<a name="module_spark.isLoggedIn">


spark.isLoggedIn() ⇒ Promise.<boolean>

Check if user is logged in

Kind: static method of spark

<a name="module_spark.initialiseRemoteData">


spark.initialiseRemoteData() ⇒ Promise.<UserData>

Fetchs logged in customer data and site related data

Kind: static method of spark

<a name="module_spark.switchImpersonatingCustomer">


spark.switchImpersonatingCustomer(customerId) ⇒ Promise.<UserData>

Switch impersonating customer or end impersonation with null

Kind: static method of spark

Param

Type

customerId

string | null



<a name="module_spark.fetch">


spark.fetch(query, variables) ⇒ Promise.<Response>

Run a GraphQL query (with the user authenticated)

Kind: static method of sparkReturns: Promise.<Response> - Returns a promise which resolves to standard JS response object (use status and data)

Param

Description

query

GraphQL query string

variables

GraphQL variables



<a name="module_spark.updateCart">


spark.updateCart(input, cartSuccessHandledLocally, cartErrorsHandledLocally) ⇒ Promise.<(null|*)>

Run an update cart mutation, shows appropriate toasts and returns result

Kind: static method of sparkReturns: Promise.<(null|*)> - Returns UpdateCartItemResult or null if error (check console for error)Throws:

  • Error If request fails

Param

Type

Description

input

UpdateCart

Follows the GraphQL UpdateCart Mutation Object

cartSuccessHandledLocally

boolean

Do not show any success toasts, ask result will be handled locally (useful in the cart, as the change is shown by the update)

cartErrorsHandledLocally

boolean

Do not show any error toasts, ask result will be handled locally



<a name="module_spark.externalClearBasket">


spark.externalClearBasket() ⇒ Promise.<void>

Call SparkLayer to clear the basket, designed to be used on the thanks page

Kind: static method of spark

<a name="module_spark.getProduct">


spark.getProduct(parentProductId) ⇒ Promise.<Product>

Fetch the graphql product object for a given parent product id

Kind: static method of sparkThrows:

  • If product not found or error occurred fetching product

Param

Type

parentProductId

string



<a name="module_spark.getVariant">


spark.getVariant(parentProductId, variantSku) ⇒ Promise.<ProductVariant>

Fetch the graphql variant object for a given parent product id and variant sku

Kind: static method of sparkThrows:

  • If product/variant not found or error occurred fetching product

Param

Type

parentProductId

string

variantSku

string



<a name="module_spark.getPackSizeForVariant">


spark.getPackSizeForVariant(parentProductId, variantSku) ⇒ Promise.<number>

Fetch the pack size for a variant given parent product id and variant sku

Kind: static method of sparkReturns: Promise.<number> - Pack Size for VariantThrows:

  • If product/variant not found or error occurred fetching product

Param

Type

parentProductId

string

variantSku

string



<a name="module_spark.getRrpPriceForVariant">


spark.getRrpPriceForVariant(parentProductId, variantSku) ⇒ Promise.<{rrp: (number|null), currencyCode: string}>

Fetch the RRP price for a variant given parent product id and variant sku

Kind: static method of sparkReturns: Promise.<{rrp: (number|null), currencyCode: string}> - RRP price (null if not set for currency) and currency codeThrows:

  • If product/variant not found or error occurred fetching product

Param

Type

parentProductId

string

variantSku

string



<a name="module_spark.getPricingForVariant">


spark.getPricingForVariant(parentProductId, variantSku) ⇒ Promise.<{price: number, rrp: number, priceBreaks: Array.<PriceBreaks>, currencyCode: string}>

Fetch the pricing for a variant given parent product id and variant sku

Kind: static method of sparkReturns: Promise.<{price: number, rrp: number, priceBreaks: Array.<PriceBreaks>, currencyCode: string}> - All price related data for variantThrows:

  • If product/variant not found or error occurred fetching product

Param

Type

parentProductId

string

variantSku

string



<a name="module_spark.getPriceForProduct">


spark.getPriceForProduct(parentProductId) ⇒ Promise.<{numberOfPrices: number, numberOfPricesExcludingBreaks: number, fromPrice: (number|null), fromPriceExcludingBreaks: (number|null), rrpPrice: (number|null), currencyCode: string, hasPriceBreaks: boolean}>

Fetch the pricing for a parent product includes price breaks, lowest price and the number of prices (used to note if from is needed to be shown)

Kind: static method of sparkReturns: Promise.<{numberOfPrices: number, numberOfPricesExcludingBreaks: number, fromPrice: (number|null), fromPriceExcludingBreaks: (number|null), rrpPrice: (number|null), currencyCode: string, hasPriceBreaks: boolean}> - All price related data for parent product, including price breaks, lowest price and number of prices. Number of prices can be used to note if from is needed to be shown.Throws:

  • If product not found or error occurred fetching product

Param

Type

parentProductId

string



<a name="module_spark.calculatePricingForVariant">


spark.calculatePricingForVariant(parentProductId, variantSku, qty, qtyAcrossVariants) ⇒ Promise.<{unitPrice: number, rrp: (number|null), totalPrice: (number|null), priceBreakSavingsPercentage: (number|null), hasPriceBreaks: boolean, currencyCode: (string), priceBreaks: (Array.<PriceBreaks>), basePrice: number}>

Given a product id, sku and quantity, return the price for the product

Kind: static method of sparkReturns: Promise.<{unitPrice: number, rrp: (number|null), totalPrice: (number|null), priceBreakSavingsPercentage: (number|null), hasPriceBreaks: boolean, currencyCode: (string), priceBreaks: (Array.<PriceBreaks>), basePrice: number}> - Total price (qty * unit price) and unit priceThrows:

  • If product/variant not found or error occurred fetching product

Param

Type

Description

parentProductId

string



variantSku

string



qty

number



qtyAcrossVariants

number | null

For tiered pricing, this is calculated by qty across variants (if configured)



<a name="module_spark.getCart">


spark.getCart() ⇒ Promise.<object>

Fetch either the local cached cart or fetch the cart from GraphQL

Kind: static method of spark

<a name="module_spark..spark">


spark~spark : object

Base Spark Object, attached to window once loaded

Kind: inner typedef of sparkProperties

Name

Type

options

options



<a name="module_spark..options">


spark~options : object

Kind: inner typedef of sparkProperties

Name

Type

display

display



<a name="module_spark..display">


spark~display : object

Kind: inner typedef of sparkProperties

Name

Type

show

boolean

max

number

low

number

last

number | boolean



<a name="module_spark..UserData">


spark~UserData : Object

Kind: inner typedef of sparkAccess: publicProperties

Name

Type

id

string

email

string

name

string

companyName

string



<a name="module_spark..CartItemInput">


spark~CartItemInput : Object

Kind: inner typedef of sparkAccess: publicProperties

Name

Type

Description

deltaQuantity

int

The quantity to add or remove from the cart

absoluteQuantity

int

The quantity to set the cart item to

itemKey

string

Used within the cart to identify the item

sku

string

The SKU of the item



<a name="module_spark..UpdateCart">


spark~UpdateCart : Object

Kind: inner typedef of sparkAccess: publicProperties

Name

Type

Description

products

Array.<CartItemInput>

An array of products

deliveryAddressId

string

The ID of the delivery address

customerReference

string

The customer reference

clearCart

boolean

Whether to clear the cart or not

recreateCartFromTemplateId

string

The ID of the cart template to recreate the cart from



<a name="module_spark..Price">


spark~Price : Object

Kind: inner typedef of sparkAccess: publicProperties

Name

Type

Description

taxRate

number

The tax rate (note, tax only supported on Enterprise plans, otherwise will be 0)

net

number

The net price

gross

number

The gross price (note, only supported on Enterprise plans, due to tax setup)

currencyCode

string

The currency code



<a name="module_spark..PriceBreaks">


spark~PriceBreaks : Object

Kind: inner typedef of sparkAccess: publicProperties

Name

Type

quantity

number

price

Price



<a name="module_spark..Product">


spark~Product : Object

Kind: inner typedef of sparkAccess: publicProperties

Name

Type

Description

id

string

The product ID

variants

Array.<ProductVariant>

The product variants



<a name="module_spark..ProductVariant">


spark~ProductVariant : Object

Kind: inner typedef of sparkAccess: publicProperties

Name

Type

Description

id

string

The product ID

stockStatus

in_stock | backorder | out_of_stock

The stock status

cartImageUrl

string

The URL of the product image

sku

string

The SKU of the product

slug

string

The slug of the product

name

string

The name of the product

price

Price | null

The price of the product

priceBreaks

Array.<PriceBreaks>

The price breaks of the product

rrp

number | null

The RRP of the product (if available for currency if not null)

settings

Array.<{key: string, value: number}>

The settings of the product

options

Array.<{group: string, value: string}>

The options of the product

restockDate

string | number | Date

The restock date of the product

stockQty

number

The current quantity of stock left of the product



Updated 04 Sep 2023
Did this page help you?
PREVIOUS
Headless
NEXT
Spark Options
Docs powered by
Archbee
TABLE OF CONTENTS
spark
spark.isLoggedIn() ⇒ Promise.<boolean>
spark.initialiseRemoteData() ⇒ Promise.<UserData>
spark.switchImpersonatingCustomer(customerId) ⇒ Promise.<UserData>
spark.fetch(query, variables) ⇒ Promise.<Response>
spark.updateCart(input, cartSuccessHandledLocally, cartErrorsHandledLocally) ⇒ Promise.<(null|*)>
spark.externalClearBasket() ⇒ Promise.<void>
spark.getProduct(parentProductId) ⇒ Promise.<Product>
spark.getVariant(parentProductId, variantSku) ⇒ Promise.<ProductVariant>
spark.getPackSizeForVariant(parentProductId, variantSku) ⇒ Promise.<number>
spark.getRrpPriceForVariant(parentProductId, variantSku) ⇒ Promise.<{rrp: (number|null), currencyCode: string}>
spark.getPricingForVariant(parentProductId, variantSku) ⇒ Promise.<{price: number, rrp: number, priceBreaks: Array.<PriceBreaks>, currencyCode: string}>
spark.getPriceForProduct(parentProductId) ⇒ Promise.<{numberOfPrices: number, numberOfPricesExcludingBreaks: number, fromPrice: (number|null), fromPriceExcludingBreaks: (number|null), rrpPrice: (number|null), currencyCode: string, hasPriceBreaks: boolean}>
spark.calculatePricingForVariant(parentProductId, variantSku, qty, qtyAcrossVariants) ⇒ Promise.<{unitPrice: number, rrp: (number|null), totalPrice: (number|null), priceBreakSavingsPercentage: (number|null), hasPriceBreaks: boolean, currencyCode: (string), priceBreaks: (Array.<PriceBreaks>), basePrice: number}>
spark.getCart() ⇒ Promise.<object>
spark~spark : object
spark~options : object
spark~display : object
spark~UserData : Object
spark~CartItemInput : Object
spark~UpdateCart : Object
spark~Price : Object
spark~PriceBreaks : Object
spark~Product : Object
spark~ProductVariant : Object
Docs powered by
Archbee