Interfaces
Interface: UseCart
module react autonomy docid\ zoz6w56ubppacr0po0gls usecart usecart contains the data and methods returned by the function usecart docid\ kgn9cl0x0uu5x8r67i xu hook hierarchy omit < rootinitialstate \[ "cart" ], "data" > ↳ properties addcrosssell • addcrosssell ( options interface crosssell docid\ yuck1z8zia3cfjl4u9gyj ) => promise < interface orderbig docid\ dviaog1oicyzdwppppgmo > type declaration ▸ ( options ) promise < interface orderbig docid\ dviaog1oicyzdwppppgmo > the addcrosssell function takes an array of line items post checkout and adds them to the order, charging the card again in the process import { usecart } from '@chordcommerce/react autonomy' const crosssellcheckoutbutton = ({ orderid, ordertoken, lineitemsattributes }) => { const { addcrosssell } = usecart() const purchasecrosssells = async () => addcrosssell({ lineitemsattributes, cart { number orderid, token ordertoken, }, }) return \<button onclick={purchasecrosssells}>buy\</button> } parameters name type options interface crosssell docid\ yuck1z8zia3cfjl4u9gyj returns promise < interface orderbig docid\ dviaog1oicyzdwppppgmo > defined in packages/react autonomy/src/hooks/use cart ts 154 https //github com/chordcommerce/chord ui/blob/2b105e1/packages/react autonomy/src/hooks/use cart ts#l154 addpromocode • addpromocode ( options type alias addpromocode docid\ t7o8q0ljlg16jm9oiddn ) => promise < interface orderbig docid\ dviaog1oicyzdwppppgmo > type declaration ▸ ( options ) promise < interface orderbig docid\ dviaog1oicyzdwppppgmo > the addpromocode function applies a promo code to the current shopping cart import { usecart } from '@chordcommerce/react autonomy' const promocodeform = () => { const { cart, addpromocode } = usecart() const onsubmit = async ({ promocode }) => { try { await addpromocode(promocode) } catch(error) { console error('error applying promo code ') } } } parameters name type options type alias addpromocode docid\ t7o8q0ljlg16jm9oiddn returns promise < interface orderbig docid\ dviaog1oicyzdwppppgmo > defined in packages/react autonomy/src/hooks/use cart ts 176 https //github com/chordcommerce/chord ui/blob/2b105e1/packages/react autonomy/src/hooks/use cart ts#l176 addsubscription • addsubscription ( subscription type alias addsubscriptionitem docid\ ayiz8vvyhliize23ra i6 ) => promise < interface orderbig docid\ dviaog1oicyzdwppppgmo > type declaration ▸ ( subscription ) promise < interface orderbig docid\ dviaog1oicyzdwppppgmo > the addsubscription function adds a subscription item to the customer's cart import { usecart } from '@chordcommerce/react autonomy' const addsubscriptiontocartbutton = ({ sku, quantity, enddate, intervalunit, intervallength, }) => { const { addsubscription } = usecart() const addtocart = async () => addsubscription({ sku, quantity, enddate, interval { length intervallength, unit intervalunit, }, }) return \<button onclick={addtocart}>add to cart\</button> } parameters name type subscription type alias addsubscriptionitem docid\ ayiz8vvyhliize23ra i6 returns promise < interface orderbig docid\ dviaog1oicyzdwppppgmo > defined in packages/react autonomy/src/hooks/use cart ts 209 https //github com/chordcommerce/chord ui/blob/2b105e1/packages/react autonomy/src/hooks/use cart ts#l209 addtocart • addtocart ( items type alias addtocartitem docid\ ssshurop mkafs9 tktzs | type alias addtocartitem docid\ ssshurop mkafs9 tktzs \[]) => promise < interface orderbig docid\ dviaog1oicyzdwppppgmo > type declaration ▸ ( items ) promise < interface orderbig docid\ dviaog1oicyzdwppppgmo > the addtocart function adds a product variant to the current shopping cart (creating a line item) import { usecart } from '@chordcommerce/react autonomy' export default () => { const { addtocart } = usecart() const onsubmit = ({ sku, quantity }) => { addtocart({ sku, quantity, metadata { brand 'the plant store', } }) } } parameters name type description items type alias addtocartitem docid\ ssshurop mkafs9 tktzs | type alias addtocartitem docid\ ssshurop mkafs9 tktzs \[] the items to add to the cart returns promise < interface orderbig docid\ dviaog1oicyzdwppppgmo > a promise that resolves once the items are added to the cart defined in packages/react autonomy/src/hooks/use cart ts 235 https //github com/chordcommerce/chord ui/blob/2b105e1/packages/react autonomy/src/hooks/use cart ts#l235 cart • cart partial < interface orderbig docid\ dviaog1oicyzdwppppgmo > an object representing the current shopping cart defined in packages/react autonomy/src/hooks/use cart ts 129 https //github com/chordcommerce/chord ui/blob/2b105e1/packages/react autonomy/src/hooks/use cart ts#l129 checkredemptioncodevalidity • checkredemptioncodevalidity ( code string , email string ) => promise < interface orderbig docid\ dviaog1oicyzdwppppgmo > type declaration ▸ ( code , email ) promise < interface orderbig docid\ dviaog1oicyzdwppppgmo > the checkredemptioncodevalidity function checks the validity of a gift card redemption code or prepaid subscription redemption code it does not require the customer to be logged in it will return the order the redemption code is valid for such that a redemption code form can be filled in or products can be displayed dynamically import { usecart } from '@chordcommerce/react autonomy' const redemptioncodeform = () => { const { checkredemptioncodevalidity } = usecart() const params = new urlsearchparams(window\ location search) const code = params get('code') const { data order, error } = useasynceffect(() => { return checkredemptioncodevalidity(code) }, \[checkredemptioncodevalidity, code]) if (error) { return \<p>invalid redemption code \</p> } return \<items items={order lineitems} /> } parameters name type code string email string returns promise < interface orderbig docid\ dviaog1oicyzdwppppgmo > a promise that resolves with the order the redemption code is valid for defined in packages/react autonomy/src/hooks/use cart ts 268 https //github com/chordcommerce/chord ui/blob/2b105e1/packages/react autonomy/src/hooks/use cart ts#l268 emptycart • emptycart () => promise < interface orderbig docid\ dviaog1oicyzdwppppgmo > type declaration ▸ () promise < interface orderbig docid\ dviaog1oicyzdwppppgmo > the emptycart function clears the customer's cart contents (line items, promo codes, metadata) while keeping the same order number returns promise < interface orderbig docid\ dviaog1oicyzdwppppgmo > defined in packages/react autonomy/src/hooks/use cart ts 276 https //github com/chordcommerce/chord ui/blob/2b105e1/packages/react autonomy/src/hooks/use cart ts#l276 error • error error inherited from omit error defined in packages/react autonomy/src/redux/store/initial state ts 59 https //github com/chordcommerce/chord ui/blob/2b105e1/packages/react autonomy/src/redux/store/initial state ts#l59 forgetcart • forgetcart () => { type string = forget cart } type declaration ▸ () object the forgetcart function clears the customer's cart returns object name type type string defined in packages/react autonomy/src/hooks/use cart ts 280 https //github com/chordcommerce/chord ui/blob/2b105e1/packages/react autonomy/src/hooks/use cart ts#l280 isfetching • isfetching boolean inherited from omit isfetching defined in packages/react autonomy/src/redux/store/initial state ts 57 https //github com/chordcommerce/chord ui/blob/2b105e1/packages/react autonomy/src/redux/store/initial state ts#l57 isloaded • isloaded boolean inherited from omit isloaded defined in packages/react autonomy/src/redux/store/initial state ts 58 https //github com/chordcommerce/chord ui/blob/2b105e1/packages/react autonomy/src/redux/store/initial state ts#l58 loadcart • loadcart () => promise < interface orderbig docid\ dviaog1oicyzdwppppgmo > type declaration ▸ () promise < interface orderbig docid\ dviaog1oicyzdwppppgmo > the loadcart function loads the current cart based on the current browser session and populates the cart in redux loadcart is automatically called on page load so this should not be called except in exceptional circumstances import { usecart } from '@chordcommerce/react autonomy' export default () => { const { cart, loadcart } = usecart() useeffect(() => { loadcart() catch(error => { console error(error message) }) }, \[loadcart]) } returns promise < interface orderbig docid\ dviaog1oicyzdwppppgmo > a promise that resolves when the cart object has been added to redux defined in packages/react autonomy/src/hooks/use cart ts 304 https //github com/chordcommerce/chord ui/blob/2b105e1/packages/react autonomy/src/hooks/use cart ts#l304 modifycart • modifycart ( options interface modifycart docid\ bvt0tqygo4xw0en6upcul ) => promise < interface orderbig docid\ dviaog1oicyzdwppppgmo > type declaration ▸ ( options ) promise < interface orderbig docid\ dviaog1oicyzdwppppgmo > the modifycart function modifies the current cart it sends it's payload to the chord oms update order endpoint https //chord stoplight io/docs/chord oms/b3a6mte3nzk0mjk update order parameters name type options interface modifycart docid\ bvt0tqygo4xw0en6upcul returns promise < interface orderbig docid\ dviaog1oicyzdwppppgmo > a promise that resolves when the cart object has been updated in redux defined in packages/react autonomy/src/hooks/use cart ts 312 https //github com/chordcommerce/chord ui/blob/2b105e1/packages/react autonomy/src/hooks/use cart ts#l312 modifygiftcards • modifygiftcards ( options interface giftcardsinput docid\ bm82cy wbhfzzpyrnbq1v ) => promise < interface orderbig docid\ dviaog1oicyzdwppppgmo > type declaration ▸ ( options ) promise < interface orderbig docid\ dviaog1oicyzdwppppgmo > the modifygiftcards function applies or removes gift cards from the current cart the giftcardsdetails object is returned in the lineitem object if the lineitem is a gift card additionally, newly redeemed gift cards are available in the user object for indicating to the user that they have received a gift the gift cards can be updated by including the gift card id along with any of the following params recipientname, recipientemail, giftmessage, purchasername, sendemailat the recipient email is a required field as that will be the account used to redeem the gift cards import { usecart } from '@chordcommerce/react autonomy' export default () => { const { modifygiftcards } = usecart() const onsubmit = (event) => { modifygiftcards({ giftcardsdetails \[ { recipientemail "test\@chord co", giftmessage "hi!", sendemailat "2021 11 15", id "49" }, { recipientemail "admin\@chord co", giftmessage "", sendemailat "2021 11 16", id "50" } ] }) } } parameters name type options interface giftcardsinput docid\ bm82cy wbhfzzpyrnbq1v returns promise < interface orderbig docid\ dviaog1oicyzdwppppgmo > a promise that resolves when the cart object has been updated in redux defined in packages/react autonomy/src/hooks/use cart ts 364 https //github com/chordcommerce/chord ui/blob/2b105e1/packages/react autonomy/src/hooks/use cart ts#l364 modifylineitem • modifylineitem ( options interface modifylineitem docid\ khciw54vt64 voasfoeq ) => promise < interface orderbig docid\ dviaog1oicyzdwppppgmo > type declaration ▸ ( options ) promise < interface orderbig docid\ dviaog1oicyzdwppppgmo > the modifylineitem function updates a line item in the customer's cart it calls chord oms's update order line item endpoint https //chord stoplight io/docs/chord oms/5ca7631abac5c update order line item parameters name type options interface modifylineitem docid\ khciw54vt64 voasfoeq returns promise < interface orderbig docid\ dviaog1oicyzdwppppgmo > a promise that resolves when the cart has been updated in redux defined in packages/react autonomy/src/hooks/use cart ts 319 https //github com/chordcommerce/chord ui/blob/2b105e1/packages/react autonomy/src/hooks/use cart ts#l319 promocode • promocode object type declaration name type isfetching boolean inherited from omit promocode defined in packages/react autonomy/src/redux/store/initial state ts 60 https //github com/chordcommerce/chord ui/blob/2b105e1/packages/react autonomy/src/redux/store/initial state ts#l60 purchaseprepaidsubscription • purchaseprepaidsubscription ( input interface purchaseprepaidsubscription docid\ iwxufve0me2ffq0ux3z1x ) => promise < interface orderbig docid\ dviaog1oicyzdwppppgmo > type declaration ▸ ( input ) promise < interface orderbig docid\ dviaog1oicyzdwppppgmo > the purchaseprepaidsubscription function allows the customer to purchase a prepaid/gift subscription the process is the caller provides a input of skus, quantities, installments, delivery frequency and shipping address and is returned an order that is outside of react autonomy's state management ready to direct the customer straight to checkout you should pass order checkoutsessionid to your checkout provider to direct the customer to the next step this example is using stripe for the checkout it will allow the user to purchase a yearlog gift subscription for someone else import { usecart } from '@chordcommerce/react autonomy' // make sure to call loadstripe outside of a component’s render to avoid // recreating the stripe object on every render const stripepromise = loadstripe(process env stripe pk key, { stripeaccount process env stripe connected account }) const giftsubscriptionbutton = ({ address }) => { const { purchaseprepaidsubscription } = usecart() const onclick = () => { const stripe = await stripepromise const order = await purchaseprepaidsubscription({ sku 'flower club subscription', quantity 1, options { prepaidsubscription { installmentcount 12, interval { units 'month', length 1, }, lineitems \[{ sku 'flower club subscription', quantity 1, }], autoredeem true, actionabledate new date(), gift true, recipient { name address name, email 'help\@chord co', }, shipaddress address, } } }) stripe redirecttocheckout({ checkoutsessionid order checkoutsessionid, }) } return \<button onclick={onclick}>buy now!\</button> } parameters name type input interface purchaseprepaidsubscription docid\ iwxufve0me2ffq0ux3z1x returns promise < interface orderbig docid\ dviaog1oicyzdwppppgmo > a promise containing a new order with just the subscription in it you should pass it's checkoutsessionid to your checkout provider defined in packages/react autonomy/src/hooks/use cart ts 429 https //github com/chordcommerce/chord ui/blob/2b105e1/packages/react autonomy/src/hooks/use cart ts#l429 redeemgiftcard • redeemgiftcard ( code string , email string ) => promise < interface giftcardredemption docid\ waemxxaywq2df eatouyb > type declaration ▸ ( code , email ) promise < interface giftcardredemption docid\ waemxxaywq2df eatouyb > the redeemgiftcard function redeems a gift card to the account matching the email provided during the initial purchase it does not require the user to be logged in import { usecart } from '@chordcommerce/react autonomy' const redemptionform = () => { const { redeemgiftcard } = usecart() const submithandler = async (e) => { const code = event target code await redeemgiftcard(code) } return ( \<form onsubmit={submithandler}> \<label> \<span>enter redemption code\</span> \<input type="text" name="code" /> \</label> \</form> ) } parameters name type code string email string returns promise < interface giftcardredemption docid\ waemxxaywq2df eatouyb > defined in packages/react autonomy/src/hooks/use cart ts 461 https //github com/chordcommerce/chord ui/blob/2b105e1/packages/react autonomy/src/hooks/use cart ts#l461 redeemprepaidsubscription • redeemprepaidsubscription ( payload interface redeemprepaidsubscriptioninput docid\ qppzzecchprqjif7g7v t ) => promise < interface giftcardredemption docid\ waemxxaywq2df eatouyb > type declaration ▸ ( payload ) promise < interface giftcardredemption docid\ waemxxaywq2df eatouyb > the redeemprepaidsubscription function redeems a prepaid subscription to the account matching the email provided during the initial purchase it does not require the user to be logged in import { usecart } from '@chordcommerce/react autonomy' const redemptionform = () => { const { redeemprepaidsubscription } = usecart() const submithandler = async (e) => { const { redemptioncode shipaddress } = object fromentries(new formdata(event target)) await redeemgiftcard({ redemptioncode, shipaddress, }) } return ( \<form onsubmit={submithandler}> \<label> \<span>enter redemption code\</span> \<input type="text" name="redemptioncode" /> \</label> \<addressinputs /> \</form> ) } parameters name type payload interface redeemprepaidsubscriptioninput docid\ qppzzecchprqjif7g7v t returns promise < interface giftcardredemption docid\ waemxxaywq2df eatouyb > defined in packages/react autonomy/src/hooks/use cart ts 495 https //github com/chordcommerce/chord ui/blob/2b105e1/packages/react autonomy/src/hooks/use cart ts#l495 removefromcart • removefromcart ( options interface removefromcart docid\ iz4vkiklkv8kzgrpwfgza ) => promise < interface orderbig docid\ dviaog1oicyzdwppppgmo > type declaration ▸ ( options ) promise < interface orderbig docid\ dviaog1oicyzdwppppgmo > the removefromcart function removes a line item from the cart parameters name type options interface removefromcart docid\ iz4vkiklkv8kzgrpwfgza returns promise < interface orderbig docid\ dviaog1oicyzdwppppgmo > a promise that resolves when the cart object has been updated in redux defined in packages/react autonomy/src/hooks/use cart ts 504 https //github com/chordcommerce/chord ui/blob/2b105e1/packages/react autonomy/src/hooks/use cart ts#l504 removepromocode • removepromocode ( options interface removepromocode docid\ shnt0qkmsymt06squhxfc ) => promise < interface orderbig docid\ dviaog1oicyzdwppppgmo > type declaration ▸ ( options ) promise < interface orderbig docid\ dviaog1oicyzdwppppgmo > the removepromocode function removes an applied promo code from the cart parameters name type options interface removepromocode docid\ shnt0qkmsymt06squhxfc returns promise < interface orderbig docid\ dviaog1oicyzdwppppgmo > a promise that resolves when the cart object has been updated in redux defined in packages/react autonomy/src/hooks/use cart ts 511 https //github com/chordcommerce/chord ui/blob/2b105e1/packages/react autonomy/src/hooks/use cart ts#l511