Skip to main content
Skip to main content

create - Pricing Module Reference

This documentation provides a reference to the create method. This belongs to the Pricing Module.

create(data, sharedContext?): Promise<PriceSetDTO>

This method is used to create a new price set.

Example

To create a default price set, don't pass any rules. For example:

const priceSet = await pricingModuleService.create({
rules: [],
prices: [
{
amount: 500,
currency_code: "USD",
min_quantity: 0,
max_quantity: 4,
rules: {},
},
{
amount: 400,
currency_code: "USD",
min_quantity: 5,
max_quantity: 10,
rules: {},
},
],
})

To create a price set and associate it with rule types:

const priceSet = await pricingModuleService.create({
rules: [
{ rule_attribute: "region_id" },
{ rule_attribute: "city" },
],
prices: [
{
amount: 300,
currency_code: "EUR",
rules: {
region_id: "PL",
city: "krakow",
},
},
{
amount: 400,
currency_code: "EUR",
rules: {
region_id: "PL",
},
},
{
amount: 450,
currency_code: "EUR",
rules: {
city: "krakow",
},
},
],
})

Parameters

dataCreatePriceSetDTORequired
The attributes of the price set to create.
sharedContextContext
A context used to share resources, such as transaction manager, between the application and the module.

Returns

PromisePromise<PriceSetDTO>Required
The created price set.

create(data, sharedContext?): Promise<PriceSetDTO[]>

This method is used to create multiple price sets.

Example

const priceSets = await pricingModuleService.create([
// default price set
{
rules: [],
prices: [
{
amount: 500,
currency_code: "USD",
min_quantity: 0,
max_quantity: 4,
rules: {},
},
{
amount: 400,
currency_code: "USD",
min_quantity: 5,
max_quantity: 10,
rules: {},
},
],
},
// price set with rules
{
rules: [
{ rule_attribute: "region_id" },
{ rule_attribute: "city" },
],
prices: [
{
amount: 300,
currency_code: "EUR",
rules: {
region_id: "PL",
city: "krakow",
},
},
{
amount: 400,
currency_code: "EUR",
rules: {
region_id: "PL",
},
},
{
amount: 450,
currency_code: "EUR",
rules: {
city: "krakow",
},
},
],
},
])

Parameters

dataCreatePriceSetDTO[]Required
The price sets to create.
sharedContextContext
A context used to share resources, such as transaction manager, between the application and the module.

Returns

PromisePromise<PriceSetDTO[]>Required
The list of created price sets.
Was this section helpful?