Creating a new ShopifyPermalink

When constructing a new ShopifyPermalink object, it accepts four parameters:

const Permalink = new ShopifyPermalink(shopURL, items, options, selectors);
PropertyValue
shopURL{String} Required The fully qualified myshopify.com domain that points to your Shopify checkout (i.g. https://example-brand.myshopify.com).
items{Array} Required This should be a pointer to the cart items array. Optionally, this property can be set before navigating to checkout (i.g. Permalink.items = getYourItems()).
options{Object} Optional This is an optional settings object, which allows you to set a discount code, email, address, shipping address, cart note, ref, cart attributes, or storefront access token (i.e. sales channel).
selectors{Object} Optional This is an optional selectors object, which has two keys 'variant_id' and 'quantity', which are used to select the variant ID and quantity values from the items array. The default values are 'id' and 'quantity' respectively.

setOptions(key, value)

The setOptions method will set the permalink's options with the provided value. You can pass an {Object} in as the first argument to merge the provided options object with the existing object. If an object is passed as the first argument, the value argument is ignored.

Alternatively, individual options key/values can be assigned by passing in a string as the first argument, and a string as the second argument. If a string is used, it can be in dot notation such as 'shipping_address.first_name' to set options.shipping_address.first_name to the provided value.

PropertyValue
key{String} Required If a string is passed, the value will be used as the option key and the value argument will be assigned. String values in dot notation are also supported such as shipping_address.first_name.

-- OR --

{Object} Required If an object is passed, the options object will be merged on to the existing options object, overwriting an previous values.
value{String} Required This value will be assigned to the provided key. If an {Object} was passed as the key argument, the value argument will be ignored.

Supported key values are: discount, email, shipping_address, attributes, note, ref.

url()

The url method will return either an empty string if not items are in the cart, or the fully qualified Shopify checkout permalink using all available option arguments.

go()

The go method will redirect the user to the fully qualified Shopify checkout permalink. If no items are in the cart, it will stay onsite and log a warning message to the console.