Richer
What is it?
This library is built on top of slater (which is a fork of shopify slate). It is based on the old implementation of the Timber depreciated richcart. The idea behind this comes from Slate and Timber both being tied to jQuery and wanting to build something that could be used independent of that.
Using It
We use richer to handle API requests to the shopify AJAX cart. How you implement it is entirely up to you. We expose a couple of common routes that allow you to easily handle updating/refreshing/generating your ajax cart.
I'll outline a number of examples in YOYO below
Initialize a cart
// Some DOM defaultsconst defaults = addToCart: '.js-add-to-cart' // classname addToCartForm: 'AddToCartForm' // id cartContainer: 'CartContainer' // id cartCounter: 'CartCounter' // id items: const config = Object const dom = addToCartForm: document cartContainer: document cartCounter: document RicherAPI // Updates a cart number and builds our cartconst cartUpdateCallback = { } const updateCount = { const counter = domcartCounter counterinnerHTML = cartitem_count} const buildCart = { const cartContainer = domcartContainer cartContainerinnerHTML = null if cartitem_count === 0 cartContainerinnerHTML = `We're sorry your cart is empty` return var el = { return yo` <div class='r-cart'> </div> ` } { // TODO: handling discounts const totalPrice = slateCurrency // eslint-disable-line return yo` <div> <h5>Subtotal: </h5> </div> ` } { if discountsApplied return yo` <div> <small className='strike'></small> <br /><span></span> </div> ` else return yo` <span></span> ` } { RicherAPI } { let newCart = yo } cartContainer}
const dom = addToCartForm: document const AddToCart = { const form = domaddToCartForm form const itemAddedCallback = { RicherAPI } const itemErrorCallback = { console }} const cartUpdateCallback = { RicherAPI}
MIT License