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,
salesChannelCountryId,
languageId,
languageIdChain,
userFromContext,
setLanguage,
setCountry,
refreshSessionContext,
setShippingMethod,
setPaymentMethod,
setCurrency,
setActiveShippingAddress,
setActiveBillingAddress
} = useSessionContext(newContext);
Signature ​
ts
export function useSessionContext(
newContext?: Schemas["SalesChannelContext"],
): UseSessionContextReturn
Parameters ​
Name | Type | Description |
---|---|---|
newContext |
Return type ​
See UseSessionContextReturn
ts
export type UseSessionContextReturn = {
/**
* Patches the context in order to use new language
*/
setLanguage(language: Partial<Schemas["Language"]>): Promise<void>;
/**
* Patches the context in order to use new countryId
*
* @param {string} countryId
*/
setCountry(countryId: string): Promise<void>;
/**
* current context's language
*/
sessionContext: ComputedRef<Schemas["SalesChannelContext"] | undefined>;
/**
* Fetches the session context and assigns the result to the `sessionContext` property
*/
refreshSessionContext(): Promise<void>;
/**
* current context's language
*/
selectedShippingMethod: ComputedRef<Schemas["ShippingMethod"] | null>;
/**
* Patches the context in order to use new shipping method
*/
setShippingMethod(
shippingMethod: Partial<Schemas["ShippingMethod"]>,
): Promise<void>;
/**
* current context's payment method
*/
selectedPaymentMethod: ComputedRef<Schemas["PaymentMethod"] | null>;
/**
* Patches the context in order to use new payment method
*/
setPaymentMethod(paymentMethod: { id: string }): Promise<void>;
/**
* current context's currency
*/
currency: ComputedRef<Schemas["Currency"] | null>;
/**
* Patches the context in order to use new currency
*/
setCurrency(currency: Partial<Schemas["Currency"]>): Promise<void>;
/**
* current context's shipping address
*/
activeShippingAddress: ComputedRef<Schemas["CustomerAddress"] | null>;
/**
* Patches the context in order to use new shipping address
*/
setActiveShippingAddress(
address: Partial<Schemas["CustomerAddress"]>,
): Promise<void>;
/**
* current context's billing address
*/
activeBillingAddress: ComputedRef<Schemas["CustomerAddress"] | null>;
/**
* current context's tax state
*/
taxState: ComputedRef<string | undefined>;
/**
* Patches the context in order to use new billing address
*/
setActiveBillingAddress(
address: Partial<Schemas["CustomerAddress"]>,
): Promise<void>;
/**
* current context's country id
*/
countryId: ComputedRef<string | undefined>;
/**
* current sales channel country id
*/
salesChannelCountryId: ComputedRef<string | undefined>;
/**
* current language id
*/
languageId: ComputedRef<string | undefined>;
/**
* current language id chain
*/
languageIdChain: ComputedRef<string>;
/**
* current context's customer object
*/
userFromContext: ComputedRef<Schemas["Customer"] | undefined>;
};
Properties ​
Name | Type | Description |
---|---|---|
sessionContext | ComputedRef< | undefined> | current context's language |
selectedShippingMethod | ComputedRef< | null> | current context's language |
selectedPaymentMethod | ComputedRef< | null> | current context's payment method |
currency | ComputedRef< | null> | current context's currency |
activeShippingAddress | ComputedRef< | null> | current context's shipping address |
activeBillingAddress | ComputedRef< | null> | current context's billing address |
taxState | ComputedRef<string | undefined> | current context's tax state |
countryId | ComputedRef<string | undefined> | current context's country id |
salesChannelCountryId | ComputedRef<string | undefined> | current sales channel country id |
languageId | ComputedRef<string | undefined> | current language id |
languageIdChain | ComputedRef<string> | current language id chain |
userFromContext | ComputedRef< | undefined> | current context's customer object |
Methods ​
Name | Type | Description |
---|---|---|
setLanguage | Promise<void> | Patches the context in order to use new language |
setCountry | Promise<void> | Patches the context in order to use new countryId |
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 |