import { Context, UseStoreFactoryParams, UseStoreFactoryLoadParamArguments, UseStoreFactoryChangeParamArguments, CustomQuery } from '@vue-storefront/core'; import { ResourceIdentifierInput } from '@vue-storefront/commercetools-api'; import { StoresData } from '../types'; export interface UseStoreFactoryChangeChannelParamArguments { channel: Record; customQuery?: CustomQuery; } export interface CtUseStoreFactoryParams extends UseStoreFactoryParams { changeChannel(context: Context, params: UseStoreFactoryChangeChannelParamArguments): Promise } async function load (context: Context, params: UseStoreFactoryLoadParamArguments): Promise { const { api, config } = context.$ct; const { customQuery } = params; return { ...await api.getStores({ customQuery }), _selectedStore: config.store }; } async function change (context: Context, { store }: UseStoreFactoryChangeParamArguments) { context.$ct.config.storeService.changeCurrentStore(`${store.key}`); window.location.reload(); return null as StoresData; } async function changeChannel (context: Context, { channel }: UseStoreFactoryChangeChannelParamArguments) { context.$ct.config.storeService.changeCurrentStore(`${(channel.distributtionChannel || 'null')}-${(channel.supplyChannel || 'null')}`); window.location.reload(); return null as StoresData; } /** * @remarks References: * {@link StoresData} */ const factoryParams: CtUseStoreFactoryParams = { load, change, changeChannel }; export default factoryParams;