Skip to content

Utilities

@fingermarkglobal/cart contains many utility functions for handling different events and parts of the cart lifecylce.

Below is the current list of all utility functions with why and where they are used.

Format

format is used to transform the hydrated menu products into actionable, formatted cart products.

format is the first event that occurs when an item is staged into the cart.

Evaluate

evaluate is run on every update of the cart. evaluate goes through all customisations, combo options etc and evaluates and calculates information like pricing and counts.

Reformat

reformat is used to exchange updaters functions from 1 atom to another. This is because format usually takes the update function for the cart atom, while some items need to use the secondaryCart updater.

Replace

replace is a find function that can traverse the cart item (through customisations and combo option products) to find a matching uid. It then returns the entire original product tree with the found item being replaced by the product argument

Update

update is a curried function that takes a state updater and creates a function that can find products by uid, and replace them.

update is the primary way that cart items can handle their own internal state through actions like add and remove due to these handlers having access to their own state setter.

Scale

scale is a function that receives the hydrated combo product, the currently selected size/filter of it and the size which it should scale to.

scale identify the product size/filter to scale into, creates a temporary cart state to store that 'new' product, than identify the side products and customisations present on original selected size, and if they exist on new one, pass it forward to it. After this process, it replaces the original product on cart for the 'new' one, maintaing the original uid, sides and customisations when possible or needed.

scale is a feature defauted to false, and this can be controlled on dashboard configuration.

Stack

stack is used to find items that are exactly the same (in both customisations, and combo selections), and stack them together and increase their count.

Trim

trim is used to trim unecessary information and format cart products into API usable objects.

Destruct

destruct is used to remove all unccessary customisation and combo product items that arent selected (as all options are also available in cart items).