IPromotionModuleService
The main service interface for the Promotion Module.
Methods
registerUsage
This method adjusts the budget for each campaign associated with the promotions' specified computed actions.
It adjusts the used
property of a CampaignBudget
to account for the adjustment amounts in the specified associated
computed actions.
Example
Parameters
Returns
Promise
Promise<void>RequiredcomputeActions
This method provides the actions to perform on a cart based on the specified promotions and context.
Example
Parameters
promotionCodesToApply
string[]RequiredThe items and shipping methods of the cart.
options
Record<string, any>Returns
The list of computed actions to be applied on the cart.
create
**create**(data, sharedContext?): Promise<[PromotionDTO](types.PromotionTypes.PromotionDTO.mdx)[]>
This method creates promotions.
Example
const promotions = await promotionModuleService.create([
{
code: "50OFF",
type: "standard",
application_method: {
type: "percentage",
target_type: "items",
value: 50,
},
},
{
code: "FREESHIPPING",
type: "standard",
application_method: {
type: "percentage",
target_type: "shipping_methods",
value: 100,
},
},
{
code: "BUY2GET1",
type: "buyget",
application_method: {
type: "fixed",
target_type: "items",
buy_rules_min_quantity: 2,
apply_to_quantity: 1,
buy_rules: [
{
attribute: "SKU",
operator: "eq",
values: ["SHIRT"],
},
],
},
},
])
Parameters
The promotions to be created.
Returns
The created promotions.
**create**(data, sharedContext?): Promise<[PromotionDTO](types.PromotionTypes.PromotionDTO.mdx)>
This method creates a promotion.
Example
const promotionA = await promotionModuleService.create({
code: "50OFF",
type: "standard",
application_method: {
type: "percentage",
target_type: "items",
value: 50,
},
})
const promotionB = await promotionModuleService.create({
code: "FREESHIPPING",
type: "standard",
application_method: {
type: "percentage",
target_type: "shipping_methods",
value: 100,
},
})
const promotionC = await promotionModuleService.create({
code: "BUY2GET1",
type: "buyget",
application_method: {
type: "fixed",
target_type: "items",
buy_rules_min_quantity: 2,
apply_to_quantity: 1,
buy_rules: [
{
attribute: "SKU",
operator: "eq",
values: ["SHIRT"],
},
],
},
})
Parameters
The promotion to be created.
Returns
The created promotion.
update
**update**(data, sharedContext?): Promise<[PromotionDTO](types.PromotionTypes.PromotionDTO.mdx)[]>
This method updates existing promotions.
Example
Parameters
The attributes to update in the promotions.
Returns
The updated promotions.
**update**(data, sharedContext?): Promise<[PromotionDTO](types.PromotionTypes.PromotionDTO.mdx)>
This method updates an existing promotion.
Example
Parameters
The attributes to update in the promotion.
Returns
The updated promotion.
list
This method retrieves a paginated list of promotions based on optional filters and configuration.
Example
To retrieve a list of promotions using their IDs:
To specify relations that should be retrieved within the promotions:
By default, only the first 15
records are retrieved. You can control pagination by specifying the skip
and take
properties of the config
parameter:
Parameters
filters
FilterablePromotionPropsThe filters to apply on the retrieved promotions.
filters
FilterablePromotionPropsconfig
FindConfig<PromotionDTO>The configurations determining how the promotion is retrieved. Its properties, such as select
or relations
, accept the
attributes or relations associated with a promotion.
config
FindConfig<PromotionDTO>select
or relations
, accept the
attributes or relations associated with a promotion.Returns
The list of promotions.
listAndCount
This method retrieves a paginated list of promotions along with the total count of available promotions satisfying the provided filters.
Example
To retrieve a list of promotions using their IDs:
To specify relations that should be retrieved within the promotions:
By default, only the first 15
records are retrieved. You can control pagination by specifying the skip
and take
properties of the config
parameter:
Parameters
filters
FilterablePromotionPropsThe filters to apply on the retrieved promotions.
filters
FilterablePromotionPropsconfig
FindConfig<PromotionDTO>The configurations determining how the promotion is retrieved. Its properties, such as select
or relations
, accept the
attributes or relations associated with a promotion.
config
FindConfig<PromotionDTO>select
or relations
, accept the
attributes or relations associated with a promotion.Returns
The list of promotions along with their total count.
retrieve
This method retrieves a promotion by its ID.
Example
A simple example that retrieves a promotion by its ID:
To specify relations that should be retrieved:
Parameters
id
stringRequiredconfig
FindConfig<PromotionDTO>The configurations determining how the promotion is retrieved. Its properties, such as select
or relations
, accept the
attributes or relations associated with a promotion.
config
FindConfig<PromotionDTO>select
or relations
, accept the
attributes or relations associated with a promotion.Returns
The retrieved promotion.
delete
**delete**(ids, sharedContext?): Promise<void>
This method deletes promotions by their IDs.
Example
Parameters
ids
string[]RequiredReturns
Promise
Promise<void>Required**delete**(ids, sharedContext?): Promise<void>
This method deletes a promotion by its ID.
Example
Parameters
ids
stringRequiredReturns
Promise
Promise<void>RequiredsoftDelete
This method soft deletes a promotion by its IDs.
Example
Type Parameters
TReturnableLinkableKeys
stringRequiredParameters
promotionIds
string | string[]Requiredconfig
SoftDeleteReturn<TReturnableLinkableKeys>An object that is used to specify an entity's related entities that should be soft-deleted when the main entity is soft-deleted.
config
SoftDeleteReturn<TReturnableLinkableKeys>Returns
Promise
Promise<void | Record<string, string[]>>RequiredAn object that includes the IDs of related records that were also soft deleted, such as the ID of the associated application method.
The object's keys are the ID attribute names of the promotion entity's relations, such as application_method_id
, and its value is an array of strings, each being the ID of a record associated
with the promotion through this relation, such as the IDs of associated application method.
If there are no related records, the promise resolves to void
.
Promise
Promise<void | Record<string, string[]>>Requiredapplication_method_id
, and its value is an array of strings, each being the ID of a record associated
with the promotion through this relation, such as the IDs of associated application method.
If there are no related records, the promise resolves to void
.restore
This method restores soft deleted promotions by their IDs.
Example
Type Parameters
TReturnableLinkableKeys
stringRequiredParameters
promotionIds
string | string[]Requiredconfig
RestoreReturn<TReturnableLinkableKeys>Configurations determining which relations to restore along with each of the promotion. You can pass to its returnLinkableKeys
property any of the promotion's relation attribute names, such as application_method_id
.
config
RestoreReturn<TReturnableLinkableKeys>returnLinkableKeys
property any of the promotion's relation attribute names, such as application_method_id
.Returns
Promise
Promise<void | Record<string, string[]>>RequiredAn object that includes the IDs of related records that were restored, such as the ID of associated application method.
The object's keys are the ID attribute names of the promotion entity's relations, such as application_method_id
,
and its value is an array of strings, each being the ID of the record associated with the promotion through this relation,
such as the IDs of associated application method.
If there are no related records restored, the promise resolves to void
.
Promise
Promise<void | Record<string, string[]>>Requiredapplication_method_id
,
and its value is an array of strings, each being the ID of the record associated with the promotion through this relation,
such as the IDs of associated application method.
If there are no related records restored, the promise resolves to void
.addPromotionRules
This method adds promotion rules to a promotion.
Example
Parameters
promotionId
stringRequiredThe promotion rules to be created and added to the promotion.
Returns
The promotion rules created.
addPromotionTargetRules
This method adds target promotion rules to a promotion's application method.
Example
Parameters
promotionId
stringRequiredThe promotion rules to be created and added as target rules to the promotion's application method.
Returns
The created promotion rules.
addPromotionBuyRules
This method adds buy promotion rules to a promotion's application method.
Example
Parameters
promotionId
stringRequiredThe promotion rules to be created and added as buy rules to the promotion's applicatio method.
Returns
The created promotion rules.
removePromotionRules
This method removes promotion rules from a promotion.
Example
Parameters
promotionId
stringRequiredruleIds
string[]RequiredReturns
Promise
Promise<void>RequiredremovePromotionTargetRules
This method removes target promotion rules from a promotion's application method.
Example
Parameters
promotionId
stringRequiredruleIds
string[]RequiredReturns
Promise
Promise<void>RequiredremovePromotionBuyRules
This method removes buy promotion rules from a promotion's application method.
Example
Parameters
promotionId
stringRequiredruleIds
string[]RequiredReturns
Promise
Promise<void>RequiredcreateCampaigns
**createCampaigns**(data, sharedContext?): Promise<[CampaignDTO](types.PromotionTypes.CampaignDTO.mdx)>
This method creates a campaign.
Example
Parameters
The campaign to be created.
Returns
The created campaign.
**createCampaigns**(data, sharedContext?): Promise<[CampaignDTO](types.PromotionTypes.CampaignDTO.mdx)[]>
This method creates campaigns.
Example
Parameters
The campaigns to be created.
Returns
The created campaigns.
updateCampaigns
**updateCampaigns**(data, sharedContext?): Promise<[CampaignDTO](types.PromotionTypes.CampaignDTO.mdx)[]>
This method updates existing campaigns.
Example
Parameters
The attributes to update in the campaigns.
Returns
The updated campaigns.
**updateCampaigns**(data, sharedContext?): Promise<[CampaignDTO](types.PromotionTypes.CampaignDTO.mdx)>
This method updates an existing campaign.
Example
Parameters
The attributes to update in the campaign.
Returns
The updated campaign.
listPromotionRules
This method retrieves a paginated list of promotion rules based on optional filters and configuration.
Example
To retrieve a list of promotion rules using their IDs:
To specify relations that should be retrieved within the promotion rules:
By default, only the first 15
records are retrieved. You can control pagination by specifying the skip
and take
properties of the config
parameter:
Parameters
filters
FilterablePromotionRulePropsThe filters to apply on the retrieved promotion rules.
filters
FilterablePromotionRulePropsconfig
FindConfig<PromotionRuleDTO>The configurations determining how the promotion rule is retrieved. Its properties, such as select
or relations
, accept the
attributes or relations associated with a promotion rule.
config
FindConfig<PromotionRuleDTO>select
or relations
, accept the
attributes or relations associated with a promotion rule.Returns
The list of promotion rules.
updatePromotionRules
This method updates existing promotion rules.
Example
Parameters
The attributes to update in the promotion rules.
Returns
The updated promotion rules.
listCampaigns
This method retrieves a paginated list of campaigns based on optional filters and configuration.
Example
To retrieve a list of campaigns using their IDs:
To specify relations that should be retrieved within the campaigns:
By default, only the first 15
records are retrieved. You can control pagination by specifying the skip
and take
properties of the config
parameter:
Parameters
filters
FilterableCampaignPropsThe filters to apply on the retrieved campaigns.
filters
FilterableCampaignPropsconfig
FindConfig<CampaignDTO>The configurations determining how the campaign is retrieved. Its properties, such as select
or relations
, accept the
attributes or relations associated with a campaign.
config
FindConfig<CampaignDTO>select
or relations
, accept the
attributes or relations associated with a campaign.Returns
The list of campaigns.
listAndCountCampaigns
This method retrieves a paginated list of campaigns along with the total count of available campaigns satisfying the provided filters.
Example
To retrieve a list of campaigns using their IDs:
To specify relations that should be retrieved within the campaigns:
By default, only the first 15
records are retrieved. You can control pagination by specifying the skip
and take
properties of the config
parameter:
Parameters
filters
FilterableCampaignPropsThe filters to apply on the retrieved campaigns.
filters
FilterableCampaignPropsconfig
FindConfig<CampaignDTO>The configurations determining how the campaign is retrieved. Its properties, such as select
or relations
, accept the
attributes or relations associated with a campaign.
config
FindConfig<CampaignDTO>select
or relations
, accept the
attributes or relations associated with a campaign.Returns
The list of campaigns along with their total count.
retrieveCampaign
This method retrieves a campaigns by its ID.
Example
A simple example that retrieves a promotion by its ID:
To specify relations that should be retrieved:
Parameters
id
stringRequiredconfig
FindConfig<CampaignDTO>The configurations determining how the campaign is retrieved. Its properties, such as select
or relations
, accept the
attributes or relations associated with a campaign.
config
FindConfig<CampaignDTO>select
or relations
, accept the
attributes or relations associated with a campaign.Returns
The retrieved campaigns.
deleteCampaigns
**deleteCampaigns**(ids, sharedContext?): Promise<void>
This method deletes campaigns by their IDs.
Example
Parameters
ids
string[]RequiredReturns
Promise
Promise<void>Required**deleteCampaigns**(ids, sharedContext?): Promise<void>
This method deletes a campaign by its ID.
Example
Parameters
ids
stringRequiredReturns
Promise
Promise<void>RequiredsoftDeleteCampaigns
This method soft deletes campaigns by their IDs.
Example
Type Parameters
TReturnableLinkableKeys
stringRequiredParameters
campaignIds
string | string[]Requiredconfig
SoftDeleteReturn<TReturnableLinkableKeys>An object that is used to specify an entity's related entities that should be soft-deleted when the main entity is soft-deleted.
config
SoftDeleteReturn<TReturnableLinkableKeys>Returns
Promise
Promise<void | Record<string, string[]>>RequiredAn object that includes the IDs of related records that were also soft deleted, such as the ID of the associated campaign budget.
The object's keys are the ID attribute names of the campaign entity's relations, such as budget_id
, and its value is an array of strings, each being the ID of a record associated
with the campaign through this relation, such as the IDs of associated campaign budget.
If there are no related records, the promise resolves to void
.
Promise
Promise<void | Record<string, string[]>>Requiredbudget_id
, and its value is an array of strings, each being the ID of a record associated
with the campaign through this relation, such as the IDs of associated campaign budget.
If there are no related records, the promise resolves to void
.restoreCampaigns
This method restores soft deleted campaigns by their IDs.
Example
Type Parameters
TReturnableLinkableKeys
stringRequiredParameters
campaignIds
string | string[]Requiredconfig
RestoreReturn<TReturnableLinkableKeys>Configurations determining which relations to restore along with each of the campaigns. You can pass to its returnLinkableKeys
property any of the campaign's relation attribute names, such as budget_id
.
config
RestoreReturn<TReturnableLinkableKeys>returnLinkableKeys
property any of the campaign's relation attribute names, such as budget_id
.Returns
Promise
Promise<void | Record<string, string[]>>RequiredAn object that includes the IDs of related records that were restored, such as the ID of associated campaign budget.
The object's keys are the ID attribute names of the campaign entity's relations, such as budget_id
,
and its value is an array of strings, each being the ID of the record associated with the campaign through this relation,
such as the IDs of associated campaign budget.
If there are no related records restored, the promise resolves to void
.
Promise
Promise<void | Record<string, string[]>>Requiredbudget_id
,
and its value is an array of strings, each being the ID of the record associated with the campaign through this relation,
such as the IDs of associated campaign budget.
If there are no related records restored, the promise resolves to void
.