Chord OMS
...
Gatsby
SDK Reference
useCart
13min
the usecart hook returns a series of methods for interacting with the shopify shopping cart import { usecart } from '@chordcommerce/gatsby theme performance' const { cart, addpromocode, addtocart, applygiftcard, checkout, loadcart, modifyquantity, removefromcart, removegiftcard, removepromocode } = usecart() cart represents the current shopping cart example const { cart } = usecart() addpromocode() applies a promo code to the current order example const promocode = '50off' await addpromocode(promocode) addtocart() adds an item to the current order example const variantid = '123' const quantity = 1 await addtocart(variantid, quantity) applygiftcard() applies a gift card to the current order example const giftcardcode = 'xxxyyyzzz' await applygiftcard(giftcardcode) checkout() redirects the browser to shopify checkout example await checkout() loadcart() reloads the current shopping cart this is automatically called on every page load and with every other usecart method example await loadcart() modifyquantity() updates the quantity of a line item in the current order example const lineitemid = '123' const quantity = 2 await modifyquantity(lineitemid, quantity) modifylineitem() updates a line item in the current order example const lineitemid = '123' // update line item quantity await modifyquantity(lineitemid, { quantity 2, }) // update line item customattributes await modifyquantity(lineitemid, { customattributes \[ { key 'est shipping date', value 'march 24, 2022', } ], }) removefromcart() removes a line item from the current order example const lineitemid = '123' await removefromcart(lineitemid) removegiftcard() removes a gift card from the current order example const giftcardcode = 'xxxyyyzzz' await removegiftcard(giftcardcode) removepromocode() removes a promo code from the current order example const promocode = '50off' await removepromocode(promocode)