The Jumpseller Javascript library is included by default into every theme on every store.
If you are not confident about what this is about get an overview on Design for Jumpseller.

Using this library involves a solid understanding of Javascript.
If you are not a web-designer consider hiring a recommend expert.

Methods

isDefined

  • isDefined: function(param)
  • checks whether a variable is defined in the current Javascript scope or not.
  • param is the name of the variable/method to be checked.
  • returns a Boolean value.

requiredAttributesChecker

  • requiredAttributesChecker: function(selectors, options)
  • checks whether the options object has a callback key defined and if selectors is a valid jQuery selector string that only includes valid DOM objects with the change event (select & radio).
  • selectors is the jQuery selectors string.
  • options is the Javascript object.
  • returns a Boolean value.

paymentMethodListener

depends on requiredAttributesChecker

  • paymentMethodListener: function(paymentMethodSelector, options)
  • applies the onchange event to the paymentMethodSelector and calls the options.callback method when defined.
  • paymentMethodSelector is a jQuery selector string.
  • options is the Javascript object.
  • calls the callback method defined in the options object. If it fails, returns the Boolean value false.

countryListener

depends on requiredAttributesChecker & isDefined

  • countryListener: function(countriesSelector, options)
  • applies the onchange event to the countriesSelector and calls the options.callback method when defined.
  • countriesSelector is a jQuery selector string.
  • options is the Javascript object.
  • calls the callback method defined in the options object. If it fails, returns the Boolean value false.

  • options.updateRegions is a Boolean value which defaults to false. Otherwise, it will signal the platform to update the Regions' <select> HTML element. The method will call and depend on getRegions.

  • options.regionsSelector is a String value which defaults to countriesSelector.replace('country','region');. Otherwise, it should be a string referring to the Regions' <select> HTML element.

regionListener

depends on requiredAttributesChecker & isDefined

  • regionListener: function(regionsSelector, options)
  • applies the onchange event to the regionsSelector and calls the options.callback method when defined.
  • regionsSelector is a jQuery selector string.
  • options is the Javascript object.
  • calls the callback method defined in the options object. If it fails, returns the Boolean value false.

  • options.updateComunas is a Boolean value which defaults to false. Otherwise, it will signal the platform to update the Comunas' <select> HTML element. The method will call and depend on getComunas.

  • options.ComunasSelector is a String value which defaults to regionsSelector.replace('region','comuna');. Otherwise, it should be a string referring to the Comunas' <select> HTML element.

productVariantListener

depends on requiredAttributesChecker & updateProductInfo

  • productVariantListener: function(variantSelectors, options)
  • applies the onchange event to the variantSelectors and calls the updateProductInfo method.
  • variantSelectors is a jQuery selector string.
  • options is the Javascript object.
  • calls the callback method defined in the options object. If it fails, returns the Boolean value false.

getRegions

  • getRegions: function(regionSelectID, countryCode, selectedRegion)
  • removes all options from the $(regionSelectID) HTML element and fills it with the result from an AJAX call to '/checkout/regions?country=' + countryCode, selecting the selectedRegion if available in the list.
  • regionSelectID is a jQuery selector string.
  • countryCode is the 2-letter ISO code for the selected Country.
  • selectedRegion is the code for the selected Region.
  • the Region <select> HTML element will be hidden if no item is returned in the AJAX call.

getComunas

  • getComunas: function(comunaSelectID, regionCode, selectedComuna)
  • removes all options from the $(comunaSelectID) HTML element and fills it with the result from an AJAX call to '/checkout/comunas?region=' + regionCode, selecting the selectedComuna if available in the list.
  • comunaSelectID is a jQuery selector string.
  • regionCode is the code for the selected Region.
  • selectedComuna is the code for the selected Comuna.
  • the Comuna <select> HTML element will be hidden if no item is returned in the AJAX call.

updateProductInfo

depends on isDefined

  • updateProductInfo: function(event, variantSelectors, options)
  • retrieves all selected values from the $(variantSelectors) HTML elements, and calls the options.callback method when defined, with the browser's event and the Product Variant information as arguments.
  • event the HTML element event, will be passed as an argument to the callback method.
  • variantSelectors is a jQuery selector string.
  • options is the Javascript object.
  • options.product is the JSON data for the current product
  • calls the callback method defined in the options object. If it fails, returns the Boolean value false.

setCurrency

  • setCurrency function(currency)
  • saves the newly provided currency code as a variable named global_currency in the browser's sessionStorage and reloads the page
  • currency is the 3-letter ISO code for the desired Currency

multiCurrency

depends on isDefined

  • multiCurrency function(options)
  • activates the multi Currency selection in the store, and calls the options.callback method when defined. Exchange Rates are provided Open Exchange Rates.
  • options is a Javascript object.
  • options.token Open Exchange Rates API token, required to use multi Currency in a Jumpseller store
  • to avoid rate limits from Opem Exchange Rates API, the currency rates are saved in localStorage for every user, and renewed every 24h.

getCart

  • getCart function(options)
  • calls the method GET /api/cart.json of the Javascript API.
  • returns the JSON representation of the current cart in session.

To get the cart's total amount:

<script type="text/javascript">
  var callbackFunction = function(data){ console.log(data.total); }; // outputs the cart's total amount.
  Jumpseller.getCart({callback: callbackFunction})
</script>

updateCart

  • updateCart function(order_product_id, qty, options)
  • calls the method POST /api/cart.json of the Javascript API.
  • updates the quantity of the given product at the order.
  • returns the JSON representation of the current cart in session.

clearCart

  • clearCart function(options)
  • calls the method DELETE /api/cart.json of the Javascript API.
  • resets all cart values to zero and removes all products from the cart.
  • returns the JSON representation of the current empty cart in session.

addProductToCart

  • addProductToCart function(product_id, qty, product_options, options)
  • calls the method POST /api/cart/add.json of the Javascript API.
  • adds a simple product (with product_options = nil) or a product with variants to the cart.
  • returns the JSON representation of the current cart in session.

To add a variant of the product with the ID 12345 to the cart use:

Jumpseller.addProductToCart(12345, 1, { "Color": 123123, "Size": 321321, "Name": 'Mourinho' }, {callback: callbackFunction})

Note: Options 'Color' and 'Size' are of the Type Option and the option 'Name' is of the type Text Input.

To represent a callback function use:

<script type="text/javascript">
  var callbackFunction = function(data){
    console.log(data);
  };
</script>

addCouponToCart

  • addCouponToCart function(code, options)
  • calls the method POST /api/cart/coupon.json of the Javascript API.
  • adds a coupon code to the order in the cart. If successfull, discount will be aplied to the order.
  • returns the JSON representation of the current cart in session.