JavaScript SDK

JS SDK Docs

spark

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

spark.isLoggedIn() ⇒ Promise.<boolean>

Check if user is logged in

Kind: static method of #module_sparkspark

spark.initialiseRemoteData() ⇒ Promise.<UserData>

Fetchs logged in customer data and site related data

Kind: static method of #module_sparkspark

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

Switch impersonating customer or end impersonation with null

Kind: static method of #module_sparkspark

Param

Type

customerId

string | null

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

Run a GraphQL query (with the user authenticated)

Kind: static method of #module_sparkspark Returns: 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

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

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

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

  • Error If request fails

Param

Type

Description

input

Partial.<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

spark.externalClearBasket() ⇒ Promise.<void>

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

Kind: static method of #module_sparkspark

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

Fetch the graphql product object for a given parent product id

Kind: static method of #module_sparkspark Throws:

  • If product not found or error occurred fetching product

Param

Type

parentProductId

string

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

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

Kind: static method of #module_sparkspark Throws:

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

Param

Type

parentProductId

string

variantSku

string

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

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

Kind: static method of #module_sparkspark Returns: Promise.<number> - Pack Size for VariantThrows:

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

Param

Type

parentProductId

string

variantSku

string

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 #module_sparkspark Returns: 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

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 #module_sparkspark Returns: 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

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 #module_sparkspark Returns: 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

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 #module_sparkspark Returns: 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)

spark.getCart() ⇒ Promise.<object>

Fetch the cart from GraphQL

Kind: static method of #module_sparkspark

spark.uploadFile() ⇒ Promise.<string>

Uploads a file and returns the ID as a GID

Kind: static method of #module_sparkspark Throws:

  • if file mime type is invalid, file is too large, the file path is invalid, or there is some other error making the upload request

spark~spark : object

Base Spark Object, attached to window once loaded

Kind: inner typedef of #module_sparkspark Properties

Name

Type

options

options

spark~options : object

Kind: inner typedef of #module_sparkspark Properties

Name

Type

display

display

spark~display : object

Kind: inner typedef of #module_sparkspark Properties

Name

Type

show

boolean

max

number

low

number

last

number | boolean

spark~UserData : Object

Kind: inner typedef of #module_sparkspark Access: publicProperties

Name

Type

id

string

email

string

name

string

companyName

string

spark~CartItemInput : Object

Kind: inner typedef of #module_sparkspark Access: publicProperties

Name

Type

Description

adjustQuantity

int

The quantity to add or remove from the cart

quantity

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

quotedPrice

float



resetQuotedPrice

boolean



customAttributes

array



spark~UpdateCart : Object

Kind: inner typedef of #module_sparkspark Access: publicProperties

Name

Type

Description

products

Array.<Partial.<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

spark~Price : Object

Kind: inner typedef of #module_sparkspark Access: 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

spark~PriceBreak : Object

Kind: inner typedef of #module_sparkspark Access: publicProperties

Name

Type

quantity

number

price

Price

spark~Product : Object

Kind: inner typedef of #module_sparkspark Access: publicProperties

Name

Type

Description

id

string

The product ID

variants

Array.<ProductVariant>

The product variants

spark~CurrencyValue : Object

Kind: inner typedef of #module_sparkspark Access: publicProperties

Name

Type

number

string

currency

string

spark~ProductVariant : Object

Kind: inner typedef of #module_sparkspark Access: 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.<PriceBreak>

The price breaks of the product

rrp

number | null

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

rrpV2

CurrencyValue

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 26 Sep 2024
Did this page help you?