window.miam
The window.miam object still has a lot more methods and attributes that can make a big difference for customizing your experience. Some of them will not be useful to you right off the bat, but can be at some point.
Except for the methods mentioned in Set up and usage, none of the methods listed in this section are necessary if the basic implementation is good enough for you. But if you want or need more customization, you may need to call some of those methods.
window.miam.analytics
eventSent$: Observable<string>Each time Mealz sends an analytics event, it emits its content as a stringified JSON of the following format:
{
name: 'eventName',
path: 'https://www.yourdomain.com/thepath',
props: {aString: 'foo bar', aNumber: 5}
}
init: (domain: string, optimizeKey: string) => voidInitialises the analyticswarningDeprecated, prefer using
supplier.setupWithTokenas it initialises the analytics
window.miam.basket
-
basketIsReady$: Observable<boolean>: Emits true when Mealz's basket has successfully loaded for the first time. Does not emit anything before or after that. -
initialize: () => void: Fetch the first Basket early (before any action requires it on Mealz's side), so you can start the basket-sync earlier -
reset: () => void: Resets Mealz' basket : empties all products & recipes added by the user.infoWe recommend that you use
basket.reset()when the user empties their cart on your website, to avoid the recipes being kept in a "in-basket" state but with no products and displayed at a price of 0.Outside of this usage we don't recommand using
basket.reset()except to quickly empty Mealz's basket for testing purposes -
updatePricebook: (pricebookName: string) => Observable<void>: If you have different price tables (or pricebooks) for the same point of sale, you can call this method to let Mealz know which pricebook you are using. For example, prices could be different depending on if the user chose home delivery or drive-ininfoIf you have different pricebooks, they need to have been sent to our API so you can change them with
basket.updatePricebook(). The pricebookName should be the same that the one sent to our API -
recipeCount: () => Observable<number>: A BehaviorSubject that emits the current number of recipes in Mealz' Basket once (it waits for the Basket to be initialized to emit). -
openPreview: () => void: Opens the recipe-modal in basket preview mode to display the recipes currently in the basket (Same action as when clicking on the FAB in the recipe-catalog)
window.miam.basketSync
definePushProductsToBasket: (pushProductsToBasket: (products: ComparableProduct[]) => void) => void: The callback parameter is called when Mealz's basket changes to update the user's cart accordinglynotepushProductsToBasket: a method that updates the user's cart with the products passed in a parameter: it adds products if their quantity is positive, and removes them if their quantity is negativeretailerBasketChanged: (comparableProducts: ComparableProduct[]) => void: Call to notify Mealz that the user's cart has been updatednotecomparableProducts: The products in the user's carthandlePayment: (total: number) => void: Call to notify Mealz that the user's cart was paid. Mealz then refreshes the groceries-list and basket for the next user's cartnotetotal: The total price of the cart paid