Appearance
useSessionContext
Definition
Composable for session management. SessionContext contain all related data like user, currency, country, shippingMethod, paymentMethod etc.
Basic usage
ts
const {
sessionContext,
selectedShippingMethod,
selectedPaymentMethod,
currency,
activeShippingAddress,
activeBillingAddress,
taxState,
countryId,
languageId,
languageIdChain,
userFromContext,
setLanguage,
refreshSessionContext,
setShippingMethod,
setPaymentMethod,
setCurrency,
setActiveShippingAddress,
setActiveBillingAddress
} = useSessionContext(newContext);
Signature
ts
export function useSessionContext(
newContext?: SessionContext
): UseSessionContextReturn
Parameters
Name | Type | Description |
---|---|---|
newContext | SessionContext |
Return type
See UseSessionContextReturn
ts
export type UseSessionContextReturn = {
/**
* Patches the context in order to use new language
*/
setLanguage(language: Partial<Language>): Promise<void>;
/**
* current context's language
*/
sessionContext: ComputedRef<SessionContext | undefined>;
/**
* Fetches the session context and assigns the result to the `sessionContext` property
*/
refreshSessionContext(): Promise<void>;
/**
* current context's language
*/
selectedShippingMethod: ComputedRef<ShippingMethod | null>;
/**
* Patches the context in order to use new shipping method
*/
setShippingMethod(shippingMethod: Partial<ShippingMethod>): Promise<void>;
/**
* current context's payment method
*/
selectedPaymentMethod: ComputedRef<PaymentMethod | null>;
/**
* Patches the context in order to use new payment method
*/
setPaymentMethod(paymentMethod: Partial<PaymentMethod>): Promise<void>;
/**
* current context's currency
*/
currency: ComputedRef<Currency | null>;
/**
* Patches the context in order to use new currency
*/
setCurrency(currency: Partial<Currency>): Promise<void>;
/**
* current context's shipping address
*/
activeShippingAddress: ComputedRef<ShippingAddress | null>;
/**
* Patches the context in order to use new shipping address
*/
setActiveShippingAddress(address: Partial<ShippingAddress>): Promise<void>;
/**
* current context's billing address
*/
activeBillingAddress: ComputedRef<BillingAddress | null>;
/**
* current context's tax state
*/
taxState: ComputedRef<string | null>;
/**
* Patches the context in order to use new billing address
*/
setActiveBillingAddress(address: Partial<BillingAddress>): Promise<void>;
/**
* current context's country id
*/
countryId: ComputedRef<string | undefined>;
/**
* current language id
*/
languageId: ComputedRef<string | undefined>;
/**
* current language id chain
*/
languageIdChain: ComputedRef<string>;
/**
* current context's customer object
*/
userFromContext: ComputedRef<Customer | undefined>;
};
Properties
Name | Type | Description |
---|---|---|
sessionContext | ComputedRef<SessionContext | undefined> | current context's language |
selectedShippingMethod | ComputedRef<ShippingMethod | null> | current context's language |
selectedPaymentMethod | ComputedRef<PaymentMethod | null> | current context's payment method |
currency | ComputedRef<Currency | null> | current context's currency |
activeShippingAddress | ComputedRef<ShippingAddress | null> | current context's shipping address |
activeBillingAddress | ComputedRef<BillingAddress | null> | current context's billing address |
taxState | ComputedRef<string | null> | current context's tax state |
countryId | ComputedRef<string | undefined> | current context's country id |
languageId | ComputedRef<string | undefined> | current language id |
languageIdChain | ComputedRef<string> | current language id chain |
userFromContext | ComputedRef<Customer | undefined> | current context's customer object |
Methods
Name | Type | Description |
---|---|---|
setLanguage | Promise<void> | Patches the context in order to use new language |
refreshSessionContext | Promise<void> | Fetches the session context and assigns the result to the `sessionContext` property |
setShippingMethod | Promise<void> | Patches the context in order to use new shipping method |
setPaymentMethod | Promise<void> | Patches the context in order to use new payment method |
setCurrency | Promise<void> | Patches the context in order to use new currency |
setActiveShippingAddress | Promise<void> | Patches the context in order to use new shipping address |
setActiveBillingAddress | Promise<void> | Patches the context in order to use new billing address |