What is a Function?

Functions is the secret sauce of Ollie Shop. Is where the magic happens.

All Functions run server-side guaranteeing security and maximum performance.

Use functions to run the business logic of the customization. Make requests to external systems, transform payloads, go crazy.

How to trigger a Function?

Functions are based on Events, each function is configured to be triggered by one of the following events:

  • cart: This trigger is fired every time that the request Get Cart by ID Get cart by Id is made
  • items: This trigger is fired when there is a change on the items of the cart done by these requests:
  • customer: This trigger is fired every time that the request Update Customer Update customer is made
  • shipping: This trigger is fired every time that the request Update Shipping Update shipping is made
  • delivery: This trigger is fired every time that the request Update Delivery Update delivery is made
  • payment: This trigger is fired every time that the request Update Payment Update payment is made
  • extension: This trigger is fired every time that the request Update Extensions Update extensions is made

Invocation before/after of a Function

In the configuration of your Function you can define the invocation parameter, which is how to determine when the function should run: before or after.

There are various occasions that you might wish to run a function before actually sending the information to your ecommerce provider.

For example, if you want to limit the quantity of the same SKU being added to the cart. You'll want to have this validation happen before actually adding the product to the cart.

In the example above, you want to validate the maximum quantity of items allowed for the SKU being added, so you'll configure the function to be triggered by the items event (when the Add Items API is used), and the function to run before, meaning that if the quantity exceeds the limit, your function will abort and your Add Items request will not make it to the ecommerce provider. This feature saves you the extra request of having to remove the item from the cart.

An example of a function that you would like to run after can be a function that hides certain Payment Methods given the new total value of the cart.

Handling Errors

A function can be configured to throw when an error happens, or skip. This means you can decide if you want a function to abort the operation and throw a 4xx error, or continue without raising any events.

When you decide to show an error in the function, you can use the Ollie SDK's Reject function to return a 422 error.

Using REST API


What are the minimum requirements to create a Function?

Functions follow the same pattern as Components. Your function will have a:

  • typescript file
  • package.json
  • and the node_modules

Functions don't require a css file


How to upload a Function to my store?

Use the Ollie Builder API to upload the function to your store. You'll need the ID of the function and to compress the folder as a zip file.

FunctionId is a Path Variable

Compress your file (.zip) for upload

After receiving the files, the API validates the files and compiles the code, transforming them into a valid Javascript code.


What’s Next

Learn more about how to create multiple checkout journeys with Versions