These hooks give your components access to live checkout data and the ability to modify the checkout experience. All hooks are TypeScript-ready with full type definitions.
Quick Reference
useCheckoutSession Access cart data, customer info, and modify cart contents
useStoreInfo Store configuration, theme, and branding data
useCheckoutSession Ecommerce Provider Data, Ollie Data, session validation
useCheckoutSession
The primary hook for accessing and modifying checkout data.
📊 Cart Data
👤 Customer Data
🛠️ Cart Actions
Access cart contents and totals import { useCheckoutAction } from '@ollie-shop/sdk' ;
function CartDisplay () {
const { cart } = useCheckoutSession ();
return (
< div >
< h3 > Cart Summary </ h3 >
< p > Items: { cart . items . length } </ p >
< p > Subtotal: $ { ( cart . subtotal / 100 ). toFixed ( 2 ) } </ p >
< p > Shipping: $ { ( cart . shipping / 100 ). toFixed ( 2 ) } </ p >
< p > Tax: $ { ( cart . tax / 100 ). toFixed ( 2 ) } </ p >
< p > Total: $ { ( cart . total / 100 ). toFixed ( 2 ) } </ p >
{ cart . items . map ( item => (
< div key = { item . id } >
{ item . name } - Qty: { item . quantity } - $ { ( item . price / 100 ). toFixed ( 2 ) }
</ div >
)) }
</ div >
);
}
Cart Properties: Property Type Description itemsCartItem[]Array of products in cart totalnumberTotal amount in cents subtotalnumberSubtotal before shipping/tax shippingnumberShipping cost in cents taxnumberTax amount in cents discountnumberTotal discount amount currencystringCurrency code (USD, EUR, etc.)
CartItem Properties: Property Type Description idstringUnique product identifier namestringProduct name pricenumberPrice per unit in cents quantitynumberQuantity in cart imagestringProduct image URL categorystringProduct category skustringStock keeping unit
Access customer information import { useCheckoutSession } from '@ollie-shop/sdk' ;
function CustomerInfo () {
const { customer } = useCheckoutSession ();
return (
< div >
{ customer . isLoggedIn ? (
< div >
< h3 > Welcome back, { customer . name } ! </ h3 >
< p > Email: { customer . email } </ p >
< p > Member since: { customer . memberSince } </ p >
{ customer . tier === 'vip' && (
< span className = "vip-badge" > VIP Customer </ span >
) }
</ div >
) : (
< div >
< h3 > Welcome, Guest! </ h3 >
< button > Sign in for faster checkout </ button >
</ div >
) }
</ div >
);
}
Customer Properties: Property Type Description email`string null` Customer email address name`string null` Customer full name firstName`string null` Customer first name lastName`string null` Customer last name isLoggedInbooleanWhether customer is authenticated tier`string null` Customer tier (vip, premium, etc.) memberSince`string null` Registration date orderHistoryOrder[]Previous orders totalSpentnumberLifetime customer value orderCountnumberTotal number of orders
Modify cart contents import { useCheckoutAction } from '@ollie-shop/sdk' ;
function CartActions () {
const {
addToCart ,
removeFromCart ,
updateQuantity ,
applyCoupon ,
removeCoupon
} = useCheckoutSession ();
const handleAddUpsell = async () => {
try {
await addToCart ({
id: 'upsell-123' ,
name: 'Extended Warranty' ,
price: 2999 , // $29.99 in cents
quantity: 1
});
} catch ( error ) {
console . error ( 'Failed to add item:' , error );
}
};
const handleUpdateQuantity = async ( itemId , newQuantity ) => {
try {
await updateQuantity ( itemId , newQuantity );
} catch ( error ) {
console . error ( 'Failed to update quantity:' , error );
}
};
const handleApplyCoupon = async () => {
try {
await applyCoupon ( 'SAVE10' );
} catch ( error ) {
console . error ( 'Invalid coupon:' , error );
}
};
return (
< div >
< button onClick = { handleAddUpsell } >
Add Extended Warranty
</ button >
< button onClick = { handleApplyCoupon } >
Apply SAVE10 Coupon
</ button >
</ div >
);
}
Available Actions: Action Parameters Description addToCartCartItemAdd new item to cart removeFromCartitemId: stringRemove item from cart updateQuantityitemId: string, quantity: numberUpdate item quantity applyCouponcode: stringApply discount coupon removeCouponcode: stringRemove applied coupon
useStoreInfo
Access store configuration, theme, and branding information.
🎨 Theme & Branding
🏪 Store Configuration
⚙️ Feature Flags
Use store theme in your components import { useStoreInfo } from '@ollie-shop/sdk' ;
function ThemedComponent () {
const { theme , store } = useStoreInfo ();
return (
< div
style = { {
backgroundColor: theme . colors . background ,
color: theme . colors . text ,
fontFamily: theme . fonts . body
} }
>
< h2 style = { {
color: theme . colors . primary ,
fontFamily: theme . fonts . heading
} } >
Welcome to { store . name }
</ h2 >
< button
style = { {
backgroundColor: theme . colors . primary ,
color: theme . colors . onPrimary ,
borderRadius: theme . borderRadius ,
padding: theme . spacing . medium
} }
>
Shop Now
</ button >
</ div >
);
}
Theme Properties: Property Type Description colors.primarystringPrimary brand color colors.secondarystringSecondary color colors.backgroundstringBackground color colors.textstringText color colors.onPrimarystringText color on primary background fonts.headingstringHeading font family fonts.bodystringBody text font family spacing.smallstringSmall spacing value spacing.mediumstringMedium spacing value spacing.largestringLarge spacing value borderRadiusstringDefault border radius
Access store settings and features import { useStoreInfo } from '@ollie-shop/sdk' ;
function StoreFeatures () {
const { store , features } = useStoreInfo ();
return (
< div >
< h3 > { store . name } </ h3 >
< p > { store . description } </ p >
{ /* Show features based on store configuration */ }
{ features . guestCheckout && (
< p > ✅ Guest checkout available </ p >
) }
{ features . expressCheckout && (
< button > Express Checkout </ button >
) }
{ features . loyaltyProgram && (
< div > Earn { store . loyaltyRate } % back on every purchase </ div >
) }
{ /* Show store policies */ }
< div className = "policies" >
< p > Free shipping over $ { store . freeShippingThreshold } </ p >
< p > { store . returnPolicy } day returns </ p >
</ div >
</ div >
);
}
Store Properties: Property Type Description namestringStore name descriptionstringStore description logostringStore logo URL faviconstringFavicon URL currencystringDefault currency localestringStore locale (en-US, pt-BR) timezonestringStore timezone freeShippingThresholdnumberFree shipping minimum returnPolicynumberReturn period in days loyaltyRatenumberLoyalty points percentage
Check available features import { useStoreInfo } from '@ollie-shop/sdk' ;
function ConditionalFeatures () {
const { features } = useStoreInfo ();
return (
< div >
{ features . guestCheckout && (
< button > Continue as Guest </ button >
) }
{ features . expressCheckout && (
< button > Express Checkout </ button >
) }
{ features . socialLogin && (
< div >
< button > Login with Google </ button >
< button > Login with Facebook </ button >
</ div >
) }
{ features . installments && (
< div > Pay in installments available </ div >
) }
{ features . coupons && (
< input placeholder = "Enter coupon code" />
) }
</ div >
);
}
Available Features: Feature Type Description guestCheckoutbooleanAllow checkout without account expressCheckoutbooleanOne-click checkout enabled socialLoginbooleanSocial media login options installmentsbooleanInstallment payments available couponsbooleanCoupon/discount codes enabled loyaltyProgrambooleanLoyalty points system wishlistbooleanWishlist functionality reviewsbooleanProduct reviews enabled
Hook Usage Patterns
🔄 Combining Multiple Hooks
Use multiple hooks together for rich components: import { useCheckoutSession , usePayment , useShipping , useStoreInfo } from '@ollie-shop/sdk' ;
function ComprehensiveCheckoutSummary () {
const { cart , customer } = useCheckoutSession ();
const { selectedMethod } = usePayment ();
const { selectedOption } = useShipping ();
const { store } = useStoreInfo ();
return (
< div >
< h2 > Order Summary - { store . name } </ h2 >
< div className = "customer-info" >
{ customer . isLoggedIn ? (
< p > Order for: { customer . name } </ p >
) : (
< p > Guest order </ p >
) }
</ div >
< div className = "cart-summary" >
< p > Items ( { cart . items . length } ): $ { ( cart . subtotal / 100 ). toFixed ( 2 ) } </ p >
< p > Shipping ( { selectedOption ?. name } ): $ { ( cart . shipping / 100 ). toFixed ( 2 ) } </ p >
< p > Payment method: { selectedMethod ?. name } </ p >
< p >< strong > Total: $ { ( cart . total / 100 ). toFixed ( 2 ) } </ strong ></ p >
</ div >
</ div >
);
}
⚡ Performance Optimization
Handle loading states and errors gracefully: import { useCheckoutSession } from '@ollie-shop/sdk' ;
import { useState } from 'react' ;
function RobustComponent () {
const { addToCart } = useCheckoutSession ();
const [ loading , setLoading ] = useState ( false );
const [ error , setError ] = useState ( null );
const handleAddToCart = async ( item ) => {
setLoading ( true );
setError ( null );
try {
await addToCart ( item );
} catch ( err ) {
setError ( 'Failed to add item to cart. Please try again.' );
console . error ( 'Add to cart error:' , err );
} finally {
setLoading ( false );
}
};
if ( error ) {
return (
< div className = "error" >
< p > { error } </ p >
< button onClick = { () => setError ( null ) } > Dismiss </ button >
</ div >
);
}
return (
< button
onClick = { () => handleAddToCart ( someItem ) }
disabled = { loading }
>
{ loading ? 'Adding...' : 'Add to Cart' }
</ button >
);
}