import { Context } from '@vue-storefront/core' ; import { AvailableStores , StoreConfig } from '@vue-storefront/magento-api' ; import { useStoreFactory , UseStoreFactoryParams } from '../../factories/useStoreFactory' ; import { UseStore } from '../../types/composables' ; import useCart from '../useCart' ; import StoreConfigGetters from '../../getters/storeConfigGetters' ; const factoryParams = { provide ( ) { return { cart : useCart ( ) , } ; } , load : async ( context , params ) : Promise < AvailableStores > => { const { data } = await context . $magento . api . availableStores ( ) ; return data . availableStores || [ ] ; } , change : ( context , store ) => { context . $magento . config . state . setStore ( StoreConfigGetters . getCode ( store ) ) ; context . $magento . config . state . setCurrency ( StoreConfigGetters . getCurrency ( store ) ) ; context . $magento . config . state . setLocale ( StoreConfigGetters . getCurrency ( store ) ) ; context . cart . clear ( ) ; } , } ; const useStore = useStoreFactory < AvailableStores , StoreConfig > ( factoryParams ) ; export default useStore ;