# useChannel
# Features
useChannel
composable can be used to:
- fetch channels list
- get places from channels
- get address string from channel
- get store times string
# API
search
- function for fetching channels data. When invoked, it requests data from the API and populateschannels
property. This method accepts a single params object. Theparams
has the following option:id: string
limit?: number
offset?: number
customQuery?: CustomQuery
type CustomQuery = { channels: string }
change
- function for changing channels cookie. When invoked, it changes the Browsers cookie and stores the data intocurrency
object. This method accepts the ChannelId as parameter and returnsvoid
.channel: ComputedProperty<string>
- reactive data containing the activecurrency
from Cookies or default.channels: ComputedProperty<Channel[]>
- reactive data object containing the response from the backend.export enum ChannelRole { InventorySupply = 'InventorySupply', ProductDistribution = 'ProductDistribution', OrderExport = 'OrderExport', OrderImport = 'OrderImport', Primary = 'Primary' } export type Channel = Versioned & ReviewTarget & { __typename?: 'Channel'; id: Scalars['String']; version: Scalars['Long']; key: Scalars['String']; roles: Array<ChannelRole>; name?: Maybe<Scalars['String']>; nameAllLocales?: Maybe<Array<LocalizedString>>; description?: Maybe<Scalars['String']>; descriptionAllLocales?: Maybe<Array<LocalizedString>>; address?: Maybe<Address>; geoLocation?: Maybe<GeometryInput>; createdAt: Scalars['DateTime']; lastModifiedAt: Scalars['DateTime']; reviewRatingStatistics?: Maybe<ReviewRatingStatistics>; custom?: Maybe<CustomFieldsType>; createdBy?: Maybe<Initiator>; lastModifiedBy?: Maybe<Initiator>; };
loading: boolean
- reactive object containing information about loading state ofsearch
method.error: UseChannelErrors
- reactive object containing the error message, ifsearch
failed for any reason.interface UseChannelErrors { search: Error; }
# Getters
getChannelAddress
- return channel address as stringgetStoreTimes
- return channel time as stringgetPlacesFromChannels
- return array ofAgnosticPlace
from channelsinterface AgnosticPlace extends Channel { addressLine: string; openingHours: string; storeName: string; } interface ChannelGetters { getChannelAddress: (channel: Channel) => string; getStoreTimes: (channel: Channel) => string | null; getPlacesFromChannels: (channels: Channel[]) => Array<AgnosticPlace>; }
# Example
import { onSSR } from '@vue-storefront/core';
import { useChannel, channelGetters } from '@vsf-enterprise/commercetools';
export default {
setup() {
const {
channels,
search,
loading,
error
} = useChannel('<CACHE_ID>');
onSSR(async () => {
await search();
});
return {
places: computed(() => channelGetters.getPlacesFromChannels(channels.value)),
loading,
error
};
}
};