Skip to main content
Skip to main content

SalesChannelService

Constructors

constructor

**new SalesChannelService**(«destructured»)

Parameters

__namedParametersInjectedDependenciesRequired

Properties

__configModule__Record<string, unknown>
__container__anyRequired
__moduleDeclaration__Record<string, unknown>
eventBusService_EventBusServiceRequired
manager_EntityManagerRequired
salesChannelRepository_Repository<SalesChannel> & &#123; addProducts: Method addProducts ; getFreeTextSearchResultsAndCount: Method getFreeTextSearchResultsAndCount ; listProductIdsBySalesChannelIds: Method listProductIdsBySalesChannelIds ; removeProducts: Method removeProducts &#125;Required
storeService_StoreServiceRequired
transactionManager_undefined | EntityManagerRequired
EventsobjectRequired
Events.CREATEDstringRequired

Default: "sales_channel.created"

Events.DELETEDstringRequired

Default: "sales_channel.deleted"

Events.UPDATEDstringRequired

Default: "sales_channel.updated"

Accessors

activeManager_

Protected get**activeManager_**(): EntityManager

Returns

EntityManager

EntityManagerEntityManagerRequired

Methods

addProducts

**addProducts**(salesChannelId, productIds): Promise&#60;[SalesChannel](/references/services/classes/SalesChannel)&#62;

Add a batch of product to a sales channel

Parameters

salesChannelIdstringRequired
The id of the sales channel on which to add the products
productIdsstring[]Required
The products ids to attach to the sales channel

Returns

Promise<SalesChannel>

PromisePromise<SalesChannel>Required
the sales channel on which the products have been added

atomicPhase_

Protected **atomicPhase_**<TypeParameter TResult, TypeParameter TError>(work, isolationOrErrorHandler?, maybeErrorHandlerOrDontFail?): Promise&#60;TResult&#62;

Wraps some work within a transactional block. If the service already has a transaction manager attached this will be reused, otherwise a new transaction manager is created.

TResultobjectRequired
TErrorobjectRequired

Parameters

work(transactionManager: EntityManager) => Promise<TResult>Required
the transactional work to be done
isolationOrErrorHandlerIsolationLevel | (error: TError) => Promise<void | TResult>
the isolation level to be used for the work.
maybeErrorHandlerOrDontFail(error: TError) => Promise<void | TResult>
Potential error handler

Returns

Promise<TResult>

PromisePromise<TResult>Required
the result of the transactional work

create

**create**(data): Promise&#60;[SalesChannel](/references/services/classes/SalesChannel)&#62;

Creates a SalesChannel

This feature is under development and may change in the future. To use this feature please enable the corresponding feature flag in your medusa backend project.

Parameters

Returns

Promise<SalesChannel>

PromisePromise<SalesChannel>Required
the created channel

createDefault

**createDefault**(): Promise&#60;[SalesChannel](/references/services/classes/SalesChannel)&#62;

Creates a default sales channel, if this does not already exist.

Returns

Promise<SalesChannel>

PromisePromise<SalesChannel>Required
the sales channel

delete

**delete**(salesChannelId): Promise&#60;void&#62;

Deletes a sales channel from This feature is under development and may change in the future. To use this feature please enable the corresponding feature flag in your medusa backend project.

Parameters

salesChannelIdstringRequired
the id of the sales channel to delete

Returns

Promise<void>

PromisePromise<void>Required

listAndCount

**listAndCount**(selector, config?): Promise&#60;[[SalesChannel](/references/services/classes/SalesChannel)[], number]&#62;

Lists sales channels based on the provided parameters and includes the count of sales channels that match the query.

Parameters

selectorQuerySelector<SalesChannel>Required
configFindConfig<SalesChannel>Required

Returns

Promise<[SalesChannel[], number]>

PromisePromise<[SalesChannel[], number]>Required
an array containing the sales channels as the first element and the total count of sales channels that matches the query as the second element.

listProductIdsBySalesChannelIds

**listProductIdsBySalesChannelIds**(salesChannelIds): Promise&#60;&#123; [salesChannelId: string]: string[]; &#125;&#62;

List all product ids that belongs to the sales channels ids

Parameters

salesChannelIdsstring | string[]Required

Returns

Promise<{ [salesChannelId: string]: string[]; }>

PromisePromise<{ [salesChannelId: string]: string[]; }>Required

removeProducts

**removeProducts**(salesChannelId, productIds): Promise&#60;[SalesChannel](/references/services/classes/SalesChannel)&#62;

Remove a batch of product from a sales channel

Parameters

salesChannelIdstringRequired
The id of the sales channel on which to remove the products
productIdsstring[]Required
The products ids to remove from the sales channel

Returns

Promise<SalesChannel>

PromisePromise<SalesChannel>Required
the sales channel on which the products have been removed

retrieve

**retrieve**(salesChannelId, config?): Promise&#60;[SalesChannel](/references/services/classes/SalesChannel)&#62;

Retrieve a SalesChannel by id

Parameters

salesChannelIdstringRequired
id of the channel to retrieve
configFindConfig<SalesChannel>Required
SC config This feature is under development and may change in the future. To use this feature please enable the corresponding feature flag in your medusa backend project.

Default: {}

Returns

Promise<SalesChannel>

PromisePromise<SalesChannel>Required
a sales channel

retrieveByName

**retrieveByName**(name, config?): Promise&#60;unknown&#62;

Find a sales channel by name.

Parameters

namestringRequired
of the sales channel
configFindConfig<SalesChannel>Required
find config

Default: {}

Returns

Promise<unknown>

PromisePromise<unknown>Required
a sales channel with matching name

retrieveDefault

**retrieveDefault**(): Promise&#60;[SalesChannel](/references/services/classes/SalesChannel)&#62;

Retrieves the default sales channel.

Returns

Promise<SalesChannel>

PromisePromise<SalesChannel>Required
the sales channel

retrieve_

Protected **retrieve_**(selector, config?): Promise&#60;[SalesChannel](/references/services/classes/SalesChannel)&#62;

A generic retrieve used to find a sales channel by different attributes.

Parameters

selectorSelector<SalesChannel>Required
SC selector
configFindConfig<SalesChannel>Required
find config

Default: {}

Returns

Promise<SalesChannel>

PromisePromise<SalesChannel>Required
a single SC matching the query or throws

shouldRetryTransaction_

Protected **shouldRetryTransaction_**(err): boolean

Parameters

errRecord<string, unknown> | &#123; code: string &#125;Required

Returns

boolean

booleanboolean

update

**update**(salesChannelId, data): Promise&#60;[SalesChannel](/references/services/classes/SalesChannel)&#62;

Parameters

salesChannelIdstringRequired

Returns

Promise<SalesChannel>

PromisePromise<SalesChannel>Required

withTransaction

**withTransaction**(transactionManager?): [SalesChannelService](/references/services/classes/SalesChannelService)

Parameters

transactionManagerEntityManager

Returns

SalesChannelService

SalesChannelServiceSalesChannelServiceRequired
Was this section helpful?