Cart Resource

Cart Resource

This resource is used to interact with the cart functionality.

Methods

Dispatch

Dispatches an action to the cart reducer

Arguments
action
string
(required)
Argument example
"add_variants"
payload
object
(required)
Argument example
[
  {
    variantId: "gid://shopify/ProductVariant/TEST-ID",
    quantity: 1,
  },
]
Examples

      __nylaResources.cart.dispatch({
        type: 'add_variants',
        payload: [
          {
            id: 'gid://Shopify/ProductVariant/test-id',
            sku: 'sku-test',
            price: {
              amount: '10.0',
              currencyCode: 'USD'
            },
            title: 'test variant',
            image: {
              url: 'https://cdn.shopify.com/test-image',
              alt: '',
            };
            product: {
              id: 'gid://Shopify/Product/test-product-id',
              title: 'test product',
              type: 'test product type',
            };
          },
            quantity: 1,
            customAttributes: []
          }
        ]
      })
AddVariant

Adds a variant to the cart

Arguments
event
Event | null | undefined
(required)
quantity
number
(required)
variant
Variant
(required)
Argument example
{
  id: "gid://Shopify/ProductVariant/test-id",
  sku: "sku-test",
  price: {
    amount: "10.0",
    currencyCode: "USD",
  },
  title: "test variant",
  image: {
    url: "https://cdn.shopify.com/test-image",
    alt: "",
  },
  product: {
    id: "gid://Shopify/Product/test-product-id",
    title: "test product",
    type: "test product type",
  },
}
customAttributes
Array<Attribute>
(required)
Argument example
[
  {
    key: "test-attribute-key",
    value: "test-attribute-value",
  },
]
Examples

      __nylaResources.cart.addVariant(null, 1, {
        id: 'gid://Shopify/ProductVariant/test-id',
        sku: 'sku-test',
        price: {
          amount: '10.0',
          currencyCode: 'USD'
        },
        title: 'test variant',
        image: {
          url: 'https://cdn.shopify.com/test-image',
          alt: '',
        };
        product: {
          id: 'gid://Shopify/Product/test-product-id',
          title: 'test product',
          type: 'test product type',
        };
      }, [{
        key: 'test-attribute-key',
        value: 'test-attribute-value'
      }])
ToggleCart

Opens/Closes the cart

Arguments
status
string
(required)
Examples
__nylaResources.cart.toggleCart('open')