API Reference

Product Protection

The Shopify Addon provides specialized methods for managing product protection (warranty) plans in Shopify carts.

addPlanToCart

Adds an Extend warranty plan to the Shopify cart. This function should only be used within callbacks provided by Extend base SDK functions that return an Extend Plan and Product.

Syntax

ExtendShopify.addPlanToCart(plan, product, callback)
ExtendShopify.addPlanToCart(options, callback)

Parameters

Parameter Type Required Default Description
options AddToCartOptions Yes - Configuration object
callback Function No - Optional callback function

Callback Parameters

Parameter Type Required Default Description
error Error | null Yes - Error if operation failed

Examples

// Basic usage
const plan = {
  planId: 'warranty-plan-123',
  price: 2999, // Price in cents
  term: 24 // months
}

const product = {
  id: 'product-456',
  price: 29999,
  title: 'Smartphone',
  category: 'Electronics'
}

ExtendShopify.addPlanToCart(plan, product, (error) => {
  if (error) {
    console.error('Failed to add warranty:', error)
  } else {
    console.log('Warranty added to cart')
  }
})

// With options object
ExtendShopify.addPlanToCart({
  plan: plan,
  product: product,
  quantity: 1,
  leadToken: 'lead-token-789'
}, (error) => {
  if (!error) {
    console.log('Warranty added with lead tracking')
  }
})

// Multiple products (bundle)
ExtendShopify.addPlanToCart({
  plan: plan,
  product: product,
  products: [product1, product2, product3],
  quantity: 1
})

warrantyAlreadyInCart

Checks if a warranty plan is already present in the cart for a specific product variant.

Syntax

const isInCart = ExtendShopify.warrantyAlreadyInCart(variantId, cartItems)

Parameters

Parameter Type Required Default Description
variantId string Yes - The product variant ID to check
cartItems CartLineItem[] Yes - Array of cart line items

Returns

Type Description
boolean true if warranty exists in cart, false otherwise

Examples

// Check if warranty exists for a product variant
fetch('/cart.js')
  .then(response => response.json())
  .then(cart => {
    const hasWarranty = ExtendShopify.warrantyAlreadyInCart('variant-456', cart.items)
    
    if (hasWarranty) {
      console.log('Warranty already in cart')
    } else {
      console.log('No warranty found for this variant')
    }
  })

getPlanVariant

Gets the Shopify variant information for an Extend warranty plan.

Syntax

ExtendShopify.getPlanVariant(options, callback)

Parameters

Parameter Type Required Default Description
options GetPlanVariantOptions Yes - Plan variant options
callback function Yes - Callback function with variant data

Callback Parameters

Parameter Type Required Default Description
error Error | null Yes - Error if operation failed
variant PlanVariant No - Plan variant information

Examples

// Get variant for a plan
ExtendShopify.getPlanVariant({
  planId: 'warranty-plan-123',
  price: 2999
}, (error, variant) => {
  if (error) {
    console.error('Failed to get variant:', error)
  } else {
    console.log('Plan variant:', variant)
    console.log('Variant ID:', variant.variantId)
  }
})

handleAddToCart

Enhanced add-to-cart handler that integrates warranty selection with product purchases. This function checks the Extend offer buttons for a selected plan. If a plan is selected, it adds the plan to the cart and executes the callback. If no plan is selected, it can optionally show the Extend offer modal based on the configuration.

Syntax

ExtendShopify.handleAddToCart(element, options)

Parameters

Parameter Type Required Default Description
element string | Element Yes - DOM element or selector
options HandleAddToCartOptions Yes - Configuration options

Examples

// Handle add to cart with warranty integration
ExtendShopify.handleAddToCart('#add-to-cart-button', {
  modal: true,
  quantity: 1,
  done: (error) => {
    if (error) {
      console.error('Add to cart failed:', error)
    } else {
      console.log('Product and warranty added to cart')
    }
  }
})

Type Definitions

HandleAddToCartOptions

Configuration options for the handleAddToCart function.

Property Type Required Default Description
modal boolean No true Whether to show warranty modal if no plan is selected
quantity number No 1 Quantity to add to cart
done function No - Callback function executed after operation completes

GetPlanVariantOptions

Configuration options for the getPlanVariant function. Supports two different query methods depending on the SDK version.

Property Type Required Default Description
planId string No* - Plan identifier (v1 only, required with price)
price number No* - Plan price in cents (v1 only, required with planId)
referenceId string No* - Product reference ID (v2 only, required with termLength)
termLength number No* - Warranty term in months (v2 only, required with referenceId)
premium number No* - Premium amount in cents (v2 only, alternative to referenceId/termLength)
storeId string No - Store identifier (uses Extend SDK config if not provided)
environment string No 'production' Extend environment (‘production’ or ‘demo’)

Note: Either (planId + price) for v1, or (referenceId + termLength) or premium for v2 is required.

PlanSelection

Warranty plan selection object from the Extend SDK.

Property Type Required Description
planId string Yes Unique plan identifier
price number Yes Plan price in cents
term number Yes Warranty term in months
title string Yes Plan title/name
coverageType string Yes Type of coverage (e.g., ‘adh’)

Product

Product information object.

Property Type Required Description
id string Yes Product identifier
name string No Product name

AddToCartOptions

Configuration object for adding plans to cart.

Property Type Required Description
plan PlanSelection Yes The warranty plan to add
product Product Yes The product being protected
products Product[] No Multiple products (for bundles)
quantity number Yes Quantity of warranty plans
leadToken string No Lead tracking token

PlanVariant

Shopify variant information for an Extend warranty plan.

Property Type Required Description
variantId number Yes Shopify variant ID for the plan
price number Yes Plan price in cents
title string Yes Plan title/description