docs: resdesign and restructure modules references (#5372)
* docs: change format of module reference * description fix * update structure + comments * added new options to README * small text fix * change section ordering * change how required/optional are shown * remove optional text * docs: redesigned accordion
This commit is contained in:
1 parent
3dada88c81
commit
2d74ec256f
218 files changed
+5433
-7683
No files matched your search
@@ -25,9 +25,8 @@ module.exports = ({
|
|||||||
},
|
},
|
||||||
expandMembers: true,
|
expandMembers: true,
|
||||||
showCommentsAsHeader: true,
|
showCommentsAsHeader: true,
|
||||||
parameterStyle: "list",
|
parameterStyle: "component",
|
||||||
useTsLinkResolution: false,
|
useTsLinkResolution: false,
|
||||||
showReturnSignature: false,
|
|
||||||
sections: {
|
sections: {
|
||||||
reflection_typeParameters: false,
|
reflection_typeParameters: false,
|
||||||
member_declaration_typeParameters: false,
|
member_declaration_typeParameters: false,
|
||||||
@@ -39,13 +38,30 @@ module.exports = ({
|
|||||||
member_signature_sources: false,
|
member_signature_sources: false,
|
||||||
member_signature_title: false,
|
member_signature_title: false,
|
||||||
title_reflectionPath: false,
|
title_reflectionPath: false,
|
||||||
|
member_sources_definedIn: false,
|
||||||
|
member_signature_returns: false,
|
||||||
},
|
},
|
||||||
reflectionGroups: {
|
reflectionGroups: {
|
||||||
Constructors: false,
|
Constructors: false,
|
||||||
Properties: false,
|
Properties: false,
|
||||||
},
|
},
|
||||||
|
parameterComponent: "ParameterTypes",
|
||||||
|
mdxImports: [
|
||||||
|
`import ParameterTypes from "@site/src/components/ParameterTypes"`,
|
||||||
|
],
|
||||||
}
|
}
|
||||||
: {}),
|
: {
|
||||||
|
showCommentsAsHeader: true,
|
||||||
|
sections: {
|
||||||
|
member_sources_definedIn: false,
|
||||||
|
reflection_hierarchy: false,
|
||||||
|
},
|
||||||
|
parameterStyle: "component",
|
||||||
|
parameterComponent: "ParameterTypes",
|
||||||
|
mdxImports: [
|
||||||
|
`import ParameterTypes from "@site/src/components/ParameterTypes"`,
|
||||||
|
],
|
||||||
|
}),
|
||||||
...additionalFormatting,
|
...additionalFormatting,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -73,6 +89,8 @@ module.exports = ({
|
|||||||
hideMembersSymbol: true,
|
hideMembersSymbol: true,
|
||||||
formatting,
|
formatting,
|
||||||
allReflectionsHaveOwnDocument: true,
|
allReflectionsHaveOwnDocument: true,
|
||||||
|
objectLiteralTypeDeclarationStyle: "component",
|
||||||
|
mdxOutput: true,
|
||||||
...extraOptions,
|
...extraOptions,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -18,7 +18,6 @@ module.exports = modulesConfig({
|
|||||||
text: "Beta",
|
text: "Beta",
|
||||||
},
|
},
|
||||||
slug: "/references/pricing",
|
slug: "/references/pricing",
|
||||||
// hide_table_of_contents: true,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -26,7 +25,7 @@ module.exports = modulesConfig({
|
|||||||
pattern: "IPricingModuleService/methods",
|
pattern: "IPricingModuleService/methods",
|
||||||
additionalFormatting: {
|
additionalFormatting: {
|
||||||
reflectionDescription:
|
reflectionDescription:
|
||||||
"This documentation provides a reference to the {{alias}} {{kind}}. This belongs to the Pricing Module.",
|
"This documentation provides a reference to the `{{alias}}` {{kind}}. This belongs to the Pricing Module.",
|
||||||
frontmatterData: {
|
frontmatterData: {
|
||||||
displayed_sidebar: "pricingReference",
|
displayed_sidebar: "pricingReference",
|
||||||
badge: {
|
badge: {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ A plugin that forks and customizes the [typedoc-plugin-markdown](https://github.
|
|||||||
|
|
||||||
Aside from the options detailed in [typedoc-plugin-markdown](https://github.com/tgreyuk/typedoc-plugin-markdown/tree/master/packages/typedoc-plugin-markdown#options), the following options are accepted:
|
Aside from the options detailed in [typedoc-plugin-markdown](https://github.com/tgreyuk/typedoc-plugin-markdown/tree/master/packages/typedoc-plugin-markdown#options), the following options are accepted:
|
||||||
|
|
||||||
|
- `mdxImports`: A boolean value indicating whether the outputted files should be MDX files with the `.mdx` extension.
|
||||||
- `formatting`: An object whose keys are string patterns used to target specific files. You can also use the string `*` to target all files. The values are objects having the following properties:
|
- `formatting`: An object whose keys are string patterns used to target specific files. You can also use the string `*` to target all files. The values are objects having the following properties:
|
||||||
- `sections`: (optional) an object whose keys are of type [`SectionKey`](./src/types.ts#L19) and values are boolean. This property is used to enable/disable certain sections in the outputted generated docs.
|
- `sections`: (optional) an object whose keys are of type [`SectionKey`](./src/types.ts#L19) and values are boolean. This property is used to enable/disable certain sections in the outputted generated docs.
|
||||||
- `reflectionGroups`: (optional) an object whose keys are titles of reflection groups (for example, `Constructors`), and values are boolean. This property is used to enable/disable reflection group from being documented.
|
- `reflectionGroups`: (optional) an object whose keys are titles of reflection groups (for example, `Constructors`), and values are boolean. This property is used to enable/disable reflection group from being documented.
|
||||||
@@ -17,10 +18,11 @@ Aside from the options detailed in [typedoc-plugin-markdown](https://github.com/
|
|||||||
- `expandMembers`: (optional) a boolean indicating whether members in a page should be expanded. When enabled, the member titles (for example, `Methods`) are removed and the heading level of nested titles whithin the member is elevated by `1`.
|
- `expandMembers`: (optional) a boolean indicating whether members in a page should be expanded. When enabled, the member titles (for example, `Methods`) are removed and the heading level of nested titles whithin the member is elevated by `1`.
|
||||||
- `showCommentAsHeader`: (optional) a boolean indicating whether comments, for example, a method's name, are represented as headers.
|
- `showCommentAsHeader`: (optional) a boolean indicating whether comments, for example, a method's name, are represented as headers.
|
||||||
- `showCommentsAsDetails`: (optional) a boolean indicating whether comments, for example, a method's name, are represented as details component.
|
- `showCommentsAsDetails`: (optional) a boolean indicating whether comments, for example, a method's name, are represented as details component.
|
||||||
- `parameterStyle`: (optional) a string indicating how parameters are displayed. Its value can be `table` (default) or `list`.
|
- `parameterStyle`: (optional) a string indicating how parameters are displayed. Its value can be `table` (default), `list`, or `component`.
|
||||||
- `showReturnSignature`: (optional) a boolean indicating whether to show the signature for returned values.
|
- `showReturnSignature`: (optional) a boolean indicating whether to show the signature for returned values.
|
||||||
- `frontmatterData`: (optional) an object that will be injected as frontmatter to the pages matching specified pattern.
|
- `frontmatterData`: (optional) an object that will be injected as frontmatter to the pages matching specified pattern.
|
||||||
-
|
- `parameterComponent`: (optional) a string indicating the name of a React component to pass the parameters as an object to. This is only used if the `parameterStyle` option is set to `component`. This also must be used with the `mdxOutput` option enabled, and an import string for the component passed to the `mdxImports` option. The React component will receive a `parameters` prop, which is an array of type [Parameter](./src/types.ts#L95).
|
||||||
|
- `mdxImports`: (optional) an array of strings, each holding an import statement that will be added to the beginning of each page. For example, `["import ParameterTypes from "@site/src/components/ParameterTypes""]`. Must be used along with the `mdxOutput` option enabled.
|
||||||
|
|
||||||
## Build Plugin
|
## Build Plugin
|
||||||
|
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ export function load(app: Application) {
|
|||||||
type: ParameterType.String,
|
type: ParameterType.String,
|
||||||
defaultValue: "table",
|
defaultValue: "table",
|
||||||
validate: (x) => {
|
validate: (x) => {
|
||||||
const availableValues = ["table", "list"]
|
const availableValues = ["table", "list", "component"]
|
||||||
if (!availableValues.includes(x)) {
|
if (!availableValues.includes(x)) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Wrong value for objectLiteralTypeDeclarationStyle, the expected value is one of ${availableValues}`
|
`Wrong value for objectLiteralTypeDeclarationStyle, the expected value is one of ${availableValues}`
|
||||||
@@ -102,5 +102,12 @@ export function load(app: Application) {
|
|||||||
type: ParameterType.Object,
|
type: ParameterType.Object,
|
||||||
defaultValue: {},
|
defaultValue: {},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
app.options.addDeclaration({
|
||||||
|
help: "[Markdown Plugin] Whether outputted files should have an mdx extension.",
|
||||||
|
name: "mdxOutput",
|
||||||
|
type: ParameterType.Boolean,
|
||||||
|
defaultValue: false,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
export { MarkdownTheme }
|
export { MarkdownTheme }
|
||||||
@@ -37,8 +37,16 @@ import parameterHelper from "./resources/helpers/parameter"
|
|||||||
import debugHelper from "./resources/helpers/debug"
|
import debugHelper from "./resources/helpers/debug"
|
||||||
import frontmatterHelper from "./resources/helpers/frontmatter"
|
import frontmatterHelper from "./resources/helpers/frontmatter"
|
||||||
import reflectionDescriptionHelper from "./resources/helpers/reflection-description"
|
import reflectionDescriptionHelper from "./resources/helpers/reflection-description"
|
||||||
|
import mdxImportsHelper from "./resources/helpers/mdx-imports"
|
||||||
|
import parameterComponentHelper from "./resources/helpers/parameter-component"
|
||||||
|
import typeParameterComponentHelper from "./resources/helpers/type-parameter-component"
|
||||||
|
import showPropertiesAsComponentHelper from "./resources/helpers/show-properties-as-component"
|
||||||
|
import commentTagHelper from "./resources/helpers/comment-tag"
|
||||||
|
import exampleHelper from "./resources/helpers/example"
|
||||||
import { MarkdownTheme } from "./theme"
|
import { MarkdownTheme } from "./theme"
|
||||||
|
|
||||||
|
// test
|
||||||
|
|
||||||
const TEMPLATE_PATH = path.join(__dirname, "resources", "templates")
|
const TEMPLATE_PATH = path.join(__dirname, "resources", "templates")
|
||||||
|
|
||||||
export const indexTemplate = Handlebars.compile(
|
export const indexTemplate = Handlebars.compile(
|
||||||
@@ -68,7 +76,7 @@ export function registerPartials() {
|
|||||||
export function registerHelpers(theme: MarkdownTheme) {
|
export function registerHelpers(theme: MarkdownTheme) {
|
||||||
breadcrumbsHelper(theme)
|
breadcrumbsHelper(theme)
|
||||||
commentHelper(theme)
|
commentHelper(theme)
|
||||||
commentsHelper(theme)
|
commentsHelper()
|
||||||
declarationTitleHelper(theme)
|
declarationTitleHelper(theme)
|
||||||
escapeHelper()
|
escapeHelper()
|
||||||
hierarchyHelper()
|
hierarchyHelper()
|
||||||
@@ -86,7 +94,7 @@ export function registerHelpers(theme: MarkdownTheme) {
|
|||||||
reflectionPathHelper()
|
reflectionPathHelper()
|
||||||
reflectionTitleHelper(theme)
|
reflectionTitleHelper(theme)
|
||||||
relativeUrlHelper(theme)
|
relativeUrlHelper(theme)
|
||||||
returns()
|
returns(theme)
|
||||||
signatureTitleHelper(theme)
|
signatureTitleHelper(theme)
|
||||||
tocHelper(theme)
|
tocHelper(theme)
|
||||||
typeHelper()
|
typeHelper()
|
||||||
@@ -102,4 +110,10 @@ export function registerHelpers(theme: MarkdownTheme) {
|
|||||||
debugHelper()
|
debugHelper()
|
||||||
frontmatterHelper(theme)
|
frontmatterHelper(theme)
|
||||||
reflectionDescriptionHelper(theme)
|
reflectionDescriptionHelper(theme)
|
||||||
|
mdxImportsHelper(theme)
|
||||||
|
parameterComponentHelper(theme)
|
||||||
|
typeParameterComponentHelper(theme)
|
||||||
|
showPropertiesAsComponentHelper(theme)
|
||||||
|
commentTagHelper(theme)
|
||||||
|
exampleHelper()
|
||||||
}
|
}
|
||||||
+27
@@ -0,0 +1,27 @@
|
|||||||
|
import * as Handlebars from "handlebars"
|
||||||
|
import { CommentTag } from "typedoc"
|
||||||
|
import { camelToTitleCase } from "../../utils"
|
||||||
|
import { MarkdownTheme } from "../../theme"
|
||||||
|
|
||||||
|
export default function (theme: MarkdownTheme) {
|
||||||
|
Handlebars.registerHelper(
|
||||||
|
"commentTag",
|
||||||
|
function (tag: CommentTag, commentLevel = 4, parent = null) {
|
||||||
|
const { showCommentsAsHeader, showCommentsAsDetails } =
|
||||||
|
theme.getFormattingOptionsForLocation()
|
||||||
|
const tagTitle = camelToTitleCase(tag.tag.substring(1)),
|
||||||
|
tagContent = Handlebars.helpers.comment(tag.content)
|
||||||
|
|
||||||
|
if (showCommentsAsHeader) {
|
||||||
|
return `${Handlebars.helpers.titleLevel.call(
|
||||||
|
parent,
|
||||||
|
commentLevel
|
||||||
|
)} ${tagTitle}\n\n${tagContent}`
|
||||||
|
} else if (showCommentsAsDetails) {
|
||||||
|
return `<details>\n<summary>\n${tagTitle}\n</summary>\n\n${tagContent}\n\n</details>`
|
||||||
|
}
|
||||||
|
|
||||||
|
return `**${tagTitle}**\n\n${tagContent}`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
+9
-21
@@ -1,9 +1,7 @@
|
|||||||
import * as Handlebars from "handlebars"
|
import * as Handlebars from "handlebars"
|
||||||
import { Comment } from "typedoc"
|
import { Comment } from "typedoc"
|
||||||
import { camelToTitleCase } from "../../utils"
|
|
||||||
import { MarkdownTheme } from "../../theme"
|
|
||||||
|
|
||||||
export default function (theme: MarkdownTheme) {
|
export default function () {
|
||||||
Handlebars.registerHelper(
|
Handlebars.registerHelper(
|
||||||
"comments",
|
"comments",
|
||||||
function (
|
function (
|
||||||
@@ -13,33 +11,23 @@ export default function (theme: MarkdownTheme) {
|
|||||||
commentLevel = 4,
|
commentLevel = 4,
|
||||||
parent = null
|
parent = null
|
||||||
) {
|
) {
|
||||||
const { showCommentsAsHeader, showCommentsAsDetails } =
|
|
||||||
theme.getFormattingOptionsForLocation()
|
|
||||||
const md: string[] = []
|
const md: string[] = []
|
||||||
|
|
||||||
if (showSummary && comment.summary) {
|
if (showSummary && comment.summary) {
|
||||||
md.push(Handlebars.helpers.comment(comment.summary))
|
md.push(Handlebars.helpers.comment(comment.summary))
|
||||||
}
|
}
|
||||||
|
|
||||||
const filteredTags = comment.blockTags.filter(
|
const filteredTags = comment.blockTags
|
||||||
(tag) => tag.tag !== "@returns"
|
.filter((tag) => tag.tag !== "@returns")
|
||||||
)
|
.filter((tag) => tag.tag !== "@example")
|
||||||
|
|
||||||
if (showTags && comment.blockTags?.length) {
|
if (showTags && comment.blockTags?.length) {
|
||||||
const tags = filteredTags.map((tag) => {
|
const tags = filteredTags.map((tag) => {
|
||||||
const tagTitle = camelToTitleCase(tag.tag.substring(1)),
|
return Handlebars.helpers.commentTag(
|
||||||
tagContent = Handlebars.helpers.comment(tag.content)
|
tag,
|
||||||
|
commentLevel,
|
||||||
if (showCommentsAsHeader) {
|
parent || comment
|
||||||
return `${Handlebars.helpers.titleLevel.call(
|
)
|
||||||
parent || comment,
|
|
||||||
commentLevel
|
|
||||||
)} ${tagTitle}\n\n${tagContent}`
|
|
||||||
} else if (showCommentsAsDetails) {
|
|
||||||
return `<details>\n<summary>\n${tagTitle}\n</summary>\n\n${tagContent}\n\n</details>`
|
|
||||||
} else {
|
|
||||||
return `**${tagTitle}**\n\n${tagContent}`
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
md.push(tags.join("\n\n"))
|
md.push(tags.join("\n\n"))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import * as Handlebars from "handlebars"
|
||||||
|
import { Reflection } from "typedoc"
|
||||||
|
|
||||||
|
export default function () {
|
||||||
|
Handlebars.registerHelper(
|
||||||
|
"example",
|
||||||
|
function (reflection: Reflection, commentLevel = 4) {
|
||||||
|
const exampleTag = reflection.comment?.blockTags.find(
|
||||||
|
(tag) => tag.tag === "@example"
|
||||||
|
)
|
||||||
|
|
||||||
|
if (!exampleTag) {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
return Handlebars.helpers.commentTag(exampleTag, commentLevel, reflection)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
import * as Handlebars from "handlebars"
|
||||||
|
import { MarkdownTheme } from "../../theme"
|
||||||
|
|
||||||
|
export default function (theme: MarkdownTheme) {
|
||||||
|
Handlebars.registerHelper("mdxImports", function () {
|
||||||
|
if (!theme.mdxOutput) {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
const { mdxImports } = theme.getFormattingOptionsForLocation()
|
||||||
|
|
||||||
|
return mdxImports?.join("\n") || ""
|
||||||
|
})
|
||||||
|
}
|
||||||
+22
@@ -0,0 +1,22 @@
|
|||||||
|
import * as Handlebars from "handlebars"
|
||||||
|
import { ReflectionParameterType } from "../../types"
|
||||||
|
import { parseParams } from "../../utils/params-utils"
|
||||||
|
import { MarkdownTheme } from "../../theme"
|
||||||
|
import { reflectionComponentFormatter } from "../../utils/reflection-formatter"
|
||||||
|
|
||||||
|
export default function (theme: MarkdownTheme) {
|
||||||
|
Handlebars.registerHelper(
|
||||||
|
"parameterComponent",
|
||||||
|
function (this: ReflectionParameterType[]) {
|
||||||
|
const { parameterComponent } = theme.getFormattingOptionsForLocation()
|
||||||
|
const parameters = this.reduce(
|
||||||
|
(acc: ReflectionParameterType[], current) => parseParams(current, acc),
|
||||||
|
[]
|
||||||
|
).map((parameter) => reflectionComponentFormatter(parameter, 1))
|
||||||
|
|
||||||
|
return `<${parameterComponent} parameters={${JSON.stringify(
|
||||||
|
parameters
|
||||||
|
)}} />`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
+2
-2
@@ -1,7 +1,7 @@
|
|||||||
import * as Handlebars from "handlebars"
|
import * as Handlebars from "handlebars"
|
||||||
import reflectionFomatter from "../../utils/reflection-formatter"
|
|
||||||
import { ReflectionParameterType } from "../../types"
|
import { ReflectionParameterType } from "../../types"
|
||||||
import { parseParams } from "../../utils/params-utils"
|
import { parseParams } from "../../utils/params-utils"
|
||||||
|
import reflectionFormatter from "../../utils/reflection-formatter"
|
||||||
|
|
||||||
export default function () {
|
export default function () {
|
||||||
Handlebars.registerHelper(
|
Handlebars.registerHelper(
|
||||||
@@ -21,7 +21,7 @@ export default function () {
|
|||||||
|
|
||||||
function list(parameters: ReflectionParameterType[]) {
|
function list(parameters: ReflectionParameterType[]) {
|
||||||
const items = parameters.map((parameter) => {
|
const items = parameters.map((parameter) => {
|
||||||
return reflectionFomatter(parameter)
|
return reflectionFormatter(parameter, "list")
|
||||||
})
|
})
|
||||||
|
|
||||||
return items.join("\n")
|
return items.join("\n")
|
||||||
|
|||||||
+18
-106
@@ -1,119 +1,31 @@
|
|||||||
import * as Handlebars from "handlebars"
|
import * as Handlebars from "handlebars"
|
||||||
import { ParameterReflection, ReflectionType } from "typedoc"
|
|
||||||
import { stripLineBreaks } from "../../utils"
|
|
||||||
import { getReflectionType } from "./type"
|
|
||||||
import { parseParams } from "../../utils/params-utils"
|
import { parseParams } from "../../utils/params-utils"
|
||||||
import { ReflectionParameterType } from "../../types"
|
import { ReflectionParameterType } from "../../types"
|
||||||
|
import {
|
||||||
|
getTableHeaders,
|
||||||
|
reflectionTableFormatter,
|
||||||
|
} from "../../utils/reflection-formatter"
|
||||||
|
|
||||||
export default function () {
|
export default function () {
|
||||||
Handlebars.registerHelper(
|
Handlebars.registerHelper(
|
||||||
"parameterTable",
|
"parameterTable",
|
||||||
|
|
||||||
function (this: ReflectionParameterType[]) {
|
function (this: ReflectionParameterType[]) {
|
||||||
return table(
|
const parameters = this.reduce(
|
||||||
this.reduce(
|
(acc: ReflectionParameterType[], current: ReflectionParameterType) =>
|
||||||
(acc: ReflectionParameterType[], current: ReflectionParameterType) =>
|
parseParams(current, acc),
|
||||||
parseParams(current, acc),
|
[]
|
||||||
[]
|
|
||||||
) as ParameterReflection[]
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const headers = getTableHeaders(parameters)
|
||||||
|
|
||||||
|
const rows = parameters.map((parameter) =>
|
||||||
|
reflectionTableFormatter(parameter)
|
||||||
|
)
|
||||||
|
|
||||||
|
return `\n| ${headers.join(" | ")} |\n| ${headers
|
||||||
|
.map(() => ":------")
|
||||||
|
.join(" | ")} |\n${rows.join("")}`
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function table(parameters: ParameterReflection[]) {
|
|
||||||
const showDefaults = hasDefaultValues(parameters)
|
|
||||||
|
|
||||||
const comments = parameters.map(
|
|
||||||
(param: ParameterReflection) => !!param.comment?.hasVisibleComponent()
|
|
||||||
)
|
|
||||||
const hasComments = !comments.every((value) => !value)
|
|
||||||
|
|
||||||
const headers = ["Name", "Type"]
|
|
||||||
|
|
||||||
if (showDefaults) {
|
|
||||||
headers.push("Default value")
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hasComments) {
|
|
||||||
headers.push("Description")
|
|
||||||
}
|
|
||||||
|
|
||||||
const rows = parameters.map((parameter) => {
|
|
||||||
const row: string[] = []
|
|
||||||
|
|
||||||
const nbsp = " " // ? <== Unicode no-break space character
|
|
||||||
const rest = parameter.flags.isRest ? "..." : ""
|
|
||||||
const optional = parameter.flags.isOptional ? "?" : ""
|
|
||||||
|
|
||||||
const isDestructuredParam = parameter.name == "__namedParameters"
|
|
||||||
const isDestructuredParamProp =
|
|
||||||
parameter.name.startsWith("__namedParameters.")
|
|
||||||
|
|
||||||
if (isDestructuredParam) {
|
|
||||||
row.push(`\`${rest}«destructured»\``)
|
|
||||||
} else if (isDestructuredParamProp) {
|
|
||||||
row.push(`›${nbsp}\`${rest}${parameter.name.slice(18)}${optional}\``)
|
|
||||||
} else {
|
|
||||||
row.push(`\`${rest}${parameter.name}${optional}\``)
|
|
||||||
}
|
|
||||||
|
|
||||||
row.push(
|
|
||||||
parameter.type
|
|
||||||
? Handlebars.helpers.type.call(parameter.type, "object")
|
|
||||||
: getReflectionType(parameter, "object")
|
|
||||||
)
|
|
||||||
|
|
||||||
if (showDefaults) {
|
|
||||||
row.push(getDefaultValue(parameter))
|
|
||||||
}
|
|
||||||
if (hasComments) {
|
|
||||||
const comments = getComments(parameter)
|
|
||||||
if (comments) {
|
|
||||||
row.push(
|
|
||||||
stripLineBreaks(Handlebars.helpers.comments(comments)).replace(
|
|
||||||
/\|/g,
|
|
||||||
"\\|"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
row.push("-")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return `| ${row.join(" | ")} |\n`
|
|
||||||
})
|
|
||||||
|
|
||||||
const output = `\n| ${headers.join(" | ")} |\n| ${headers
|
|
||||||
.map(() => ":------")
|
|
||||||
.join(" | ")} |\n${rows.join("")}`
|
|
||||||
return output
|
|
||||||
}
|
|
||||||
|
|
||||||
function getDefaultValue(parameter: ParameterReflection) {
|
|
||||||
return parameter.defaultValue && parameter.defaultValue !== "..."
|
|
||||||
? `\`${parameter.defaultValue}\``
|
|
||||||
: "`undefined`"
|
|
||||||
}
|
|
||||||
|
|
||||||
function hasDefaultValues(parameters: ParameterReflection[]) {
|
|
||||||
const defaultValues = (parameters as ParameterReflection[]).map(
|
|
||||||
(param) =>
|
|
||||||
param.defaultValue !== "{}" &&
|
|
||||||
param.defaultValue !== "..." &&
|
|
||||||
!!param.defaultValue
|
|
||||||
)
|
|
||||||
|
|
||||||
return !defaultValues.every((value) => !value)
|
|
||||||
}
|
|
||||||
|
|
||||||
function getComments(parameter: ParameterReflection) {
|
|
||||||
if (parameter.type instanceof ReflectionType) {
|
|
||||||
if (
|
|
||||||
parameter.type?.declaration?.signatures &&
|
|
||||||
parameter.type?.declaration?.signatures[0]?.comment
|
|
||||||
) {
|
|
||||||
return parameter.type?.declaration?.signatures[0]?.comment
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return parameter.comment
|
|
||||||
}
|
|
||||||
@@ -10,6 +10,8 @@ export default function (theme: MarkdownTheme) {
|
|||||||
|
|
||||||
if (parameterStyle === "list") {
|
if (parameterStyle === "list") {
|
||||||
return Handlebars.helpers.parameterList.call(this)
|
return Handlebars.helpers.parameterList.call(this)
|
||||||
|
} else if (parameterStyle === "component") {
|
||||||
|
return Handlebars.helpers.parameterComponent.call(this)
|
||||||
} else {
|
} else {
|
||||||
return Handlebars.helpers.parameterTable.call(this)
|
return Handlebars.helpers.parameterTable.call(this)
|
||||||
}
|
}
|
||||||
|
|||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
import * as Handlebars from "handlebars"
|
||||||
|
import { MarkdownTheme } from "../../theme"
|
||||||
|
import { DeclarationReference } from "typedoc"
|
||||||
|
|
||||||
|
export default function (theme: MarkdownTheme) {
|
||||||
|
Handlebars.registerHelper(
|
||||||
|
"propertiesComponent",
|
||||||
|
function (this: DeclarationReference) {
|
||||||
|
console.log(this)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
+101
-29
@@ -1,34 +1,106 @@
|
|||||||
import * as Handlebars from "handlebars"
|
import * as Handlebars from "handlebars"
|
||||||
import { Comment, DeclarationReflection } from "typedoc"
|
import { Comment, DeclarationReflection, SignatureReflection } from "typedoc"
|
||||||
import reflectionFomatter from "../../utils/reflection-formatter"
|
import { MarkdownTheme } from "../../theme"
|
||||||
|
import reflectionFormatter from "../../utils/reflection-formatter"
|
||||||
|
import { returnReflectionComponentFormatter } from "../../utils/return-reflection-formatter"
|
||||||
|
import { Parameter } from "../../types"
|
||||||
|
|
||||||
export default function () {
|
export default function (theme: MarkdownTheme) {
|
||||||
Handlebars.registerHelper("returns", function (comment: Comment) {
|
Handlebars.registerHelper(
|
||||||
const md: string[] = []
|
"returns",
|
||||||
|
function (reflection: SignatureReflection) {
|
||||||
if (comment.blockTags?.length) {
|
if (reflection.variant === "signature" && "type" in reflection) {
|
||||||
const tags = comment.blockTags
|
return getReturnFromType(theme, reflection)
|
||||||
.filter((tag) => tag.tag === "@returns")
|
} else if (reflection.comment) {
|
||||||
.map((tag) => {
|
return getReturnFromComment(theme, reflection.comment)
|
||||||
let result = Handlebars.helpers.comment(tag.content)
|
} else {
|
||||||
tag.content.forEach((commentPart) => {
|
return ""
|
||||||
if (
|
}
|
||||||
"target" in commentPart &&
|
|
||||||
commentPart.target instanceof DeclarationReflection
|
|
||||||
) {
|
|
||||||
const content = commentPart.target.children?.map((childItem) =>
|
|
||||||
reflectionFomatter(childItem)
|
|
||||||
)
|
|
||||||
result += `\n\n<details>\n<summary>\n${
|
|
||||||
commentPart.target.name
|
|
||||||
}\n</summary>\n\n${content?.join("\n")}\n\n</details>`
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return result
|
|
||||||
})
|
|
||||||
md.push(tags.join("\n\n"))
|
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return md.join("")
|
function getReturnFromType(
|
||||||
})
|
theme: MarkdownTheme,
|
||||||
|
reflection: SignatureReflection
|
||||||
|
) {
|
||||||
|
const { parameterStyle, parameterComponent } =
|
||||||
|
theme.getFormattingOptionsForLocation()
|
||||||
|
|
||||||
|
if (!reflection.type) {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
const componentItems = returnReflectionComponentFormatter(
|
||||||
|
reflection.type,
|
||||||
|
reflection.project || theme.project,
|
||||||
|
reflection.comment,
|
||||||
|
1
|
||||||
|
)
|
||||||
|
|
||||||
|
if (parameterStyle === "component") {
|
||||||
|
return `<${parameterComponent} parameters={${JSON.stringify(
|
||||||
|
componentItems
|
||||||
|
)}} />`
|
||||||
|
} else {
|
||||||
|
return formatReturnAsList(componentItems)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatReturnAsList(componentItems: Parameter[], level = 1): string {
|
||||||
|
const prefix = `${Array(level - 1)
|
||||||
|
.fill("\t")
|
||||||
|
.join("")}-`
|
||||||
|
return componentItems
|
||||||
|
.map(
|
||||||
|
(item) =>
|
||||||
|
`${prefix}\`${item.name}\`: ${
|
||||||
|
item.optional || item.defaultValue
|
||||||
|
? `(${item.optional ? "optional" : ""}${
|
||||||
|
item.optional && item.defaultValue ? "," : ""
|
||||||
|
}${item.defaultValue ? `default: ${item.defaultValue}` : ""}) `
|
||||||
|
: ""
|
||||||
|
}${item.description}${
|
||||||
|
item.children?.length
|
||||||
|
? `\n${formatReturnAsList(item.children, level + 1)}`
|
||||||
|
: ""
|
||||||
|
}`
|
||||||
|
)
|
||||||
|
.join("\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
function getReturnFromComment(theme: MarkdownTheme, comment: Comment) {
|
||||||
|
const md: string[] = []
|
||||||
|
const { parameterStyle, parameterComponent } =
|
||||||
|
theme.getFormattingOptionsForLocation()
|
||||||
|
|
||||||
|
if (comment.blockTags?.length) {
|
||||||
|
const tags = comment.blockTags
|
||||||
|
.filter((tag) => tag.tag === "@returns")
|
||||||
|
.map((tag) => {
|
||||||
|
let result = Handlebars.helpers.comment(tag.content)
|
||||||
|
tag.content.forEach((commentPart) => {
|
||||||
|
if (
|
||||||
|
"target" in commentPart &&
|
||||||
|
commentPart.target instanceof DeclarationReflection
|
||||||
|
) {
|
||||||
|
const content = commentPart.target.children?.map((childItem) =>
|
||||||
|
reflectionFormatter(childItem, parameterStyle, 1)
|
||||||
|
)
|
||||||
|
result +=
|
||||||
|
parameterStyle === "component"
|
||||||
|
? `\n\n<${parameterComponent} parameters={${JSON.stringify(
|
||||||
|
content
|
||||||
|
)}} title={"${commentPart.target.name}"} />\n\n`
|
||||||
|
: `\n\n<details>\n<summary>\n${
|
||||||
|
commentPart.target.name
|
||||||
|
}\n</summary>\n\n${content?.join("\n")}\n\n</details>`
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return result
|
||||||
|
})
|
||||||
|
md.push(tags.join("\n\n"))
|
||||||
|
}
|
||||||
|
|
||||||
|
return md.join("")
|
||||||
}
|
}
|
||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
import * as Handlebars from "handlebars"
|
||||||
|
import { MarkdownTheme } from "../../theme"
|
||||||
|
|
||||||
|
export default function (theme: MarkdownTheme) {
|
||||||
|
Handlebars.registerHelper(
|
||||||
|
"showPropertiesAsComponent",
|
||||||
|
function (title: string) {
|
||||||
|
const { parameterStyle } = theme.getFormattingOptionsForLocation()
|
||||||
|
|
||||||
|
// console.log(parameterStyle, title)
|
||||||
|
|
||||||
|
return parameterStyle === "component" && title === "Properties"
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
+20
-2
@@ -2,14 +2,15 @@ import * as Handlebars from "handlebars"
|
|||||||
import { DeclarationReflection, ReflectionType } from "typedoc"
|
import { DeclarationReflection, ReflectionType } from "typedoc"
|
||||||
import { MarkdownTheme } from "../../theme"
|
import { MarkdownTheme } from "../../theme"
|
||||||
import { escapeChars, stripLineBreaks } from "../../utils"
|
import { escapeChars, stripLineBreaks } from "../../utils"
|
||||||
import reflectionFomatter from "../../utils/reflection-formatter"
|
|
||||||
import { parseParams } from "../../utils/params-utils"
|
import { parseParams } from "../../utils/params-utils"
|
||||||
import { ReflectionParameterType } from "../../types"
|
import { ReflectionParameterType } from "../../types"
|
||||||
|
import reflectionFormatter from "../../utils/reflection-formatter"
|
||||||
|
|
||||||
export default function (theme: MarkdownTheme) {
|
export default function (theme: MarkdownTheme) {
|
||||||
Handlebars.registerHelper(
|
Handlebars.registerHelper(
|
||||||
"typeDeclarationMembers",
|
"typeDeclarationMembers",
|
||||||
function (this: DeclarationReflection[]) {
|
function (this: DeclarationReflection[]) {
|
||||||
|
const { parameterComponent } = theme.getFormattingOptionsForLocation()
|
||||||
const comments = this.map(
|
const comments = this.map(
|
||||||
(param) => !!param.comment?.hasVisibleComponent()
|
(param) => !!param.comment?.hasVisibleComponent()
|
||||||
)
|
)
|
||||||
@@ -27,6 +28,10 @@ export default function (theme: MarkdownTheme) {
|
|||||||
result = getListMarkdownContent(properties)
|
result = getListMarkdownContent(properties)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
case "component": {
|
||||||
|
result = getComponentMarkdownContent(properties, parameterComponent)
|
||||||
|
break
|
||||||
|
}
|
||||||
case "table": {
|
case "table": {
|
||||||
result = getTableMarkdownContent(properties, hasComments)
|
result = getTableMarkdownContent(properties, hasComments)
|
||||||
break
|
break
|
||||||
@@ -38,11 +43,24 @@ export default function (theme: MarkdownTheme) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getListMarkdownContent(properties: DeclarationReflection[]) {
|
function getListMarkdownContent(properties: DeclarationReflection[]) {
|
||||||
const items = properties.map((property) => reflectionFomatter(property))
|
const items = properties.map((property) =>
|
||||||
|
reflectionFormatter(property, "list")
|
||||||
|
)
|
||||||
|
|
||||||
return items.join("\n")
|
return items.join("\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getComponentMarkdownContent(
|
||||||
|
properties: DeclarationReflection[],
|
||||||
|
parameterComponent?: string
|
||||||
|
) {
|
||||||
|
const parameters = properties.map((property) =>
|
||||||
|
reflectionFormatter(property, "component")
|
||||||
|
)
|
||||||
|
|
||||||
|
return `<${parameterComponent} parameters={${JSON.stringify(parameters)}} />`
|
||||||
|
}
|
||||||
|
|
||||||
function getTableMarkdownContent(
|
function getTableMarkdownContent(
|
||||||
properties: DeclarationReflection[],
|
properties: DeclarationReflection[],
|
||||||
hasComments: boolean
|
hasComments: boolean
|
||||||
|
|||||||
+20
@@ -0,0 +1,20 @@
|
|||||||
|
import * as Handlebars from "handlebars"
|
||||||
|
import { TypeParameterReflection } from "typedoc"
|
||||||
|
import { reflectionComponentFormatter } from "../../utils/reflection-formatter"
|
||||||
|
import { MarkdownTheme } from "../../theme"
|
||||||
|
|
||||||
|
export default function (theme: MarkdownTheme) {
|
||||||
|
Handlebars.registerHelper(
|
||||||
|
"typeParameterComponent",
|
||||||
|
function (this: TypeParameterReflection[]) {
|
||||||
|
const { parameterComponent } = theme.getFormattingOptionsForLocation()
|
||||||
|
const parameters = this.map((parameter) =>
|
||||||
|
reflectionComponentFormatter(parameter, 1)
|
||||||
|
)
|
||||||
|
|
||||||
|
return `<${parameterComponent} parameters={${JSON.stringify(
|
||||||
|
parameters
|
||||||
|
)}} />`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
+4
-2
@@ -1,6 +1,6 @@
|
|||||||
import * as Handlebars from "handlebars"
|
import * as Handlebars from "handlebars"
|
||||||
import { TypeParameterReflection } from "typedoc"
|
import { TypeParameterReflection } from "typedoc"
|
||||||
import reflectionFomatter from "../../utils/reflection-formatter"
|
import reflectionFormatter from "../../utils/reflection-formatter"
|
||||||
|
|
||||||
export default function () {
|
export default function () {
|
||||||
Handlebars.registerHelper(
|
Handlebars.registerHelper(
|
||||||
@@ -12,7 +12,9 @@ export default function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function list(parameters: TypeParameterReflection[]) {
|
function list(parameters: TypeParameterReflection[]) {
|
||||||
const items = parameters.map((parameter) => reflectionFomatter(parameter))
|
const items = parameters.map((parameter) =>
|
||||||
|
reflectionFormatter(parameter, "list")
|
||||||
|
)
|
||||||
|
|
||||||
return items.join("\n")
|
return items.join("\n")
|
||||||
}
|
}
|
||||||
+13
-72
@@ -1,82 +1,23 @@
|
|||||||
import * as Handlebars from "handlebars"
|
import * as Handlebars from "handlebars"
|
||||||
import { TypeParameterReflection } from "typedoc"
|
import { TypeParameterReflection } from "typedoc"
|
||||||
import { stripLineBreaks } from "../../utils"
|
import {
|
||||||
|
getTableHeaders,
|
||||||
|
reflectionTableFormatter,
|
||||||
|
} from "../../utils/reflection-formatter"
|
||||||
|
import { hasTypes } from "../../utils/type-utils"
|
||||||
|
|
||||||
export default function () {
|
export default function () {
|
||||||
Handlebars.registerHelper(
|
Handlebars.registerHelper(
|
||||||
"typeParameterTable",
|
"typeParameterTable",
|
||||||
function (this: TypeParameterReflection[]) {
|
function (this: TypeParameterReflection[]) {
|
||||||
return table(this)
|
const showTypeCol = hasTypes(this)
|
||||||
|
const headers = getTableHeaders(this, showTypeCol)
|
||||||
|
|
||||||
|
const rows = this.map((parameter) => reflectionTableFormatter(parameter))
|
||||||
|
|
||||||
|
return `\n| ${headers.join(" | ")} |\n| ${headers
|
||||||
|
.map(() => ":------")
|
||||||
|
.join(" | ")} |\n${rows.join("")}`
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function table(parameters: TypeParameterReflection[]) {
|
|
||||||
const showTypeCol = hasTypes(parameters)
|
|
||||||
|
|
||||||
const comments = parameters.map(
|
|
||||||
(param: TypeParameterReflection) => !!param.comment?.hasVisibleComponent()
|
|
||||||
)
|
|
||||||
|
|
||||||
const hasComments = !comments.every((value) => !value)
|
|
||||||
|
|
||||||
const headers = ["Name"]
|
|
||||||
|
|
||||||
if (showTypeCol) {
|
|
||||||
headers.push("Type")
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hasComments) {
|
|
||||||
headers.push("Description")
|
|
||||||
}
|
|
||||||
|
|
||||||
const rows = parameters.map((parameter: TypeParameterReflection) => {
|
|
||||||
const row: string[] = []
|
|
||||||
|
|
||||||
row.push(`\`${parameter.name}\``)
|
|
||||||
|
|
||||||
if (showTypeCol) {
|
|
||||||
const typeCol: string[] = []
|
|
||||||
if (!parameter.type && !parameter.default) {
|
|
||||||
typeCol.push(`\`${parameter.name}\``)
|
|
||||||
}
|
|
||||||
if (parameter.type) {
|
|
||||||
typeCol.push(
|
|
||||||
`extends ${Handlebars.helpers.type.call(parameter.type, "object")}`
|
|
||||||
)
|
|
||||||
}
|
|
||||||
if (parameter.default) {
|
|
||||||
if (parameter.type) {
|
|
||||||
typeCol.push(" = ")
|
|
||||||
}
|
|
||||||
typeCol.push(Handlebars.helpers.type.call(parameter.default))
|
|
||||||
}
|
|
||||||
row.push(typeCol.join(""))
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hasComments) {
|
|
||||||
if (parameter.comment?.summary) {
|
|
||||||
row.push(
|
|
||||||
stripLineBreaks(
|
|
||||||
Handlebars.helpers.comment(parameter.comment?.summary)
|
|
||||||
).replace(/\|/g, "\\|")
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
row.push("-")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return `| ${row.join(" | ")} |\n`
|
|
||||||
})
|
|
||||||
|
|
||||||
const output = `\n| ${headers.join(" | ")} |\n| ${headers
|
|
||||||
.map(() => ":------")
|
|
||||||
.join(" | ")} |\n${rows.join("")}`
|
|
||||||
return output
|
|
||||||
}
|
|
||||||
|
|
||||||
function hasTypes(parameters: TypeParameterReflection[]) {
|
|
||||||
const types = (parameters as TypeParameterReflection[]).map(
|
|
||||||
(param) => !!param.type || !!param.default
|
|
||||||
)
|
|
||||||
return !types.every((value) => !value)
|
|
||||||
}
|
|
||||||
+2
@@ -10,6 +10,8 @@ export default function (theme: MarkdownTheme) {
|
|||||||
|
|
||||||
if (parameterStyle === "list") {
|
if (parameterStyle === "list") {
|
||||||
return Handlebars.helpers.typeParameterList.call(this)
|
return Handlebars.helpers.typeParameterList.call(this)
|
||||||
|
} else if (parameterStyle === "component") {
|
||||||
|
return Handlebars.helpers.typeParameterComponent.call(this)
|
||||||
} else {
|
} else {
|
||||||
return Handlebars.helpers.typeParameterTable.call(this)
|
return Handlebars.helpers.typeParameterTable.call(this)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,26 +2,19 @@ import * as Handlebars from "handlebars"
|
|||||||
import {
|
import {
|
||||||
ArrayType,
|
ArrayType,
|
||||||
ConditionalType,
|
ConditionalType,
|
||||||
DeclarationReflection,
|
|
||||||
IndexedAccessType,
|
IndexedAccessType,
|
||||||
InferredType,
|
InferredType,
|
||||||
IntersectionType,
|
IntersectionType,
|
||||||
IntrinsicType,
|
IntrinsicType,
|
||||||
LiteralType,
|
|
||||||
PredicateType,
|
PredicateType,
|
||||||
QueryType,
|
QueryType,
|
||||||
ReferenceType,
|
ReferenceType,
|
||||||
ReflectionType,
|
|
||||||
SignatureReflection,
|
|
||||||
TupleType,
|
TupleType,
|
||||||
TypeOperatorType,
|
TypeOperatorType,
|
||||||
UnionType,
|
UnionType,
|
||||||
UnknownType,
|
UnknownType,
|
||||||
} from "typedoc"
|
} from "typedoc"
|
||||||
import { escapeChars } from "../../utils"
|
import getType, { Collapse } from "../../utils/type-utils"
|
||||||
import { ReflectionParameterType } from "../../types"
|
|
||||||
|
|
||||||
type Collapse = "object" | "function" | "all" | "none"
|
|
||||||
|
|
||||||
export default function () {
|
export default function () {
|
||||||
Handlebars.registerHelper(
|
Handlebars.registerHelper(
|
||||||
@@ -46,267 +39,7 @@ export default function () {
|
|||||||
collapse: Collapse = "none",
|
collapse: Collapse = "none",
|
||||||
emphasis = true
|
emphasis = true
|
||||||
) {
|
) {
|
||||||
if (this instanceof ReferenceType) {
|
return getType(this, collapse, emphasis)
|
||||||
return getReferenceType(this, emphasis)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this instanceof ArrayType && this.elementType) {
|
|
||||||
return getArrayType(this, emphasis)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this instanceof UnionType && this.types) {
|
|
||||||
return getUnionType(this, emphasis)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this instanceof IntersectionType && this.types) {
|
|
||||||
return getIntersectionType(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this instanceof TupleType && this.elements) {
|
|
||||||
return getTupleType(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this instanceof IntrinsicType && this.name) {
|
|
||||||
return getIntrinsicType(this, emphasis)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this instanceof ReflectionType) {
|
|
||||||
return getReflectionType(this, collapse)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this instanceof DeclarationReflection) {
|
|
||||||
return getReflectionType(this, collapse)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this instanceof TypeOperatorType) {
|
|
||||||
return getTypeOperatorType(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this instanceof QueryType) {
|
|
||||||
return getQueryType(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this instanceof ConditionalType) {
|
|
||||||
return getConditionalType(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this instanceof IndexedAccessType) {
|
|
||||||
return getIndexAccessType(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this instanceof UnknownType) {
|
|
||||||
return getUnknownType(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this instanceof InferredType) {
|
|
||||||
return getInferredType(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this instanceof LiteralType) {
|
|
||||||
return getLiteralType(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
return this ? escapeChars(this.toString()) : ""
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function getLiteralType(model: LiteralType) {
|
|
||||||
if (typeof model.value === "bigint") {
|
|
||||||
return `\`${model.value}n\``
|
|
||||||
}
|
|
||||||
return `\`\`${JSON.stringify(model.value)}\`\``
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getReflectionType(
|
|
||||||
model: ReflectionParameterType,
|
|
||||||
collapse: Collapse
|
|
||||||
) {
|
|
||||||
const root = model instanceof ReflectionType ? model.declaration : model
|
|
||||||
if ("signatures" in root && root.signatures) {
|
|
||||||
return collapse === "function" || collapse === "all"
|
|
||||||
? `\`fn\``
|
|
||||||
: getFunctionType(root.signatures)
|
|
||||||
}
|
|
||||||
return collapse === "object" || collapse === "all"
|
|
||||||
? `\`Object\``
|
|
||||||
: getDeclarationType(root as DeclarationReflection)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getDeclarationType(model: DeclarationReflection) {
|
|
||||||
if (model.indexSignature || model.children) {
|
|
||||||
let indexSignature = ""
|
|
||||||
const declarationIndexSignature = model.indexSignature
|
|
||||||
if (declarationIndexSignature) {
|
|
||||||
const key = declarationIndexSignature.parameters
|
|
||||||
? declarationIndexSignature.parameters.map(
|
|
||||||
(param) => `\`[${param.name}: ${param.type}]\``
|
|
||||||
)
|
|
||||||
: ""
|
|
||||||
const obj = Handlebars.helpers.type.call(declarationIndexSignature.type)
|
|
||||||
indexSignature = `${key}: ${obj}; `
|
|
||||||
}
|
|
||||||
const types =
|
|
||||||
model.children &&
|
|
||||||
model.children.map((obj) => {
|
|
||||||
return `\`${obj.name}${
|
|
||||||
obj.flags.isOptional ? "?" : ""
|
|
||||||
}\`: ${Handlebars.helpers.type.call(
|
|
||||||
obj.signatures || obj.children ? obj : obj.type
|
|
||||||
)} ${
|
|
||||||
obj.defaultValue && obj.defaultValue !== "..."
|
|
||||||
? `= ${escapeChars(obj.defaultValue)}`
|
|
||||||
: ""
|
|
||||||
}`
|
|
||||||
})
|
|
||||||
return `{ ${indexSignature ? indexSignature : ""}${
|
|
||||||
types ? types.join("; ") : ""
|
|
||||||
} }${
|
|
||||||
model.defaultValue && model.defaultValue !== "..."
|
|
||||||
? `= ${escapeChars(model.defaultValue)}`
|
|
||||||
: ""
|
|
||||||
}`
|
|
||||||
}
|
|
||||||
return "{}"
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getFunctionType(modelSignatures: SignatureReflection[]) {
|
|
||||||
const functions = modelSignatures.map((fn) => {
|
|
||||||
const typeParams = fn.typeParameters
|
|
||||||
? `<${fn.typeParameters
|
|
||||||
.map((typeParameter) => typeParameter.name)
|
|
||||||
.join(", ")}\\>`
|
|
||||||
: []
|
|
||||||
const params = fn.parameters
|
|
||||||
? fn.parameters.map((param) => {
|
|
||||||
return `${param.flags.isRest ? "..." : ""}\`${param.name}${
|
|
||||||
param.flags.isOptional ? "?" : ""
|
|
||||||
}\`: ${Handlebars.helpers.type.call(param.type ? param.type : param)}`
|
|
||||||
})
|
|
||||||
: []
|
|
||||||
const returns = Handlebars.helpers.type.call(fn.type)
|
|
||||||
return typeParams + `(${params.join(", ")}) => ${returns}`
|
|
||||||
})
|
|
||||||
return functions.join("")
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getReferenceType(model: ReferenceType, emphasis: boolean) {
|
|
||||||
if (model.reflection || (model.name && model.typeArguments)) {
|
|
||||||
const reflection: string[] = []
|
|
||||||
|
|
||||||
if (model.reflection?.url) {
|
|
||||||
reflection.push(
|
|
||||||
emphasis
|
|
||||||
? `[${`\`${model.reflection.name}\``}](${Handlebars.helpers.relativeURL(
|
|
||||||
model.reflection.url
|
|
||||||
)})`
|
|
||||||
: model.reflection.name
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
reflection.push(
|
|
||||||
emphasis
|
|
||||||
? model.externalUrl
|
|
||||||
? `[${`\`${model.name}\``}]( ${model.externalUrl} )`
|
|
||||||
: `\`${model.name}\``
|
|
||||||
: model.name
|
|
||||||
)
|
|
||||||
}
|
|
||||||
if (model.typeArguments && model.typeArguments.length > 0) {
|
|
||||||
reflection.push(
|
|
||||||
`<${model.typeArguments
|
|
||||||
.map((typeArgument) =>
|
|
||||||
Handlebars.helpers.type.call(typeArgument, "none", emphasis)
|
|
||||||
)
|
|
||||||
.join(", ")}\\>`
|
|
||||||
)
|
|
||||||
}
|
|
||||||
return reflection.join("")
|
|
||||||
}
|
|
||||||
return emphasis
|
|
||||||
? model.externalUrl
|
|
||||||
? `[${`\`${model.name}\``}]( ${model.externalUrl} )`
|
|
||||||
: `\`${model.name}\``
|
|
||||||
: escapeChars(model.name)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getArrayType(model: ArrayType, emphasis: boolean) {
|
|
||||||
const arrayType = Handlebars.helpers.type.call(
|
|
||||||
model.elementType,
|
|
||||||
"none",
|
|
||||||
emphasis
|
|
||||||
)
|
|
||||||
return model.elementType.type === "union"
|
|
||||||
? `(${arrayType})[]`
|
|
||||||
: `${arrayType}[]`
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getUnionType(model: UnionType, emphasis: boolean) {
|
|
||||||
return model.types
|
|
||||||
.map((unionType) =>
|
|
||||||
Handlebars.helpers.type.call(unionType, "none", emphasis)
|
|
||||||
)
|
|
||||||
.join(` \\| `)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getIntersectionType(model: IntersectionType) {
|
|
||||||
return model.types
|
|
||||||
.map((intersectionType) => Handlebars.helpers.type.call(intersectionType))
|
|
||||||
.join(" & ")
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getTupleType(model: TupleType) {
|
|
||||||
return `[${model.elements
|
|
||||||
.map((element) => Handlebars.helpers.type.call(element))
|
|
||||||
.join(", ")}]`
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getIntrinsicType(model: IntrinsicType, emphasis: boolean) {
|
|
||||||
return emphasis ? `\`${model.name}\`` : escapeChars(model.name)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getTypeOperatorType(model: TypeOperatorType) {
|
|
||||||
return `${model.operator} ${Handlebars.helpers.type.call(model.target)}`
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getQueryType(model: QueryType) {
|
|
||||||
return `typeof ${Handlebars.helpers.type.call(model.queryType)}`
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getInferredType(model: InferredType) {
|
|
||||||
return `infer ${escapeChars(model.name)}`
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getUnknownType(model: UnknownType) {
|
|
||||||
return escapeChars(model.name)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getConditionalType(model: ConditionalType) {
|
|
||||||
const md: string[] = []
|
|
||||||
if (model.checkType) {
|
|
||||||
md.push(Handlebars.helpers.type.call(model.checkType))
|
|
||||||
}
|
|
||||||
md.push("extends")
|
|
||||||
if (model.extendsType) {
|
|
||||||
md.push(Handlebars.helpers.type.call(model.extendsType))
|
|
||||||
}
|
|
||||||
md.push("?")
|
|
||||||
if (model.trueType) {
|
|
||||||
md.push(Handlebars.helpers.type.call(model.trueType))
|
|
||||||
}
|
|
||||||
md.push(":")
|
|
||||||
if (model.falseType) {
|
|
||||||
md.push(Handlebars.helpers.type.call(model.falseType))
|
|
||||||
}
|
|
||||||
return md.join(" ")
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getIndexAccessType(model: IndexedAccessType) {
|
|
||||||
const md: string[] = []
|
|
||||||
if (model.objectType) {
|
|
||||||
md.push(Handlebars.helpers.type.call(model.objectType))
|
|
||||||
}
|
|
||||||
if (model.indexType) {
|
|
||||||
md.push(`[${Handlebars.helpers.type.call(model.indexType)}]`)
|
|
||||||
}
|
|
||||||
return md.join("")
|
|
||||||
}
|
|
||||||
@@ -1,3 +1,11 @@
|
|||||||
|
{{#with model}}
|
||||||
|
|
||||||
|
{{{frontmatter}}}
|
||||||
|
|
||||||
|
{{/with}}
|
||||||
|
|
||||||
|
{{{mdxImports}}}
|
||||||
|
|
||||||
{{#ifShowBreadcrumbs}}
|
{{#ifShowBreadcrumbs}}
|
||||||
|
|
||||||
{{{breadcrumbs}}}
|
{{{breadcrumbs}}}
|
||||||
|
|||||||
+6
@@ -2,6 +2,12 @@
|
|||||||
|
|
||||||
{{> comment}}
|
{{> comment}}
|
||||||
|
|
||||||
|
{{#if (sectionEnabled "member_declaration_example")}}
|
||||||
|
|
||||||
|
{{{example this 4}}}
|
||||||
|
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
{{#if (sectionEnabled "member_declaration_typeParameters")}}
|
{{#if (sectionEnabled "member_declaration_typeParameters")}}
|
||||||
|
|
||||||
{{#if typeParameters}}
|
{{#if typeParameters}}
|
||||||
|
|||||||
+7
-5
@@ -28,6 +28,12 @@
|
|||||||
|
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
|
{{#if (sectionEnabled "member_signature_example")}}
|
||||||
|
|
||||||
|
{{{example this 4}}}
|
||||||
|
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
{{#if (sectionEnabled "member_signature_parameters")}}
|
{{#if (sectionEnabled "member_signature_parameters")}}
|
||||||
|
|
||||||
{{#if parameters}}
|
{{#if parameters}}
|
||||||
@@ -66,7 +72,7 @@
|
|||||||
|
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
{{#if (getFormattingOption "showReturnSignature")}}
|
{{#if (sectionEnabled "member_signature_returns")}}
|
||||||
|
|
||||||
{{#with type}}
|
{{#with type}}
|
||||||
|
|
||||||
@@ -76,12 +82,8 @@
|
|||||||
|
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
{{#with comment}}
|
|
||||||
|
|
||||||
{{{returns this}}}
|
{{{returns this}}}
|
||||||
|
|
||||||
{{/with}}
|
|
||||||
|
|
||||||
{{#with type}}
|
{{#with type}}
|
||||||
|
|
||||||
{{#if (sectionEnabled "member_signature_declarationSignatures")}}
|
{{#if (sectionEnabled "member_signature_declarationSignatures")}}
|
||||||
|
|||||||
+24
@@ -14,12 +14,24 @@ ___
|
|||||||
|
|
||||||
{{/unless}}
|
{{/unless}}
|
||||||
|
|
||||||
|
{{#if (showPropertiesAsComponent title)}}
|
||||||
|
|
||||||
|
{{#with children}}
|
||||||
|
|
||||||
|
{{{parameterComponent}}}
|
||||||
|
|
||||||
|
{{/with}}
|
||||||
|
|
||||||
|
{{else}}
|
||||||
|
|
||||||
{{#each children}}
|
{{#each children}}
|
||||||
|
|
||||||
{{> member}}
|
{{> member}}
|
||||||
|
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
|
||||||
{{else}}
|
{{else}}
|
||||||
@@ -30,6 +42,16 @@ ___
|
|||||||
|
|
||||||
{{/unless}}
|
{{/unless}}
|
||||||
|
|
||||||
|
{{#if (showPropertiesAsComponent title)}}
|
||||||
|
|
||||||
|
{{#with children}}
|
||||||
|
|
||||||
|
{{{parameterComponent}}}
|
||||||
|
|
||||||
|
{{/with}}
|
||||||
|
|
||||||
|
{{else}}
|
||||||
|
|
||||||
{{#each children}}
|
{{#each children}}
|
||||||
|
|
||||||
{{> member}}
|
{{> member}}
|
||||||
@@ -39,3 +61,5 @@ ___
|
|||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
|
{{/if}}
|
||||||
@@ -1,9 +1,3 @@
|
|||||||
{{#with model}}
|
|
||||||
|
|
||||||
{{{frontmatter}}}
|
|
||||||
|
|
||||||
{{/with}}
|
|
||||||
|
|
||||||
{{> header}}
|
{{> header}}
|
||||||
|
|
||||||
{{#with model.readme}}
|
{{#with model.readme}}
|
||||||
|
|||||||
+6
-6
@@ -1,9 +1,3 @@
|
|||||||
{{#with model}}
|
|
||||||
|
|
||||||
{{{frontmatter}}}
|
|
||||||
|
|
||||||
{{/with}}
|
|
||||||
|
|
||||||
{{> header}}
|
{{> header}}
|
||||||
|
|
||||||
{{> title}}
|
{{> title}}
|
||||||
@@ -22,6 +16,12 @@
|
|||||||
|
|
||||||
{{/with}}
|
{{/with}}
|
||||||
|
|
||||||
|
{{#if (sectionEnabled "reflection_example")}}
|
||||||
|
|
||||||
|
{{{example model 2}}}
|
||||||
|
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
{{#if (sectionEnabled "reflection_typeParameters")}}
|
{{#if (sectionEnabled "reflection_typeParameters")}}
|
||||||
|
|
||||||
{{#if model.typeParameters}}
|
{{#if model.typeParameters}}
|
||||||
|
|||||||
-6
@@ -1,9 +1,3 @@
|
|||||||
{{#with model}}
|
|
||||||
|
|
||||||
{{{frontmatter}}}
|
|
||||||
|
|
||||||
{{/with}}
|
|
||||||
|
|
||||||
{{> header}}
|
{{> header}}
|
||||||
|
|
||||||
{{> title}}
|
{{> title}}
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ export class MarkdownTheme extends Theme {
|
|||||||
preserveAnchorCasing!: boolean
|
preserveAnchorCasing!: boolean
|
||||||
objectLiteralTypeDeclarationStyle: ObjectLiteralDeclarationStyle
|
objectLiteralTypeDeclarationStyle: ObjectLiteralDeclarationStyle
|
||||||
formattingOptions: FormattingOptionsType
|
formattingOptions: FormattingOptionsType
|
||||||
|
mdxOutput: boolean
|
||||||
|
|
||||||
project?: ProjectReflection
|
project?: ProjectReflection
|
||||||
reflection?: DeclarationReflection
|
reflection?: DeclarationReflection
|
||||||
@@ -83,6 +84,7 @@ export class MarkdownTheme extends Theme {
|
|||||||
this.formattingOptions = this.getOption(
|
this.formattingOptions = this.getOption(
|
||||||
"formatting"
|
"formatting"
|
||||||
) as FormattingOptionsType
|
) as FormattingOptionsType
|
||||||
|
this.mdxOutput = this.getOption("mdxOutput") as boolean
|
||||||
|
|
||||||
this.listenTo(this.owner, {
|
this.listenTo(this.owner, {
|
||||||
[RendererEvent.BEGIN]: this.onBeginRenderer,
|
[RendererEvent.BEGIN]: this.onBeginRenderer,
|
||||||
@@ -162,7 +164,12 @@ export class MarkdownTheme extends Theme {
|
|||||||
}
|
}
|
||||||
|
|
||||||
toUrl(mapping: Mapping, reflection: DeclarationReflection) {
|
toUrl(mapping: Mapping, reflection: DeclarationReflection) {
|
||||||
return mapping.directory + "/" + this.getUrl(reflection) + ".md"
|
return (
|
||||||
|
mapping.directory +
|
||||||
|
"/" +
|
||||||
|
this.getUrl(reflection) +
|
||||||
|
(this.mdxOutput ? ".mdx" : ".md")
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
getUrl(reflection: Reflection, relative?: Reflection): string {
|
getUrl(reflection: Reflection, relative?: Reflection): string {
|
||||||
@@ -364,7 +371,7 @@ export class MarkdownTheme extends Theme {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get globalsFile() {
|
get globalsFile() {
|
||||||
return "modules.md"
|
return `modules.${this.mdxOutput ? "mdx" : "md"}`
|
||||||
}
|
}
|
||||||
|
|
||||||
getFormattingOptionsForLocation(): FormattingOptionType {
|
getFormattingOptionsForLocation(): FormattingOptionType {
|
||||||
|
|||||||
@@ -8,14 +8,14 @@ import {
|
|||||||
TypeParameterReflection,
|
TypeParameterReflection,
|
||||||
} from "typedoc"
|
} from "typedoc"
|
||||||
|
|
||||||
export type ParameterStyle = "table" | "list"
|
export type ParameterStyle = "table" | "list" | "component"
|
||||||
|
|
||||||
export type ReflectionTitleOptions = {
|
export type ReflectionTitleOptions = {
|
||||||
typeParameters?: boolean
|
typeParameters?: boolean
|
||||||
kind?: boolean
|
kind?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ObjectLiteralDeclarationStyle = "table" | "list"
|
export type ObjectLiteralDeclarationStyle = "table" | "list" | "component"
|
||||||
|
|
||||||
export type SectionKey =
|
export type SectionKey =
|
||||||
| "comment"
|
| "comment"
|
||||||
@@ -23,6 +23,7 @@ export type SectionKey =
|
|||||||
| "member_declaration_indexSignature"
|
| "member_declaration_indexSignature"
|
||||||
| "member_declaration_signatures"
|
| "member_declaration_signatures"
|
||||||
| "member_declaration_typeDeclaration"
|
| "member_declaration_typeDeclaration"
|
||||||
|
| "member_declaration_example"
|
||||||
| "member_getteSetter_getSignature"
|
| "member_getteSetter_getSignature"
|
||||||
| "member_getteSetter_setSignature"
|
| "member_getteSetter_setSignature"
|
||||||
| "member_signatures"
|
| "member_signatures"
|
||||||
@@ -33,10 +34,10 @@ export type SectionKey =
|
|||||||
| "member_signature_comment"
|
| "member_signature_comment"
|
||||||
| "member_signature_typeParameters"
|
| "member_signature_typeParameters"
|
||||||
| "member_signature_parameters"
|
| "member_signature_parameters"
|
||||||
| "showReturnSignature"
|
| "member_signature_example"
|
||||||
|
| "member_signature_returns"
|
||||||
| "member_signature_declarationSignatures"
|
| "member_signature_declarationSignatures"
|
||||||
| "member_signature_declarationChildren"
|
| "member_signature_declarationChildren"
|
||||||
| "member_signature_comment"
|
|
||||||
| "member_signature_sources"
|
| "member_signature_sources"
|
||||||
| "member_sources_implementationOf"
|
| "member_sources_implementationOf"
|
||||||
| "member_sources_inheritedFrom"
|
| "member_sources_inheritedFrom"
|
||||||
@@ -70,8 +71,9 @@ export type FormattingOptionType = {
|
|||||||
showCommentsAsHeader?: boolean
|
showCommentsAsHeader?: boolean
|
||||||
showCommentsAsDetails?: boolean
|
showCommentsAsDetails?: boolean
|
||||||
parameterStyle?: ParameterStyle
|
parameterStyle?: ParameterStyle
|
||||||
showReturnSignature?: boolean
|
|
||||||
frontmatterData?: Record<string, unknown>
|
frontmatterData?: Record<string, unknown>
|
||||||
|
parameterComponent?: string
|
||||||
|
mdxImports?: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export type FormattingOptionsType = {
|
export type FormattingOptionsType = {
|
||||||
@@ -90,6 +92,15 @@ export type Mapping = {
|
|||||||
template: (pageEvent: PageEvent<ContainerReflection>) => string
|
template: (pageEvent: PageEvent<ContainerReflection>) => string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type Parameter = {
|
||||||
|
name: string
|
||||||
|
type: string
|
||||||
|
optional?: boolean
|
||||||
|
defaultValue?: string
|
||||||
|
description?: string
|
||||||
|
children?: Parameter[]
|
||||||
|
}
|
||||||
|
|
||||||
export class NavigationItem {
|
export class NavigationItem {
|
||||||
title: string
|
title: string
|
||||||
url: string
|
url: string
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ export function formatContents(contents: string) {
|
|||||||
|
|
||||||
export function escapeChars(str: string) {
|
export function escapeChars(str: string) {
|
||||||
return str
|
return str
|
||||||
|
.replace(/>/g, "\\>")
|
||||||
.replace(/>/g, "\\>")
|
.replace(/>/g, "\\>")
|
||||||
.replace(/_/g, "\\_")
|
.replace(/_/g, "\\_")
|
||||||
.replace(/`/g, "\\`")
|
.replace(/`/g, "\\`")
|
||||||
|
|||||||
+192
-15
@@ -1,14 +1,38 @@
|
|||||||
import { Comment, DeclarationReflection, ReflectionType } from "typedoc"
|
import {
|
||||||
|
Comment,
|
||||||
|
DeclarationReflection,
|
||||||
|
ProjectReflection,
|
||||||
|
ReflectionType,
|
||||||
|
SomeType,
|
||||||
|
} from "typedoc"
|
||||||
import * as Handlebars from "handlebars"
|
import * as Handlebars from "handlebars"
|
||||||
import { stripLineBreaks } from "../utils"
|
import { stripLineBreaks } from "../utils"
|
||||||
import { ReflectionParameterType } from "../types"
|
import { Parameter, ParameterStyle, ReflectionParameterType } from "../types"
|
||||||
|
import getType, { getReflectionType } from "./type-utils"
|
||||||
|
|
||||||
const MAX_LEVEL = 3
|
const MAX_LEVEL = 3
|
||||||
|
|
||||||
export default function reflectionFomatter(
|
export default function reflectionFormatter(
|
||||||
|
reflection: ReflectionParameterType,
|
||||||
|
type: ParameterStyle = "table",
|
||||||
|
level = 1
|
||||||
|
): string | Parameter {
|
||||||
|
switch (type) {
|
||||||
|
case "list":
|
||||||
|
return reflectionListFormatter(reflection, level)
|
||||||
|
case "component":
|
||||||
|
return reflectionComponentFormatter(reflection, level)
|
||||||
|
case "table":
|
||||||
|
return reflectionTableFormatter(reflection)
|
||||||
|
default:
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function reflectionListFormatter(
|
||||||
reflection: ReflectionParameterType,
|
reflection: ReflectionParameterType,
|
||||||
level = 1
|
level = 1
|
||||||
) {
|
): string {
|
||||||
const prefix = `${Array(level - 1)
|
const prefix = `${Array(level - 1)
|
||||||
.fill("\t")
|
.fill("\t")
|
||||||
.join("")}-`
|
.join("")}-`
|
||||||
@@ -25,16 +49,17 @@ export default function reflectionFomatter(
|
|||||||
|
|
||||||
if (comments) {
|
if (comments) {
|
||||||
item += stripLineBreaks(Handlebars.helpers.comments(comments))
|
item += stripLineBreaks(Handlebars.helpers.comments(comments))
|
||||||
|
}
|
||||||
|
|
||||||
|
const hasChildren = "children" in reflection && reflection.children?.length
|
||||||
|
|
||||||
|
if ((reflection.type || hasChildren) && level + 1 <= MAX_LEVEL) {
|
||||||
|
const children = hasChildren
|
||||||
|
? reflection.children
|
||||||
|
: getTypeChildren(reflection.type!, reflection.project)
|
||||||
const itemChildren: string[] = []
|
const itemChildren: string[] = []
|
||||||
comments.summary.forEach((commentSummary) => {
|
children?.forEach((childItem) => {
|
||||||
if ("target" in commentSummary) {
|
itemChildren.push(reflectionListFormatter(childItem, level + 1))
|
||||||
const targetReflection = commentSummary.target as DeclarationReflection
|
|
||||||
if (targetReflection.children && level + 1 <= MAX_LEVEL) {
|
|
||||||
targetReflection.children.forEach((childItem) => {
|
|
||||||
itemChildren.push(reflectionFomatter(childItem, level + 1))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
if (itemChildren.length) {
|
if (itemChildren.length) {
|
||||||
// TODO maybe we should check the type of the reflection and replace
|
// TODO maybe we should check the type of the reflection and replace
|
||||||
@@ -50,7 +75,120 @@ export default function reflectionFomatter(
|
|||||||
return item
|
return item
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDefaultValue(parameter: ReflectionParameterType): string | null {
|
export function reflectionComponentFormatter(
|
||||||
|
reflection: ReflectionParameterType,
|
||||||
|
level = 1
|
||||||
|
): Parameter {
|
||||||
|
const defaultValue = getDefaultValue(reflection) || ""
|
||||||
|
const optional = reflection.flags.isOptional
|
||||||
|
const comments = getComments(reflection)
|
||||||
|
const componentItem: Parameter = {
|
||||||
|
name: reflection.name,
|
||||||
|
type: reflection.type
|
||||||
|
? getType(reflection.type, "object")
|
||||||
|
: getReflectionType(reflection, "object"),
|
||||||
|
description: comments
|
||||||
|
? stripLineBreaks(Handlebars.helpers.comments(comments))
|
||||||
|
: "",
|
||||||
|
optional,
|
||||||
|
defaultValue,
|
||||||
|
children: [],
|
||||||
|
}
|
||||||
|
|
||||||
|
const hasChildren = "children" in reflection && reflection.children?.length
|
||||||
|
|
||||||
|
if ((reflection.type || hasChildren) && level + 1 <= MAX_LEVEL) {
|
||||||
|
const children = hasChildren
|
||||||
|
? reflection.children
|
||||||
|
: getTypeChildren(reflection.type!, reflection.project)
|
||||||
|
children?.forEach((childItem) => {
|
||||||
|
componentItem.children?.push(
|
||||||
|
reflectionComponentFormatter(childItem, level + 1)
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return componentItem
|
||||||
|
}
|
||||||
|
|
||||||
|
export function reflectionTableFormatter(
|
||||||
|
parameter: ReflectionParameterType
|
||||||
|
): string {
|
||||||
|
const showDefaults = hasDefaultValues([parameter])
|
||||||
|
|
||||||
|
const hasComments = !!parameter.comment?.hasVisibleComponent()
|
||||||
|
|
||||||
|
const row: string[] = []
|
||||||
|
|
||||||
|
const nbsp = " " // ? <== Unicode no-break space character
|
||||||
|
const rest = parameter.flags.isRest ? "..." : ""
|
||||||
|
const optional = parameter.flags.isOptional ? "?" : ""
|
||||||
|
|
||||||
|
const isDestructuredParam = parameter.name == "__namedParameters"
|
||||||
|
const isDestructuredParamProp =
|
||||||
|
parameter.name.startsWith("__namedParameters.")
|
||||||
|
|
||||||
|
if (isDestructuredParam) {
|
||||||
|
row.push(`\`${rest}«destructured»\``)
|
||||||
|
} else if (isDestructuredParamProp) {
|
||||||
|
row.push(`›${nbsp}\`${rest}${parameter.name.slice(18)}${optional}\``)
|
||||||
|
} else {
|
||||||
|
row.push(`\`${rest}${parameter.name}${optional}\``)
|
||||||
|
}
|
||||||
|
|
||||||
|
row.push(
|
||||||
|
parameter.type
|
||||||
|
? Handlebars.helpers.type.call(parameter.type, "object")
|
||||||
|
: getReflectionType(parameter, "object")
|
||||||
|
)
|
||||||
|
|
||||||
|
if (showDefaults) {
|
||||||
|
row.push(getDefaultValue(parameter) || "")
|
||||||
|
}
|
||||||
|
if (hasComments) {
|
||||||
|
const comments = getComments(parameter)
|
||||||
|
if (comments) {
|
||||||
|
row.push(
|
||||||
|
stripLineBreaks(Handlebars.helpers.comments(comments)).replace(
|
||||||
|
/\|/g,
|
||||||
|
"\\|"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
row.push("-")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return `| ${row.join(" | ")} |\n`
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getTableHeaders(
|
||||||
|
parameters: ReflectionParameterType[],
|
||||||
|
showTypeHeader?: boolean
|
||||||
|
): string[] {
|
||||||
|
const showDefaults = hasDefaultValues(parameters)
|
||||||
|
const hasComments = parameters.some(
|
||||||
|
(parameter) => !!parameter.comment?.hasVisibleComponent()
|
||||||
|
)
|
||||||
|
const headers = ["Name"]
|
||||||
|
|
||||||
|
if (showTypeHeader) {
|
||||||
|
headers.push("Type")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (showDefaults) {
|
||||||
|
headers.push("Default value")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasComments) {
|
||||||
|
headers.push("Description")
|
||||||
|
}
|
||||||
|
|
||||||
|
return headers
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getDefaultValue(
|
||||||
|
parameter: ReflectionParameterType
|
||||||
|
): string | null {
|
||||||
if (!("defaultValue" in parameter)) {
|
if (!("defaultValue" in parameter)) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
@@ -59,7 +197,21 @@ function getDefaultValue(parameter: ReflectionParameterType): string | null {
|
|||||||
: null
|
: null
|
||||||
}
|
}
|
||||||
|
|
||||||
function getComments(parameter: ReflectionParameterType): Comment | undefined {
|
export function hasDefaultValues(parameters: ReflectionParameterType[]) {
|
||||||
|
const defaultValues = (parameters as ReflectionParameterType[]).map(
|
||||||
|
(param) =>
|
||||||
|
"defaultValue" in param &&
|
||||||
|
param.defaultValue !== "{}" &&
|
||||||
|
param.defaultValue !== "..." &&
|
||||||
|
!!param.defaultValue
|
||||||
|
)
|
||||||
|
|
||||||
|
return !defaultValues.every((value) => !value)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getComments(
|
||||||
|
parameter: ReflectionParameterType
|
||||||
|
): Comment | undefined {
|
||||||
if (parameter.type instanceof ReflectionType) {
|
if (parameter.type instanceof ReflectionType) {
|
||||||
if (
|
if (
|
||||||
parameter.type?.declaration?.signatures &&
|
parameter.type?.declaration?.signatures &&
|
||||||
@@ -70,3 +222,28 @@ function getComments(parameter: ReflectionParameterType): Comment | undefined {
|
|||||||
}
|
}
|
||||||
return parameter.comment
|
return parameter.comment
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getTypeChildren(
|
||||||
|
reflectionType: SomeType,
|
||||||
|
project: ProjectReflection
|
||||||
|
) {
|
||||||
|
let children: DeclarationReflection[] = []
|
||||||
|
|
||||||
|
switch (reflectionType.type) {
|
||||||
|
case "reference":
|
||||||
|
// eslint-disable-next-line no-case-declarations
|
||||||
|
const referencedReflection = project.getChildByName(reflectionType.name)
|
||||||
|
|
||||||
|
if (
|
||||||
|
referencedReflection instanceof DeclarationReflection &&
|
||||||
|
referencedReflection.children
|
||||||
|
) {
|
||||||
|
children = referencedReflection.children
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case "array":
|
||||||
|
children = getTypeChildren(reflectionType.elementType, project)
|
||||||
|
}
|
||||||
|
|
||||||
|
return children
|
||||||
|
}
|
||||||
+180
@@ -0,0 +1,180 @@
|
|||||||
|
import {
|
||||||
|
Comment,
|
||||||
|
DeclarationReflection,
|
||||||
|
ProjectReflection,
|
||||||
|
ReflectionFlags,
|
||||||
|
SomeType,
|
||||||
|
} from "typedoc"
|
||||||
|
import * as Handlebars from "handlebars"
|
||||||
|
import getType from "./type-utils"
|
||||||
|
import { Parameter } from "../types"
|
||||||
|
import {
|
||||||
|
getDefaultValue,
|
||||||
|
reflectionComponentFormatter,
|
||||||
|
} from "./reflection-formatter"
|
||||||
|
|
||||||
|
const MAX_LEVEL = 3
|
||||||
|
|
||||||
|
export function returnReflectionComponentFormatter(
|
||||||
|
reflectionType: SomeType,
|
||||||
|
project: ProjectReflection,
|
||||||
|
comment?: Comment,
|
||||||
|
level = 1
|
||||||
|
): Parameter[] {
|
||||||
|
const typeName = getType(reflectionType, "object", false)
|
||||||
|
const type = getType(reflectionType, "object")
|
||||||
|
const componentItem: Parameter[] = []
|
||||||
|
if (reflectionType.type === "reference") {
|
||||||
|
// put type name as a title and its referenced items as children.
|
||||||
|
if (reflectionType.typeArguments) {
|
||||||
|
const parentKey = componentItem.push({
|
||||||
|
name: "name" in reflectionType ? reflectionType.name : typeName,
|
||||||
|
type,
|
||||||
|
optional:
|
||||||
|
"flags" in reflectionType
|
||||||
|
? (reflectionType.flags as ReflectionFlags).isOptional
|
||||||
|
: false,
|
||||||
|
defaultValue:
|
||||||
|
"declaration" in reflectionType
|
||||||
|
? getDefaultValue(
|
||||||
|
reflectionType.declaration as DeclarationReflection
|
||||||
|
) || ""
|
||||||
|
: "",
|
||||||
|
description: comment ? getReturnComment(comment) : "",
|
||||||
|
children: [],
|
||||||
|
})
|
||||||
|
if (!isOnlyVoid(reflectionType.typeArguments) && level + 1 <= MAX_LEVEL) {
|
||||||
|
reflectionType.typeArguments.forEach((typeArg) => {
|
||||||
|
const typeArgComponent = returnReflectionComponentFormatter(
|
||||||
|
typeArg,
|
||||||
|
project,
|
||||||
|
undefined,
|
||||||
|
level + 1
|
||||||
|
)
|
||||||
|
if (typeArgComponent.length) {
|
||||||
|
componentItem[parentKey - 1].children?.push(...typeArgComponent)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} else if (reflectionType.reflection) {
|
||||||
|
componentItem.push(
|
||||||
|
reflectionComponentFormatter(
|
||||||
|
reflectionType.reflection as DeclarationReflection,
|
||||||
|
level
|
||||||
|
)
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
// try to retrieve reflection by its name
|
||||||
|
const reflection = project.getChildByName(reflectionType.name)
|
||||||
|
if (reflection) {
|
||||||
|
componentItem.push(
|
||||||
|
reflectionComponentFormatter(
|
||||||
|
reflection as DeclarationReflection,
|
||||||
|
level
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (reflectionType.type === "array") {
|
||||||
|
const parentKey = componentItem.push({
|
||||||
|
name:
|
||||||
|
"name" in reflectionType ? (reflectionType.name as string) : typeName,
|
||||||
|
type,
|
||||||
|
optional:
|
||||||
|
"flags" in reflectionType
|
||||||
|
? (reflectionType.flags as ReflectionFlags).isOptional
|
||||||
|
: false,
|
||||||
|
defaultValue:
|
||||||
|
"declaration" in reflectionType
|
||||||
|
? getDefaultValue(
|
||||||
|
reflectionType.declaration as DeclarationReflection
|
||||||
|
) || ""
|
||||||
|
: "",
|
||||||
|
description: comment ? getReturnComment(comment) : "",
|
||||||
|
children: [],
|
||||||
|
})
|
||||||
|
if (level + 1 <= MAX_LEVEL) {
|
||||||
|
const elementTypeItem = returnReflectionComponentFormatter(
|
||||||
|
reflectionType.elementType,
|
||||||
|
project,
|
||||||
|
undefined,
|
||||||
|
level + 1
|
||||||
|
)
|
||||||
|
if (elementTypeItem.length) {
|
||||||
|
componentItem[parentKey - 1].children?.push(...elementTypeItem)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (reflectionType.type === "tuple") {
|
||||||
|
let pushTo: Parameter[] = []
|
||||||
|
if (level === 1) {
|
||||||
|
const parentKey = componentItem.push({
|
||||||
|
name:
|
||||||
|
"name" in reflectionType ? (reflectionType.name as string) : typeName,
|
||||||
|
type,
|
||||||
|
optional:
|
||||||
|
"flags" in reflectionType
|
||||||
|
? (reflectionType.flags as ReflectionFlags).isOptional
|
||||||
|
: false,
|
||||||
|
defaultValue:
|
||||||
|
"declaration" in reflectionType
|
||||||
|
? getDefaultValue(
|
||||||
|
reflectionType.declaration as DeclarationReflection
|
||||||
|
) || ""
|
||||||
|
: "",
|
||||||
|
description: comment ? getReturnComment(comment) : "",
|
||||||
|
children: [],
|
||||||
|
})
|
||||||
|
pushTo = componentItem[parentKey - 1].children!
|
||||||
|
} else {
|
||||||
|
pushTo = componentItem
|
||||||
|
}
|
||||||
|
if (level + 1 <= MAX_LEVEL) {
|
||||||
|
reflectionType.elements.forEach((element) => {
|
||||||
|
const elementTypeItem = returnReflectionComponentFormatter(
|
||||||
|
element,
|
||||||
|
project,
|
||||||
|
undefined,
|
||||||
|
level + 1
|
||||||
|
)
|
||||||
|
if (elementTypeItem.length) {
|
||||||
|
pushTo.push(...elementTypeItem)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// put type as the only component.
|
||||||
|
componentItem.push({
|
||||||
|
name: "name" in reflectionType ? reflectionType.name : typeName,
|
||||||
|
type,
|
||||||
|
optional:
|
||||||
|
"flags" in reflectionType
|
||||||
|
? (reflectionType.flags as ReflectionFlags).isOptional
|
||||||
|
: true,
|
||||||
|
defaultValue:
|
||||||
|
"declaration" in reflectionType
|
||||||
|
? getDefaultValue(reflectionType.declaration) || ""
|
||||||
|
: "",
|
||||||
|
description: comment ? getReturnComment(comment) : "",
|
||||||
|
children: [],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return componentItem
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getReturnComment(comment: Comment): string {
|
||||||
|
if (!comment.blockTags?.length) {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
return comment.blockTags
|
||||||
|
.filter((tag) => tag.tag === "@returns")
|
||||||
|
.map((tag) => Handlebars.helpers.comment(tag.content))
|
||||||
|
.join("\n\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isOnlyVoid(reflectionTypes: SomeType[]) {
|
||||||
|
return reflectionTypes.every(
|
||||||
|
(type) => type.type === "intrinsic" && type.name === "void"
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,300 @@
|
|||||||
|
import {
|
||||||
|
ArrayType,
|
||||||
|
ConditionalType,
|
||||||
|
DeclarationReflection,
|
||||||
|
IndexedAccessType,
|
||||||
|
InferredType,
|
||||||
|
IntersectionType,
|
||||||
|
IntrinsicType,
|
||||||
|
LiteralType,
|
||||||
|
QueryType,
|
||||||
|
ReferenceType,
|
||||||
|
ReflectionType,
|
||||||
|
SignatureReflection,
|
||||||
|
SomeType,
|
||||||
|
TupleType,
|
||||||
|
TypeOperatorType,
|
||||||
|
TypeParameterReflection,
|
||||||
|
UnionType,
|
||||||
|
UnknownType,
|
||||||
|
} from "typedoc"
|
||||||
|
import * as Handlebars from "handlebars"
|
||||||
|
import { ReflectionParameterType } from "../types"
|
||||||
|
import { escapeChars } from "../utils"
|
||||||
|
|
||||||
|
export type Collapse = "object" | "function" | "all" | "none"
|
||||||
|
|
||||||
|
export default function getType(
|
||||||
|
reflectionType: SomeType,
|
||||||
|
collapse: Collapse = "none",
|
||||||
|
emphasis = true
|
||||||
|
): string {
|
||||||
|
if (reflectionType instanceof ReferenceType) {
|
||||||
|
return getReferenceType(reflectionType, emphasis)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reflectionType instanceof ArrayType && reflectionType.elementType) {
|
||||||
|
return getArrayType(reflectionType, emphasis)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reflectionType instanceof UnionType && reflectionType.types) {
|
||||||
|
return getUnionType(reflectionType, emphasis)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reflectionType instanceof IntersectionType && reflectionType.types) {
|
||||||
|
return getIntersectionType(reflectionType)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reflectionType instanceof TupleType && reflectionType.elements) {
|
||||||
|
return getTupleType(reflectionType)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reflectionType instanceof IntrinsicType && reflectionType.name) {
|
||||||
|
return getIntrinsicType(reflectionType, emphasis)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reflectionType instanceof ReflectionType) {
|
||||||
|
return getReflectionType(reflectionType.declaration, collapse)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reflectionType instanceof DeclarationReflection) {
|
||||||
|
return getReflectionType(reflectionType, collapse)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reflectionType instanceof TypeOperatorType) {
|
||||||
|
return getTypeOperatorType(reflectionType)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reflectionType instanceof QueryType) {
|
||||||
|
return getQueryType(reflectionType)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reflectionType instanceof ConditionalType) {
|
||||||
|
return getConditionalType(reflectionType)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reflectionType instanceof IndexedAccessType) {
|
||||||
|
return getIndexAccessType(reflectionType)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reflectionType instanceof UnknownType) {
|
||||||
|
return getUnknownType(reflectionType)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reflectionType instanceof InferredType) {
|
||||||
|
return getInferredType(reflectionType)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reflectionType instanceof LiteralType) {
|
||||||
|
return getLiteralType(reflectionType)
|
||||||
|
}
|
||||||
|
|
||||||
|
return reflectionType ? escapeChars(reflectionType.toString()) : ""
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getReflectionType(
|
||||||
|
model: ReflectionParameterType,
|
||||||
|
collapse: Collapse
|
||||||
|
): string {
|
||||||
|
if ("signatures" in model && model.signatures) {
|
||||||
|
return collapse === "function" || collapse === "all"
|
||||||
|
? `\`fn\``
|
||||||
|
: getFunctionType(model.signatures)
|
||||||
|
}
|
||||||
|
return collapse === "object" || collapse === "all"
|
||||||
|
? `\`object\``
|
||||||
|
: getDeclarationType(model as DeclarationReflection)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getDeclarationType(model: DeclarationReflection): string {
|
||||||
|
if (model.indexSignature || model.children) {
|
||||||
|
let indexSignature = ""
|
||||||
|
const declarationIndexSignature = model.indexSignature
|
||||||
|
if (declarationIndexSignature) {
|
||||||
|
const key = declarationIndexSignature.parameters
|
||||||
|
? declarationIndexSignature.parameters.map(
|
||||||
|
(param) => `\`[${param.name}: ${param.type}]\``
|
||||||
|
)
|
||||||
|
: ""
|
||||||
|
const obj = declarationIndexSignature.type
|
||||||
|
? getType(declarationIndexSignature.type)
|
||||||
|
: ""
|
||||||
|
indexSignature = `${key}: ${obj}; `
|
||||||
|
}
|
||||||
|
const types =
|
||||||
|
model.children &&
|
||||||
|
model.children.map((obj) => {
|
||||||
|
return `\`${obj.name}${obj.flags.isOptional ? "?" : ""}\`: ${
|
||||||
|
obj.type ? getType(obj.type) : escapeChars(obj.toString())
|
||||||
|
} ${
|
||||||
|
obj.defaultValue && obj.defaultValue !== "..."
|
||||||
|
? `= ${escapeChars(obj.defaultValue)}`
|
||||||
|
: ""
|
||||||
|
}`
|
||||||
|
})
|
||||||
|
return `{ ${indexSignature ? indexSignature : ""}${
|
||||||
|
types ? types.join("; ") : ""
|
||||||
|
} }${
|
||||||
|
model.defaultValue && model.defaultValue !== "..."
|
||||||
|
? `= ${escapeChars(model.defaultValue)}`
|
||||||
|
: ""
|
||||||
|
}`
|
||||||
|
}
|
||||||
|
return "{}"
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getFunctionType(
|
||||||
|
modelSignatures: SignatureReflection[]
|
||||||
|
): string {
|
||||||
|
const functions = modelSignatures.map((fn) => {
|
||||||
|
const typeParams = fn.typeParameters
|
||||||
|
? `<${fn.typeParameters
|
||||||
|
.map((typeParameter) => typeParameter.name)
|
||||||
|
.join(", ")}\\>`
|
||||||
|
: []
|
||||||
|
const params = fn.parameters
|
||||||
|
? fn.parameters.map((param) => {
|
||||||
|
return `${param.flags.isRest ? "..." : ""}\`${param.name}${
|
||||||
|
param.flags.isOptional ? "?" : ""
|
||||||
|
}\`: ${
|
||||||
|
param.type ? getType(param.type) : escapeChars(param.toString())
|
||||||
|
}`
|
||||||
|
})
|
||||||
|
: []
|
||||||
|
const returns = fn.type ? getType(fn.type) : escapeChars(fn.toString())
|
||||||
|
return typeParams + `(${params.join(", ")}) => ${returns}`
|
||||||
|
})
|
||||||
|
return functions.join("")
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getLiteralType(model: LiteralType): string {
|
||||||
|
if (typeof model.value === "bigint") {
|
||||||
|
return `\`${model.value}n\``
|
||||||
|
}
|
||||||
|
return `\`\`${JSON.stringify(model.value)}\`\``
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getReferenceType(
|
||||||
|
model: ReferenceType,
|
||||||
|
emphasis: boolean
|
||||||
|
): string {
|
||||||
|
const shouldShowLink = emphasis && model.name !== "Record"
|
||||||
|
if (model.reflection || (model.name && model.typeArguments)) {
|
||||||
|
const reflection: string[] = []
|
||||||
|
|
||||||
|
if (model.reflection?.url) {
|
||||||
|
reflection.push(
|
||||||
|
shouldShowLink
|
||||||
|
? `[${`\`${model.reflection.name}\``}](${Handlebars.helpers.relativeURL(
|
||||||
|
model.reflection.url
|
||||||
|
)})`
|
||||||
|
: model.reflection.name
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
reflection.push(
|
||||||
|
shouldShowLink
|
||||||
|
? model.externalUrl
|
||||||
|
? `[${`\`${model.name}\``}]( ${model.externalUrl} )`
|
||||||
|
: `\`${model.name}\``
|
||||||
|
: model.name
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (model.typeArguments && model.typeArguments.length > 0) {
|
||||||
|
reflection.push(
|
||||||
|
`<${model.typeArguments
|
||||||
|
.map((typeArgument) => getType(typeArgument, "none", emphasis))
|
||||||
|
.join(", ")}\\>`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return reflection.join("")
|
||||||
|
}
|
||||||
|
return shouldShowLink
|
||||||
|
? model.externalUrl
|
||||||
|
? `[${`\`${model.name}\``}]( ${model.externalUrl} )`
|
||||||
|
: `\`${model.name}\``
|
||||||
|
: escapeChars(model.name)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getArrayType(model: ArrayType, emphasis: boolean): string {
|
||||||
|
const arrayType = getType(model.elementType, "none", emphasis)
|
||||||
|
return model.elementType.type === "union"
|
||||||
|
? `(${arrayType})[]`
|
||||||
|
: `${arrayType}[]`
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getUnionType(model: UnionType, emphasis: boolean): string {
|
||||||
|
return model.types
|
||||||
|
.map((unionType) => getType(unionType, "none", emphasis))
|
||||||
|
.join(` \\| `)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getIntersectionType(model: IntersectionType): string {
|
||||||
|
return model.types
|
||||||
|
.map((intersectionType) => getType(intersectionType))
|
||||||
|
.join(" & ")
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getTupleType(model: TupleType): string {
|
||||||
|
return `[${model.elements.map((element) => getType(element)).join(", ")}]`
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getIntrinsicType(
|
||||||
|
model: IntrinsicType,
|
||||||
|
emphasis: boolean
|
||||||
|
): string {
|
||||||
|
return emphasis ? `\`${model.name}\`` : escapeChars(model.name)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getTypeOperatorType(model: TypeOperatorType): string {
|
||||||
|
return `${model.operator} ${getType(model.target)}`
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getQueryType(model: QueryType): string {
|
||||||
|
return `typeof ${getType(model.queryType)}`
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getInferredType(model: InferredType): string {
|
||||||
|
return `infer ${escapeChars(model.name)}`
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getUnknownType(model: UnknownType): string {
|
||||||
|
return escapeChars(model.name)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getConditionalType(model: ConditionalType): string {
|
||||||
|
const md: string[] = []
|
||||||
|
if (model.checkType) {
|
||||||
|
md.push(getType(model.checkType))
|
||||||
|
}
|
||||||
|
md.push("extends")
|
||||||
|
if (model.extendsType) {
|
||||||
|
md.push(getType(model.extendsType))
|
||||||
|
}
|
||||||
|
md.push("?")
|
||||||
|
if (model.trueType) {
|
||||||
|
md.push(getType(model.trueType))
|
||||||
|
}
|
||||||
|
md.push(":")
|
||||||
|
if (model.falseType) {
|
||||||
|
md.push(getType(model.falseType))
|
||||||
|
}
|
||||||
|
return md.join(" ")
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getIndexAccessType(model: IndexedAccessType): string {
|
||||||
|
const md: string[] = []
|
||||||
|
if (model.objectType) {
|
||||||
|
md.push(getType(model.objectType))
|
||||||
|
}
|
||||||
|
if (model.indexType) {
|
||||||
|
md.push(`[${getType(model.indexType)}]`)
|
||||||
|
}
|
||||||
|
return md.join("")
|
||||||
|
}
|
||||||
|
|
||||||
|
export function hasTypes(parameters: TypeParameterReflection[]) {
|
||||||
|
const types = (parameters as TypeParameterReflection[]).map(
|
||||||
|
(param) => !!param.type || !!param.default
|
||||||
|
)
|
||||||
|
return !types.every((value) => !value)
|
||||||
|
}
|
||||||
@@ -3,14 +3,13 @@ import { BaseFilterable } from "../../dal"
|
|||||||
/**
|
/**
|
||||||
* @interface
|
* @interface
|
||||||
*
|
*
|
||||||
* An object representing a currency.
|
* A currency's data.
|
||||||
*
|
*
|
||||||
* @prop code - a string indicating the code of the currency.
|
* @prop code - The code of the currency.
|
||||||
* @prop symbol - a string indicating the symbol of the currency.
|
* @prop symbol - The symbol of the currency.
|
||||||
* @prop symbol_native -
|
* @prop symbol_native -
|
||||||
* a string indicating the symbol of the currecy in its native form.
|
* The symbol of the currecy in its native form. This is typically the symbol used when displaying a price.
|
||||||
* This is typically the symbol used when displaying a price.
|
* @prop name - The name of the currency.
|
||||||
* @prop name - a string indicating the name of the currency.
|
|
||||||
*/
|
*/
|
||||||
export interface CurrencyDTO {
|
export interface CurrencyDTO {
|
||||||
code: string
|
code: string
|
||||||
@@ -22,14 +21,13 @@ export interface CurrencyDTO {
|
|||||||
/**
|
/**
|
||||||
* @interface
|
* @interface
|
||||||
*
|
*
|
||||||
* An object that holds data to create a currency.
|
* A currency to create.
|
||||||
*
|
*
|
||||||
* @prop code - a string indicating the code of the currency.
|
* @prop code - The code of the currency.
|
||||||
* @prop symbol - a string indicating the symbol of the currency.
|
* @prop symbol - The symbol of the currency.
|
||||||
* @prop symbol_native -
|
* @prop symbol_native -
|
||||||
* a string indicating the symbol of the currecy in its native form.
|
* The symbol of the currecy in its native form. This is typically the symbol used when displaying a price.
|
||||||
* This is typically the symbol used when displaying a price.
|
* @prop name - The name of the currency.
|
||||||
* @prop name - a string indicating the name of the currency.
|
|
||||||
*/
|
*/
|
||||||
export interface CreateCurrencyDTO {
|
export interface CreateCurrencyDTO {
|
||||||
code: string
|
code: string
|
||||||
@@ -41,14 +39,13 @@ export interface CreateCurrencyDTO {
|
|||||||
/**
|
/**
|
||||||
* @interface
|
* @interface
|
||||||
*
|
*
|
||||||
* An object that holds data to update a currency. The currency code must be provided to identify which currency to update.
|
* The data to update in a currency. The `code` is used to identify which currency to update.
|
||||||
*
|
*
|
||||||
* @prop code - a string indicating the code of the currency to update.
|
* @prop code - The code of the currency to update.
|
||||||
* @prop symbol - a string indicating the symbol of the currency.
|
* @prop symbol - The symbol of the currency.
|
||||||
* @prop symbol_native -
|
* @prop symbol_native -
|
||||||
* a string indicating the symbol of the currecy in its native form.
|
* The symbol of the currecy in its native form. This is typically the symbol used when displaying a price.
|
||||||
* This is typically the symbol used when displaying a price.
|
* @prop name - The name of the currency.
|
||||||
* @prop name - a string indicating the name of the currency.
|
|
||||||
*/
|
*/
|
||||||
export interface UpdateCurrencyDTO {
|
export interface UpdateCurrencyDTO {
|
||||||
code: string
|
code: string
|
||||||
@@ -60,9 +57,9 @@ export interface UpdateCurrencyDTO {
|
|||||||
/**
|
/**
|
||||||
* @interface
|
* @interface
|
||||||
*
|
*
|
||||||
* An object used to filter retrieved currencies.
|
* Filters to apply on a currency.
|
||||||
*
|
*
|
||||||
* @prop code - an array of strings, each being a currency code to filter the currencies.
|
* @prop code - The codes to filter the currencies by.
|
||||||
*/
|
*/
|
||||||
export interface FilterableCurrencyProps
|
export interface FilterableCurrencyProps
|
||||||
extends BaseFilterable<FilterableCurrencyProps> {
|
extends BaseFilterable<FilterableCurrencyProps> {
|
||||||
|
|||||||
@@ -4,14 +4,14 @@ import { CreateCurrencyDTO, CurrencyDTO } from "./currency"
|
|||||||
/**
|
/**
|
||||||
* @interface
|
* @interface
|
||||||
*
|
*
|
||||||
* An object that holds prices, which typically belong to a price set.
|
* A money amount's data. A money amount represents a price.
|
||||||
*
|
*
|
||||||
* @prop id - A string that indicates the ID of the money amount. A money amount represents a price.
|
* @prop id - The ID of the money amount.
|
||||||
* @prop currency_code - A string that indicates the currency code of this price.
|
* @prop currency_code - The currency code of this money amount.
|
||||||
* @prop currency - An object of type {@link CurrencyDTO} that holds the details of the price's currency. Since this is a relation, it will only be retrieved if it's passed to the `relations` array of the find-configuration options.
|
* @prop currency - The money amount's currency. Since this is a relation, it will only be retrieved if it's passed to the `relations` array of the find-configuration options.
|
||||||
* @prop amount - A number indicating the amount of this price.
|
* @prop amount - The price of this money amount.
|
||||||
* @prop min_quantity - A number that indicates the minimum quantity required to be purchased for this price to be applied.
|
* @prop min_quantity - The minimum quantity required to be purchased for this price to be applied.
|
||||||
* @prop max_quantity - A number that indicates the maximum quantity required to be purchased for this price to be applied.
|
* @prop max_quantity - The maximum quantity required to be purchased for this price to be applied.
|
||||||
*/
|
*/
|
||||||
export interface MoneyAmountDTO {
|
export interface MoneyAmountDTO {
|
||||||
id: string
|
id: string
|
||||||
@@ -23,16 +23,16 @@ export interface MoneyAmountDTO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* * @interface
|
* @interface
|
||||||
*
|
*
|
||||||
* An object that holds data to create a money amount.
|
* The money amount to create.
|
||||||
*
|
*
|
||||||
* @prop id - A string that indicates the ID of the money amount.
|
* @prop id - The ID of the money amount.
|
||||||
* @prop currency_code - A string that indicates the currency code of this money amount.
|
* @prop currency_code - The currency code of this money amount.
|
||||||
* @prop currency - An object of type {@link CurrencyDTO} that holds the details of the money amount's currency. Since this is a relation, it will only be retrieved if it's passed to the `relations` array of the find-configuration options.
|
* @prop currency - The currency of this money amount.
|
||||||
* @prop amount - A number indicating the amount of this money amount.
|
* @prop amount - The amount of this money amount.
|
||||||
* @prop min_quantity - A number that indicates the minimum quantity required to be purchased for this money amount to be applied.
|
* @prop min_quantity - The minimum quantity required to be purchased for this money amount to be applied.
|
||||||
* @prop max_quantity - A number that indicates the maximum quantity required to be purchased for this money amount to be applied.
|
* @prop max_quantity - The maximum quantity required to be purchased for this money amount to be applied.
|
||||||
*/
|
*/
|
||||||
export interface CreateMoneyAmountDTO {
|
export interface CreateMoneyAmountDTO {
|
||||||
id?: string
|
id?: string
|
||||||
@@ -46,14 +46,14 @@ export interface CreateMoneyAmountDTO {
|
|||||||
/**
|
/**
|
||||||
* * @interface
|
* * @interface
|
||||||
*
|
*
|
||||||
* An object that holds data to update a money amount.
|
* The data to update in a money amount. The `id` is used to identify which money amount to update.
|
||||||
*
|
*
|
||||||
* @prop id - A string that indicates the ID of the money amount to update.
|
* @prop id - The ID of the money amount to update.
|
||||||
* @prop currency_code - A string that indicates the currency code of the money amount.
|
* @prop currency_code - The code of the currency to associate with the money amount.
|
||||||
* @prop currency - An object of type {@link CurrencyDTO} that holds the details of the money amount's currency. Since this is a relation, it will only be retrieved if it's passed to the `relations` array of the find-configuration options.
|
* @prop currency - The currency to associte with the money amount.
|
||||||
* @prop amount - A number indicating the amount of this money amount.
|
* @prop amount - The price of this money amount.
|
||||||
* @prop min_quantity - A number that indicates the minimum quantity required to be purchased for this money amount to be applied.
|
* @prop min_quantity - The minimum quantity required to be purchased for this money amount to be applied.
|
||||||
* @prop max_quantity - A number that indicates the maximum quantity required to be purchased for this money amount to be applied.
|
* @prop max_quantity - The maximum quantity required to be purchased for this money amount to be applied.
|
||||||
*/
|
*/
|
||||||
export interface UpdateMoneyAmountDTO {
|
export interface UpdateMoneyAmountDTO {
|
||||||
id: string
|
id: string
|
||||||
@@ -66,10 +66,10 @@ export interface UpdateMoneyAmountDTO {
|
|||||||
/**
|
/**
|
||||||
* @interface
|
* @interface
|
||||||
*
|
*
|
||||||
* An object that can be used to filter money amounts.
|
* Filters to apply on a money amount.
|
||||||
*
|
*
|
||||||
* @prop id - An array of strings, each being an ID to filter money amounts.
|
* @prop id - IDs to filter money amounts by.
|
||||||
* @prop currency_code - A string or an array of strings, each being a currency code to filter money amounts.
|
* @prop currency_code - Currency codes to filter money amounts by.
|
||||||
*/
|
*/
|
||||||
export interface FilterableMoneyAmountProps
|
export interface FilterableMoneyAmountProps
|
||||||
extends BaseFilterable<FilterableMoneyAmountProps> {
|
extends BaseFilterable<FilterableMoneyAmountProps> {
|
||||||
|
|||||||
@@ -5,18 +5,17 @@ import { RuleTypeDTO } from "./rule-type"
|
|||||||
/**
|
/**
|
||||||
* @interface
|
* @interface
|
||||||
*
|
*
|
||||||
* An object that represents a price rule.
|
* A price rule's data.
|
||||||
*
|
*
|
||||||
* @prop id - A string indicating the ID of the price rule.
|
* @prop id - The ID of the price rule.
|
||||||
* @prop price_set_id - A string indicating the ID of the associated price set.
|
* @prop price_set_id - The ID of the associated price set.
|
||||||
* @prop price_set - An object of type {@link PriceSetDTO} that holds the data of the associated price set. It may only be available if the relation `price_set` is expanded.
|
* @prop price_set - The associated price set. It may only be available if the relation `price_set` is expanded.
|
||||||
* @prop rule_type_id - A string indicating the ID of the associated rule type.
|
* @prop rule_type_id - The ID of the associated rule type.
|
||||||
* @prop rule_type - An object of type {@link RuleTypeDTO} that holds the data of the associated rule type. It may only be available if the relation `rule_type` is expanded.
|
* @prop rule_type - The associated rule type. It may only be available if the relation `rule_type` is expanded.
|
||||||
* @prop is_dynamic - A boolean indicating whether the price rule is dynamic.
|
* @prop value - The value of the price rule.
|
||||||
* @prop value - A string indicating the value of the price rule.
|
* @prop priority - The priority of the price rule in comparison to other applicable price rules.
|
||||||
* @prop priority - A number indicating the priority of the price rule in comparison to other applicable price rules.
|
* @prop price_set_money_amount_id - The ID of the associated price set money amount.
|
||||||
* @prop price_set_money_amount_id - A string indicating the ID of the associated price set money amount.
|
* @prop price_list_id - The ID of the associated price list.
|
||||||
* @prop price_list_id - A string indicating the ID of the associated price list.
|
|
||||||
*/
|
*/
|
||||||
export interface PriceRuleDTO {
|
export interface PriceRuleDTO {
|
||||||
id: string
|
id: string
|
||||||
@@ -24,6 +23,12 @@ export interface PriceRuleDTO {
|
|||||||
price_set: PriceSetDTO
|
price_set: PriceSetDTO
|
||||||
rule_type_id: string
|
rule_type_id: string
|
||||||
rule_type: RuleTypeDTO
|
rule_type: RuleTypeDTO
|
||||||
|
/**
|
||||||
|
* @ignore
|
||||||
|
* @privateRemark
|
||||||
|
*
|
||||||
|
* Behavior behind this property is not implemented yet.
|
||||||
|
*/
|
||||||
is_dynamic: boolean
|
is_dynamic: boolean
|
||||||
value: string
|
value: string
|
||||||
priority: number
|
priority: number
|
||||||
@@ -35,21 +40,26 @@ export interface PriceRuleDTO {
|
|||||||
*
|
*
|
||||||
* @interface
|
* @interface
|
||||||
*
|
*
|
||||||
* An object used to specify the necessary data to create a price rule.
|
* A price rule to create.
|
||||||
*
|
*
|
||||||
* @prop id - A string indicating the ID of the price rule.
|
* @prop id - The ID of the price rule.
|
||||||
* @prop price_set_id - A string indicating the ID of the associated price set.
|
* @prop price_set_id - The ID of the associated price set.
|
||||||
* @prop rule_type_id - A string indicating the ID of the associated rule type.
|
* @prop rule_type_id - The ID of the associated rule type.
|
||||||
* @prop is_dynamic - A boolean indicating whether the price rule is dynamic.
|
* @prop value - The value of the price rule.
|
||||||
* @prop value - A string indicating the value of the price rule.
|
* @prop priority - The priority of the price rule in comparison to other applicable price rules.
|
||||||
* @prop priority - A number indicating the priority of the price rule in comparison to other applicable price rules.
|
* @prop price_set_money_amount_id - The ID of the associated price set money amount.
|
||||||
* @prop price_set_money_amount_id - A string indicating the ID of the associated price set money amount.
|
* @prop price_list_id - The ID of the associated price list.
|
||||||
* @prop price_list_id - A string indicating the ID of the associated price list.
|
|
||||||
*/
|
*/
|
||||||
export interface CreatePriceRuleDTO {
|
export interface CreatePriceRuleDTO {
|
||||||
id: string
|
id: string
|
||||||
price_set_id: string
|
price_set_id: string
|
||||||
rule_type_id: string
|
rule_type_id: string
|
||||||
|
/**
|
||||||
|
* @ignore
|
||||||
|
* @privateRemark
|
||||||
|
*
|
||||||
|
* Behavior behind this property is not implemented yet.
|
||||||
|
*/
|
||||||
is_dynamic?: boolean
|
is_dynamic?: boolean
|
||||||
value: string
|
value: string
|
||||||
priority?: number
|
priority?: number
|
||||||
@@ -61,15 +71,15 @@ export interface CreatePriceRuleDTO {
|
|||||||
*
|
*
|
||||||
* @interface
|
* @interface
|
||||||
*
|
*
|
||||||
* An object used to specify the necessary data to update a price rule.
|
* The data to update in a price rule. The `id` is used to identify which money amount to update.
|
||||||
*
|
*
|
||||||
* @prop id - A string indicating the ID of the price rule to update.
|
* @prop id - The ID of the price rule to update.
|
||||||
* @prop price_set_id - A string indicating the ID of the associated price set.
|
* @prop price_set_id - The ID of the associated price set.
|
||||||
* @prop rule_type_id - A string indicating the ID of the associated rule type.
|
* @prop rule_type_id - The ID of the associated rule type.
|
||||||
* @prop value - A string indicating the value of the price rule.
|
* @prop value - The value of the price rule.
|
||||||
* @prop priority - A number indicating the priority of the price rule in comparison to other applicable price rules.
|
* @prop priority - The priority of the price rule in comparison to other applicable price rules.
|
||||||
* @prop price_set_money_amount_id - A string indicating the ID of the associated price set money amount.
|
* @prop price_set_money_amount_id - The ID of the associated price set money amount.
|
||||||
* @prop price_list_id - A string indicating the ID of the associated price list.
|
* @prop price_list_id - The ID of the associated price list.
|
||||||
*/
|
*/
|
||||||
export interface UpdatePriceRuleDTO {
|
export interface UpdatePriceRuleDTO {
|
||||||
id: string
|
id: string
|
||||||
@@ -91,12 +101,12 @@ export interface UpdatePriceRuleDTO {
|
|||||||
/**
|
/**
|
||||||
* @interface
|
* @interface
|
||||||
*
|
*
|
||||||
* An object used to filter price rules when retrieving them.
|
* Filters to apply to price rules.
|
||||||
*
|
*
|
||||||
* @prop id - An array of strings, each indicating an ID to filter price rules.
|
* @prop id - The IDs to filter price rules by.
|
||||||
* @prop name - An array of strings, each indicating a name to filter price rules.
|
* @prop name - The names to filter price rules by.
|
||||||
* @prop price_set_id - An array of strings, each indicating a price set ID to filter price rules.
|
* @prop price_set_id - The IDs to filter the price rule's associated price set.
|
||||||
* @prop rule_type_id - An array of strings, each indicating a rule type ID to filter rule types.
|
* @prop rule_type_id - The IDs to filter the price rule's associated rule type.
|
||||||
*/
|
*/
|
||||||
export interface FilterablePriceRuleProps
|
export interface FilterablePriceRuleProps
|
||||||
extends BaseFilterable<FilterablePriceRuleProps> {
|
extends BaseFilterable<FilterablePriceRuleProps> {
|
||||||
|
|||||||
@@ -5,12 +5,12 @@ import { RuleTypeDTO } from "./rule-type"
|
|||||||
/**
|
/**
|
||||||
* @interface
|
* @interface
|
||||||
*
|
*
|
||||||
* An object representing a price set money amount rule, which holds data related to the association between a price set money amount and a rule.
|
* A price set money amount rule's data.
|
||||||
*
|
*
|
||||||
* @prop id - A string indicating the ID of the price set money amount.
|
* @prop id - The ID of the price set money amount.
|
||||||
* @prop price_set_money_amount - an object of type {@link PriceSetMoneyAmountDTO} holding the data of the associated price set money amount.
|
* @prop price_set_money_amount - The associated price set money amount. It may only be available if the relation `price_set_money_amount` is expanded.
|
||||||
* @prop rule_type - an object of type {@link RuleTypeDTO} holding the data of the associated rule type.
|
* @prop rule_type - The associated rule type. It may only be available if the relation `rule_type` is expanded.
|
||||||
* @prop value - a string indicating the value of the price set money amount rule.
|
* @prop value - The value of the price set money amount rule.
|
||||||
*/
|
*/
|
||||||
export interface PriceSetMoneyAmountRulesDTO {
|
export interface PriceSetMoneyAmountRulesDTO {
|
||||||
id: string
|
id: string
|
||||||
@@ -22,11 +22,11 @@ export interface PriceSetMoneyAmountRulesDTO {
|
|||||||
/**
|
/**
|
||||||
* @interface
|
* @interface
|
||||||
*
|
*
|
||||||
* An object used to create a price set money amount rule, which represents an association between a price set money amount and a rule type.
|
* The price set money amount rule to create.
|
||||||
*
|
*
|
||||||
* @prop price_set_money_amount - A string indicating the ID of a price set money amount.
|
* @prop price_set_money_amount - The ID of a price set money amount.
|
||||||
* @prop rule_type - A string indicating the ID of a rule type.
|
* @prop rule_type - The ID of a rule type.
|
||||||
* @prop value - A string indicating the value of the price set money amount rule.
|
* @prop value - The value of the price set money amount rule.
|
||||||
*/
|
*/
|
||||||
export interface CreatePriceSetMoneyAmountRulesDTO {
|
export interface CreatePriceSetMoneyAmountRulesDTO {
|
||||||
price_set_money_amount: string
|
price_set_money_amount: string
|
||||||
@@ -37,12 +37,12 @@ export interface CreatePriceSetMoneyAmountRulesDTO {
|
|||||||
/**
|
/**
|
||||||
* @interface
|
* @interface
|
||||||
*
|
*
|
||||||
* An object used to update a price set money amount rule. The price set money amount rule is identified by the provided `id`.
|
* The data to update in a price set money amount rule. The `id` is used to identify which money amount to update.
|
||||||
*
|
*
|
||||||
* @prop id - A string indicating the ID of the price set money amount rule to update.
|
* @prop id - The ID of the price set money amount rule to update.
|
||||||
* @prop price_set_money_amount - A string indicating the ID of a price set money amount.
|
* @prop price_set_money_amount - The ID of a price set money amount.
|
||||||
* @prop rule_type - A string indicating the ID of a rule type.
|
* @prop rule_type - The ID of a rule type.
|
||||||
* @prop value - A string indicating the value of the price set money amount rule.
|
* @prop value - The value of the price set money amount rule.
|
||||||
*/
|
*/
|
||||||
export interface UpdatePriceSetMoneyAmountRulesDTO {
|
export interface UpdatePriceSetMoneyAmountRulesDTO {
|
||||||
id: string
|
id: string
|
||||||
@@ -54,12 +54,12 @@ export interface UpdatePriceSetMoneyAmountRulesDTO {
|
|||||||
/**
|
/**
|
||||||
* @interface
|
* @interface
|
||||||
*
|
*
|
||||||
* An object used to filter price set money amount rules when listing them.
|
* Filters to apply on price set money amount rules.
|
||||||
*
|
*
|
||||||
* @prop id - An array of strings, each string indicating an ID to filter the price set money amount rules.
|
* @prop id - The ID to filter price set money amount rules by.
|
||||||
* @prop rule_type_id - An array of strings, each string indicating the ID of a rule type to filter the price set money amount rules.
|
* @prop rule_type_id - The IDs to filter the price set money amount rule's associated rule type.
|
||||||
* @prop price_set_money_amount_id - an array of strings, each string indicating the ID of a price set money amount to filter the price set money amount rules.
|
* @prop price_set_money_amount_id - The IDs to filter the price set money amount rule's associated price set money amount.
|
||||||
* @prop value - an array of strings, each string indicating a value to filter the price set money amount rules.
|
* @prop value - The value to filter price set money amount rules by.
|
||||||
*/
|
*/
|
||||||
export interface FilterablePriceSetMoneyAmountRulesProps
|
export interface FilterablePriceSetMoneyAmountRulesProps
|
||||||
extends BaseFilterable<FilterablePriceSetMoneyAmountRulesProps> {
|
extends BaseFilterable<FilterablePriceSetMoneyAmountRulesProps> {
|
||||||
|
|||||||
@@ -4,12 +4,12 @@ import { PriceSetDTO } from "./price-set"
|
|||||||
/**
|
/**
|
||||||
* @interface
|
* @interface
|
||||||
*
|
*
|
||||||
* An object representing a price set money amount, which holds the data related to the association between a price set and a money amount.
|
* A price set money amount's data.
|
||||||
*
|
*
|
||||||
* @prop id - a string indicating the ID of a price set money amount.
|
* @prop id - The ID of a price set money amount.
|
||||||
* @prop title - a string indicating the title of the price set money amount.
|
* @prop title - The title of the price set money amount.
|
||||||
* @prop price_set - an object of type {@link PriceSetDTO} holding the data of the associated price set.
|
* @prop price_set - The price set associated with the price set money amount. It may only be available if the relation `price_set` is expanded.
|
||||||
* @prop money_amount - an object of type {@link MoneyAmountDTO} holding the data of the associated money amount.
|
* @prop money_amount - The money amount associated with the price set money amount. It may only be available if the relation `money_amount` is expanded.
|
||||||
*/
|
*/
|
||||||
export interface PriceSetMoneyAmountDTO {
|
export interface PriceSetMoneyAmountDTO {
|
||||||
id: string
|
id: string
|
||||||
|
|||||||
@@ -9,15 +9,12 @@ import { RuleTypeDTO } from "./rule-type"
|
|||||||
/**
|
/**
|
||||||
* @interface
|
* @interface
|
||||||
*
|
*
|
||||||
* Used to specify the context to calculate prices. For example, you can specify the currency code to calculate prices in.
|
* The context to calculate prices. For example, you can specify the currency code to calculate prices in.
|
||||||
*
|
*
|
||||||
* @prop context -
|
* @prop context -
|
||||||
* an object whose keys are the name of the context attribute. Its value can be a string or a number. For example, you can pass the `currency_code` property with its value being the currency code to calculate the price in.
|
* an object whose keys are the name of the context attribute. Its value can be a string or a number. For example, you can pass the `currency_code` property with its value being the currency code to calculate the price in.
|
||||||
* Another example is passing the `quantity` property to calculate the price for that specified quantity, which finds a price set whose `min_quantity` and `max_quantity` conditions match the specified quantity.
|
* Another example is passing the `quantity` property to calculate the price for that specified quantity, which finds a price set whose `min_quantity` and `max_quantity` conditions match the specified quantity.
|
||||||
*
|
*
|
||||||
* @example
|
|
||||||
*
|
|
||||||
* To calculate prices
|
|
||||||
*/
|
*/
|
||||||
export interface PricingContext {
|
export interface PricingContext {
|
||||||
context?: Record<string, string | number>
|
context?: Record<string, string | number>
|
||||||
@@ -26,9 +23,9 @@ export interface PricingContext {
|
|||||||
/**
|
/**
|
||||||
* @interface
|
* @interface
|
||||||
*
|
*
|
||||||
* Used to filter prices when calculating them.
|
* Filters to apply on prices.
|
||||||
*
|
*
|
||||||
* @prop id - An array of strings, each being an ID of a price set.
|
* @prop id - IDs to filter prices.
|
||||||
*/
|
*/
|
||||||
export interface PricingFilters {
|
export interface PricingFilters {
|
||||||
id: string[]
|
id: string[]
|
||||||
@@ -37,11 +34,11 @@ export interface PricingFilters {
|
|||||||
/**
|
/**
|
||||||
* @interface
|
* @interface
|
||||||
*
|
*
|
||||||
* An object that holds the details of a retrieved price set.
|
* A price set's data.
|
||||||
*
|
*
|
||||||
* @prop id - A string indicating the ID of the price set.
|
* @prop id - The ID of the price set.
|
||||||
* @prop money_amounts - An array of objects of type {@link MoneyAmountDTO}, which holds the prices that belong to this price set.
|
* @prop money_amounts - The prices that belong to this price set.
|
||||||
* @prop rule_types - An array of objects of type {@link RuleTypeDTO}, which holds the rule types applied on this price set.
|
* @prop rule_types - The rule types applied on this price set.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
export interface PriceSetDTO {
|
export interface PriceSetDTO {
|
||||||
@@ -53,13 +50,13 @@ export interface PriceSetDTO {
|
|||||||
/**
|
/**
|
||||||
* @interface
|
* @interface
|
||||||
*
|
*
|
||||||
* An object that holds the details of a calculated price set.
|
* A calculated price set's data.
|
||||||
*
|
*
|
||||||
* @prop id - a string indicating the ID of the price set.
|
* @prop id - The ID of the price set.
|
||||||
* @prop amount - a number indicating the calculated amount. It can possibly be `null` if there's no price set up for the provided context.
|
* @prop amount - The calculated amount. It can possibly be `null` if there's no price set up for the provided context.
|
||||||
* @prop currency_code - a string indicating the currency code of the calculated price. It can possibly be `null`.
|
* @prop currency_code - The currency code of the calculated price. It can possibly be `null`.
|
||||||
* @prop min_quantity - a number indicaitng the minimum quantity required to be purchased for this price to apply. It's set if the `quantity` property is provided in the context. Otherwise, its value will be `null`.
|
* @prop min_quantity - The minimum quantity required to be purchased for this price to apply. It's set if the `quantity` property is provided in the context. Otherwise, its value will be `null`.
|
||||||
* @prop max_quantity - a number indicaitng the maximum quantity required to be purchased for this price to apply. It's set if the `quantity` property is provided in the context. Otherwise, its value will be `null`.
|
* @prop max_quantity - The maximum quantity required to be purchased for this price to apply. It's set if the `quantity` property is provided in the context. Otherwise, its value will be `null`.
|
||||||
*/
|
*/
|
||||||
export interface CalculatedPriceSetDTO {
|
export interface CalculatedPriceSetDTO {
|
||||||
id: string
|
id: string
|
||||||
@@ -72,10 +69,10 @@ export interface CalculatedPriceSetDTO {
|
|||||||
/**
|
/**
|
||||||
* @interface
|
* @interface
|
||||||
*
|
*
|
||||||
* An object used to specify the rules to add to a price set.
|
* The rules to add to a price set.
|
||||||
*
|
*
|
||||||
* @prop priceSetId - A string indicating the ID of the price set to add the rules to.
|
* @prop priceSetId - The ID of the price set to add the rules to.
|
||||||
* @prop rules - An array of objects, each object holds a property `attribute`, with its value being the `rule_attribute` of the rule to add to the price set.
|
* @prop rules - The rules to add to a price set. The value of `attribute` is the value of the rule's `rule_attribute` attribute.
|
||||||
*/
|
*/
|
||||||
export interface AddRulesDTO {
|
export interface AddRulesDTO {
|
||||||
priceSetId: string
|
priceSetId: string
|
||||||
@@ -85,9 +82,9 @@ export interface AddRulesDTO {
|
|||||||
/**
|
/**
|
||||||
* @interface
|
* @interface
|
||||||
*
|
*
|
||||||
* An object used to pass prices data when creating a price set.
|
* The prices to create part of a price set.
|
||||||
*
|
*
|
||||||
* @prop rules - An object whose keys are rule types' `rule_attribute` attribute, and values are the value of that rule associated with this price.
|
* @prop rules - The rules to add to the price. The object's keys are rule types' `rule_attribute` attribute, and values are the value of that rule associated with this price.
|
||||||
*/
|
*/
|
||||||
export interface CreatePricesDTO extends CreateMoneyAmountDTO {
|
export interface CreatePricesDTO extends CreateMoneyAmountDTO {
|
||||||
rules: Record<string, string>
|
rules: Record<string, string>
|
||||||
@@ -96,10 +93,10 @@ export interface CreatePricesDTO extends CreateMoneyAmountDTO {
|
|||||||
/**
|
/**
|
||||||
* @interface
|
* @interface
|
||||||
*
|
*
|
||||||
* An object used to specify prices to add to a price set.
|
* The prices to add to a price set.
|
||||||
*
|
*
|
||||||
* @prop priceSetId - A string indicating the ID of the price set to add prices to.
|
* @prop priceSetId - The ID of the price set to add prices to.
|
||||||
* @prop prices - An array of objects of type {@link CreatePricesDTO}, each being a price to add to the price set.
|
* @prop prices - The prices to add to the price set.
|
||||||
*/
|
*/
|
||||||
export interface AddPricesDTO {
|
export interface AddPricesDTO {
|
||||||
priceSetId: string
|
priceSetId: string
|
||||||
@@ -109,10 +106,10 @@ export interface AddPricesDTO {
|
|||||||
/**
|
/**
|
||||||
* @interface
|
* @interface
|
||||||
*
|
*
|
||||||
* An object of expected properties when removing a price set's rules.
|
* The rules to remove from a price set.
|
||||||
*
|
*
|
||||||
* @prop id - A string indicating the ID of the price set.
|
* @prop id - The ID of the price set.
|
||||||
* @prop rules - An array of strings, each string is the `rule_attribute` of a rule you want to remove.
|
* @prop rules - The rules to remove. Each string is the `rule_attribute` of a rule to remove.
|
||||||
*/
|
*/
|
||||||
export interface RemovePriceSetRulesDTO {
|
export interface RemovePriceSetRulesDTO {
|
||||||
id: string
|
id: string
|
||||||
@@ -122,12 +119,10 @@ export interface RemovePriceSetRulesDTO {
|
|||||||
/**
|
/**
|
||||||
* @interface
|
* @interface
|
||||||
*
|
*
|
||||||
* An object of expected properties when creating a price set.
|
* A price set to create.
|
||||||
*
|
*
|
||||||
* @prop rules -
|
* @prop rules - The rules to associate with the price set. The value of `attribute` is the value of the rule's `rule_attribute` attribute.
|
||||||
* An array of objects, each object accepts a property `rule_attribute`, whose value is a string indicating the `rule_attribute` value of a rule type.
|
* @prop prices -The prices to create and add to this price set.
|
||||||
* This property is used to specify the rule types associated with the price set.
|
|
||||||
* @prop prices - An array of objects of type {@link CreatePricesDTO}, each being a price to associate with the price set.
|
|
||||||
*/
|
*/
|
||||||
export interface CreatePriceSetDTO {
|
export interface CreatePriceSetDTO {
|
||||||
rules?: { rule_attribute: string }[]
|
rules?: { rule_attribute: string }[]
|
||||||
@@ -137,7 +132,7 @@ export interface CreatePriceSetDTO {
|
|||||||
/**
|
/**
|
||||||
* @interface
|
* @interface
|
||||||
*
|
*
|
||||||
* An object of expected properties when updating a price set.
|
* The data to update in a price set. The `id` is used to identify which price set to update.
|
||||||
*
|
*
|
||||||
* @prop id - A string indicating the ID of the price set to update.
|
* @prop id - A string indicating the ID of the price set to update.
|
||||||
*/
|
*/
|
||||||
@@ -148,10 +143,10 @@ export interface UpdatePriceSetDTO {
|
|||||||
/**
|
/**
|
||||||
* @interface
|
* @interface
|
||||||
*
|
*
|
||||||
* An object that can be used to specify filters on price sets.
|
* Filters to apply on price sets.
|
||||||
*
|
*
|
||||||
* @prop id - An array of strings, each being an ID to filter price sets.
|
* @prop id - IDs to filter price sets by.
|
||||||
* @prop money_amounts - An object of type {@link FilterableMoneyAmountProps} that is used to filter the price sets by their associated money amounts.
|
* @prop money_amounts - Filters to apply on a price set's associated money amounts.
|
||||||
*/
|
*/
|
||||||
export interface FilterablePriceSetProps
|
export interface FilterablePriceSetProps
|
||||||
extends BaseFilterable<FilterablePriceSetProps> {
|
extends BaseFilterable<FilterablePriceSetProps> {
|
||||||
|
|||||||
@@ -3,12 +3,12 @@ import { BaseFilterable } from "../../dal"
|
|||||||
/**
|
/**
|
||||||
* @interface
|
* @interface
|
||||||
*
|
*
|
||||||
* An object that holds the details of a rule type.
|
* A rule type's data.
|
||||||
*
|
*
|
||||||
* @prop id - A string indicating the ID of the rule type.
|
* @prop id - The ID of the rule type.
|
||||||
* @prop name - A string indicating the display name of the rule type.
|
* @prop name - The display name of the rule type.
|
||||||
* @prop rule_attribute - A string indicating a unique name used to later identify the rule_attribute. For example, it can be used in the `context` parameter of the `calculatePrices` method to specify a rule for calculating the price.
|
* @prop rule_attribute - The unique name used to later identify the rule_attribute. For example, it can be used in the `context` parameter of the `calculatePrices` method to specify a rule for calculating the price.
|
||||||
* @prop default_priority - A number indicating the priority of the rule type. This is useful when calculating the price of a price set, and multiple rules satisfy the provided context. The higher the value, the higher the priority of the rule type.
|
* @prop default_priority - The priority of the rule type. This is useful when calculating the price of a price set, and multiple rules satisfy the provided context. The higher the value, the higher the priority of the rule type.
|
||||||
*/
|
*/
|
||||||
export interface RuleTypeDTO {
|
export interface RuleTypeDTO {
|
||||||
id: string
|
id: string
|
||||||
@@ -20,12 +20,12 @@ export interface RuleTypeDTO {
|
|||||||
/**
|
/**
|
||||||
* @interface
|
* @interface
|
||||||
*
|
*
|
||||||
* An object used when creating a rule type to specify its data.
|
* The rule type to create.
|
||||||
*
|
*
|
||||||
* @prop id - A string indicating the ID of the rule type.
|
* @prop id - The ID of the rule type.
|
||||||
* @prop name - A string indicating the display name of the rule type.
|
* @prop name - The display name of the rule type.
|
||||||
* @prop rule_attribute - A string indicating a unique name used to later identify the rule_attribute. For example, it can be used in the `context` parameter of the `calculatePrices` method to specify a rule for calculating the price.
|
* @prop rule_attribute - The unique name used to later identify the rule_attribute. For example, it can be used in the `context` parameter of the `calculatePrices` method to specify a rule for calculating the price.
|
||||||
* @prop default_priority - A number indicating the priority of the rule type. This is useful when calculating the price of a price set, and multiple rules satisfy the provided context. The higher the value, the higher the priority of the rule type.
|
* @prop default_priority - The priority of the rule type. This is useful when calculating the price of a price set, and multiple rules satisfy the provided context. The higher the value, the higher the priority of the rule type.
|
||||||
*/
|
*/
|
||||||
export interface CreateRuleTypeDTO {
|
export interface CreateRuleTypeDTO {
|
||||||
id?: string
|
id?: string
|
||||||
@@ -37,12 +37,12 @@ export interface CreateRuleTypeDTO {
|
|||||||
/**
|
/**
|
||||||
* @interface
|
* @interface
|
||||||
*
|
*
|
||||||
* An object used when updating a rule type to specify the data to update.
|
* The data to update in a rule type. The `id` is used to identify which price set to update.
|
||||||
*
|
*
|
||||||
* @prop id - A string indicating the ID of the rule type to update.
|
* @prop id - The ID of the rule type to update.
|
||||||
* @prop name - A string indicating the display name of the rule type.
|
* @prop name - The display name of the rule type.
|
||||||
* @prop rule_attribute - A string indicating a unique name used to later identify the rule_attribute. For example, it can be used in the `context` parameter of the `calculatePrices` method to specify a rule for calculating the price.
|
* @prop rule_attribute - The unique name used to later identify the rule_attribute. For example, it can be used in the `context` parameter of the `calculatePrices` method to specify a rule for calculating the price.
|
||||||
* @prop default_priority - A number indicating the priority of the rule type. This is useful when calculating the price of a price set, and multiple rules satisfy the provided context. The higher the value, the higher the priority of the rule type.
|
* @prop default_priority - The priority of the rule type. This is useful when calculating the price of a price set, and multiple rules satisfy the provided context. The higher the value, the higher the priority of the rule type.
|
||||||
*/
|
*/
|
||||||
export interface UpdateRuleTypeDTO {
|
export interface UpdateRuleTypeDTO {
|
||||||
id: string
|
id: string
|
||||||
@@ -54,11 +54,11 @@ export interface UpdateRuleTypeDTO {
|
|||||||
/**
|
/**
|
||||||
* @interface
|
* @interface
|
||||||
*
|
*
|
||||||
* An object used to filter retrieved rule types.
|
* Filters to apply on rule types.
|
||||||
*
|
*
|
||||||
* @prop id - an array of strings, each being an ID to filter rule types.
|
* @prop id - The IDs to filter rule types by.
|
||||||
* @prop name - an array of strings, each being a name to filter rule types.
|
* @prop name - The names to filter rule types by.
|
||||||
* @prop rule_attribute - an array of strings, each being a rule attribute to filter rule types.
|
* @prop rule_attribute - The rule attributes to filter rule types by.
|
||||||
*/
|
*/
|
||||||
export interface FilterableRuleTypeProps
|
export interface FilterableRuleTypeProps
|
||||||
extends BaseFilterable<FilterableRuleTypeProps> {
|
extends BaseFilterable<FilterableRuleTypeProps> {
|
||||||
|
|||||||
@@ -44,12 +44,17 @@ export interface IPricingModuleService {
|
|||||||
/**
|
/**
|
||||||
* This method is used to calculate prices based on the provided filters and context.
|
* This method is used to calculate prices based on the provided filters and context.
|
||||||
*
|
*
|
||||||
* @param {PricingContext} filters - An object of type {@link PricingFilters} used to filter the price sets.
|
* @param {PricingFilters} filters - The filters to apply on prices.
|
||||||
* @param {PricingContext} context - An object of type {@link PricingContext} to select prices. For example, the pricing context can specify the currency code to calculate prices in.
|
* @param {PricingContext} context -
|
||||||
* @param {Context} sharedContext - An object of type {@link Context} used to share resources, such as transaction manager, between the application and the module.
|
* The context used to select the prices. For example, you can specify the region ID in this context, and only prices having the same value
|
||||||
* @returns {Promise<CalculatedPriceSetDTO>} A promise that resolves to an object of type {@link CalculatedPriceSetDTO} which includes the calculated prices.
|
* will be retrieved.
|
||||||
|
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||||
|
* @returns {Promise<CalculatedPriceSetDTO>} The calculated price matching the context and filters provided.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
|
* When you calculate prices, you must at least specify the currency code:
|
||||||
|
*
|
||||||
|
* ```ts
|
||||||
* import {
|
* import {
|
||||||
* initialize as initializePricingModule,
|
* initialize as initializePricingModule,
|
||||||
* } from "@medusajs/pricing"
|
* } from "@medusajs/pricing"
|
||||||
@@ -67,6 +72,53 @@ export interface IPricingModuleService {
|
|||||||
*
|
*
|
||||||
* // do something with the price or return it
|
* // do something with the price or return it
|
||||||
* }
|
* }
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* To calculate prices for specific minimum and/or maximum quantity:
|
||||||
|
*
|
||||||
|
* ```ts
|
||||||
|
* import {
|
||||||
|
* initialize as initializePricingModule,
|
||||||
|
* } from "@medusajs/pricing"
|
||||||
|
* async function calculatePrice (priceSetId: string, currencyCode: string) {
|
||||||
|
* const pricingService = await initializePricingModule()
|
||||||
|
*
|
||||||
|
* const price = await pricingService.calculatePrices(
|
||||||
|
* { id: [priceSetId] },
|
||||||
|
* {
|
||||||
|
* context: {
|
||||||
|
* currency_code: currencyCode,
|
||||||
|
* min_quantity: 4
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* )
|
||||||
|
*
|
||||||
|
* // do something with the price or return it
|
||||||
|
* }
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* To calculate prices for custom rule types:
|
||||||
|
*
|
||||||
|
* ```ts
|
||||||
|
* import {
|
||||||
|
* initialize as initializePricingModule,
|
||||||
|
* } from "@medusajs/pricing"
|
||||||
|
* async function calculatePrice (priceSetId: string, currencyCode: string) {
|
||||||
|
* const pricingService = await initializePricingModule()
|
||||||
|
*
|
||||||
|
* const price = await pricingService.calculatePrices(
|
||||||
|
* { id: [priceSetId] },
|
||||||
|
* {
|
||||||
|
* context: {
|
||||||
|
* currency_code: currencyCode,
|
||||||
|
* region_id: "US"
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* )
|
||||||
|
*
|
||||||
|
* // do something with the price or return it
|
||||||
|
* }
|
||||||
|
* ```
|
||||||
*/
|
*/
|
||||||
calculatePrices(
|
calculatePrices(
|
||||||
filters: PricingFilters,
|
filters: PricingFilters,
|
||||||
@@ -77,12 +129,12 @@ export interface IPricingModuleService {
|
|||||||
/**
|
/**
|
||||||
* This method is used to retrieves a price set by its ID.
|
* This method is used to retrieves a price set by its ID.
|
||||||
*
|
*
|
||||||
* @param {string} id - A string indicating the ID of the price set to retrieve.
|
* @param {string} id - The ID of the price set to retrieve.
|
||||||
* @param {FindConfig<PriceSetDTO>} config -
|
* @param {FindConfig<PriceSetDTO>} config -
|
||||||
* An object of type {@link FindConfig} used to configure how the price set is retrieved. Its properties, such as `select` or `relations`, accept the
|
* The configurations determining how the price set is retrieved. Its properties, such as `select` or `relations`, accept the
|
||||||
* attributes or relations associated with a price set.
|
* attributes or relations associated with a price set.
|
||||||
* @param {Context} sharedContext - An object of type {@link Context} used to share resources, such as transaction manager, between the application and the module.
|
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||||
* @returns {Promise<PriceSetDTO>} A promise that resolves to an object of type {@link PriceSetDTO} which is the retrieved price set.
|
* @returns {Promise<PriceSetDTO>} The retrieved price set.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* A simple example that retrieves a price set by its ID:
|
* A simple example that retrieves a price set by its ID:
|
||||||
@@ -133,12 +185,12 @@ export interface IPricingModuleService {
|
|||||||
/**
|
/**
|
||||||
* This method is used to retrieve a paginated list of price sets based on optional filters and configuration.
|
* This method is used to retrieve a paginated list of price sets based on optional filters and configuration.
|
||||||
*
|
*
|
||||||
* @param {FilterablePriceSetProps} filters - An object of type {@link FilterablePriceSetProps} that is used to filter the retrieved price lists.
|
* @param {FilterablePriceSetProps} filters - The filters to apply on the retrieved price lists.
|
||||||
* @param {FindConfig<PriceSetDTO>} config -
|
* @param {FindConfig<PriceSetDTO>} config -
|
||||||
* An object of type {@link FindConfig} used to configure how the price sets are retrieved. Its properties, such as `select` or `relations`, accept the
|
* The configurations determining how the price sets are retrieved. Its properties, such as `select` or `relations`, accept the
|
||||||
* attributes or relations associated with a price set.
|
* attributes or relations associated with a price set.
|
||||||
* @param {Context} sharedContext - An object of type {@link Context} used to share resources, such as transaction manager, between the application and the module.
|
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||||
* @returns {Promise<PriceSetDTO[]>} A promise that resolves to an array of objects of type {@link PriceSetDTO}.
|
* @returns {Promise<PriceSetDTO[]>} The list of price sets.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
@@ -253,13 +305,12 @@ export interface IPricingModuleService {
|
|||||||
/**
|
/**
|
||||||
* This method is used to retrieve a paginated list of price sets along with the total count of available price sets satisfying the provided filters.
|
* This method is used to retrieve a paginated list of price sets along with the total count of available price sets satisfying the provided filters.
|
||||||
*
|
*
|
||||||
* @param {FilterablePriceSetProps} filters - An object of type {@link FilterablePriceSetProps} that is used to filter the retrieved price lists.
|
* @param {FilterablePriceSetProps} filters - The filters to apply on the retrieved price lists.
|
||||||
* @param {FindConfig<PriceSetDTO>} config -
|
* @param {FindConfig<PriceSetDTO>} config -
|
||||||
* An object of type {@link FindConfig} used to configure how the price sets are retrieved. Its properties, such as `select` or `relations`, accept the
|
* The configurations determining how the price sets are retrieved. Its properties, such as `select` or `relations`, accept the
|
||||||
* attributes or relations associated with a price set.
|
* attributes or relations associated with a price set.
|
||||||
* @param {Context} sharedContext - An object of type {@link Context} used to share resources, such as transaction manager, between the application and the module.
|
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||||
* @returns {Promise<[PriceSetDTO[], number]>} A promise that resolves to an array having two items, the first item is an array of objects of type {@link PriceSetDTO},
|
* @returns {Promise<[PriceSetDTO[], number]>} The list of price sets along with their total count.
|
||||||
* and the second item is a number indicating the total count.
|
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
@@ -374,9 +425,9 @@ export interface IPricingModuleService {
|
|||||||
/**
|
/**
|
||||||
* This method is used to create a new price set.
|
* This method is used to create a new price set.
|
||||||
*
|
*
|
||||||
* @param {CreatePriceSetDTO} data - An object of type {@link CreatePriceSetDTO} that holds the attribute of the price set to create.
|
* @param {CreatePriceSetDTO} data - The attributes of the price set to create.
|
||||||
* @param {Context} sharedContext - An object of type {@link Context} used to share resources, such as transaction manager, between the application and the module.
|
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||||
* @returns {Promise<PriceSetDTO>} A promise that resolves to an object of type {@link PriceSetDTO}, which is the created price set.
|
* @returns {Promise<PriceSetDTO>} The created price set.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* To create a default price set, don't pass any rules. For example:
|
* To create a default price set, don't pass any rules. For example:
|
||||||
@@ -466,9 +517,9 @@ export interface IPricingModuleService {
|
|||||||
*
|
*
|
||||||
* This method is used to create multiple price sets.
|
* This method is used to create multiple price sets.
|
||||||
*
|
*
|
||||||
* @param {CreatePriceSetDTO[]} data - An array of objects of type {@link CreatePriceSetDTO}, where each object holds the attribute of a price set to create.
|
* @param {CreatePriceSetDTO[]} data - The price sets to create.
|
||||||
* @param {Context} sharedContext - An object of type {@link Context} used to share resources, such as transaction manager, between the application and the module.
|
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||||
* @returns {Promise<PriceSetDTO[]>} A promise that resolves to an array of objects of type {@link PriceSetDTO}, which are the created price sets.
|
* @returns {Promise<PriceSetDTO[]>} The list of created price sets.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* To create price sets with a default price, don't pass any rules and make sure to pass the `currency_code` of the price. For example:
|
* To create price sets with a default price, don't pass any rules and make sure to pass the `currency_code` of the price. For example:
|
||||||
@@ -556,9 +607,9 @@ export interface IPricingModuleService {
|
|||||||
*
|
*
|
||||||
* This method is used to update existing price sets.
|
* This method is used to update existing price sets.
|
||||||
*
|
*
|
||||||
* @param {UpdatePriceSetDTO[]} data - An array of objects of type {@link UpdatePriceSetDTO}, each holding the data of the price sets to update.
|
* @param {UpdatePriceSetDTO[]} data - The price sets to update, each having the attributes that should be updated in a price set.
|
||||||
* @param {Context} sharedContext - An object of type {@link Context} used to share resources, such as transaction manager, between the application and the module.
|
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||||
* @returns {Promise<PriceSetDTO[]>} A promise that resolves to an array of objects of type {@link PriceSetDTOs}, which are the updated price sets.
|
* @returns {Promise<PriceSetDTO[]>} The list of updated price sets.
|
||||||
*/
|
*/
|
||||||
update(
|
update(
|
||||||
data: UpdatePriceSetDTO[],
|
data: UpdatePriceSetDTO[],
|
||||||
@@ -568,9 +619,9 @@ export interface IPricingModuleService {
|
|||||||
/**
|
/**
|
||||||
* This method remove rules from a price set.
|
* This method remove rules from a price set.
|
||||||
*
|
*
|
||||||
* @param {RemovePriceSetRulesDTO[]} data - An array of objects of type {@link RemovePriceSetRulesDTO}, each specfiying which rules to remove.
|
* @param {RemovePriceSetRulesDTO[]} data - The rules to remove per price set.
|
||||||
* @param {Context} sharedContext - An object of type {@link Context} used to share resources, such as transaction manager, between the application and the module.
|
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||||
* @returns {Promise<void>} A promise that resolves when rules are successfully removed.
|
* @returns {Promise<void>} Resolves when rules are successfully removed.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* import {
|
* import {
|
||||||
@@ -596,9 +647,9 @@ export interface IPricingModuleService {
|
|||||||
/**
|
/**
|
||||||
* This method deletes price sets by their IDs.
|
* This method deletes price sets by their IDs.
|
||||||
*
|
*
|
||||||
* @param {string[]} ids - An array of strings, each being the ID for a price set to delete.
|
* @param {string[]} ids - The IDs of the price sets to delete.
|
||||||
* @param {Context} sharedContext - An object of type {@link Context} used to share resources, such as transaction manager, between the application and the module.
|
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||||
* @returns {Promise<void>} A promise that resolves when the price sets are successfully deleted.
|
* @returns {Promise<void>} Resolves when the price sets are successfully deleted.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* import {
|
* import {
|
||||||
@@ -616,9 +667,9 @@ export interface IPricingModuleService {
|
|||||||
/**
|
/**
|
||||||
* This method adds prices to a price set.
|
* This method adds prices to a price set.
|
||||||
*
|
*
|
||||||
* @param {AddPricesDTO} data - An object of type {@link AddPricesDTO} that holds the data necessary to add the prices.
|
* @param {AddPricesDTO} data - The data defining the price set to add the prices to, along with the prices to add.
|
||||||
* @param {Context} sharedContext - An object of type {@link Context} used to share resources, such as transaction manager, between the application and the module.
|
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||||
* @returns {Promise<PriceSetDTO>} A promise that resolves to an object of type {@link PriceSetDTO}, which is the price set that the prices belong to.
|
* @returns {Promise<PriceSetDTO>} The price set that the prices were added to.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
@@ -696,9 +747,9 @@ export interface IPricingModuleService {
|
|||||||
/**
|
/**
|
||||||
* This method adds prices to multiple price sets.
|
* This method adds prices to multiple price sets.
|
||||||
*
|
*
|
||||||
* @param {AddPricesDTO[]} data - An array of objects of type {@link AddPricesDTO}, each holding the data necessary to add the prices to the price set.
|
* @param {AddPricesDTO[]} data - The data defining the prices to add per price set.
|
||||||
* @param {Context} sharedContext - An object of type {@link Context} used to share resources, such as transaction manager, between the application and the module.
|
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||||
* @returns {Promise<PriceSetDTO[]>} A promise that resolves to an array of objects of type {@link PriceSetDTO}, each being a price list that prices were added to.
|
* @returns {Promise<PriceSetDTO[]>} The list of the price sets that prices were added to.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
@@ -779,9 +830,9 @@ export interface IPricingModuleService {
|
|||||||
/**
|
/**
|
||||||
* This method adds rules to a price set.
|
* This method adds rules to a price set.
|
||||||
*
|
*
|
||||||
* @param {AddRulesDTO} data - An object of type {@link AddRulesDTO} that holds the necessary data to add rules to a price set.
|
* @param {AddRulesDTO} data - The data defining the price set to add the rules to, along with the rules to add.
|
||||||
* @param {Context} sharedContext - An object of type {@link Context} used to share resources, such as transaction manager, between the application and the module.
|
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||||
* @returns {Promise<PriceSetDTO>} A promise that resolves to an object of type {@link PriceSetDTO}, which is the price set that the rules belong to.
|
* @returns {Promise<PriceSetDTO>} The price set that the rules were added to.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* import {
|
* import {
|
||||||
@@ -806,9 +857,9 @@ export interface IPricingModuleService {
|
|||||||
/**
|
/**
|
||||||
* This method adds rules to multiple price sets.
|
* This method adds rules to multiple price sets.
|
||||||
*
|
*
|
||||||
* @param {AddRulesDTO[]} data - An array of objects of type {@link AddRulesDTO}, each holding the necessary data to add rules to a price set.
|
* @param {AddRulesDTO[]} data - The data defining the rules to add per price set.
|
||||||
* @param {Context} sharedContext - An object of type {@link Context} used to share resources, such as transaction manager, between the application and the module.
|
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||||
* @returns {Promise<PriceSetDTO[]>} A promise that resolves to an array of objects of type {@link PriceSetDTO}, each being the price set that rules were added to.
|
* @returns {Promise<PriceSetDTO[]>} The list of the price sets that the rules were added to.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* import {
|
* import {
|
||||||
@@ -835,10 +886,10 @@ export interface IPricingModuleService {
|
|||||||
*
|
*
|
||||||
* @param {string} id - The ID of the money amount to retrieve.
|
* @param {string} id - The ID of the money amount to retrieve.
|
||||||
* @param {FindConfig<MoneyAmountDTO>} config -
|
* @param {FindConfig<MoneyAmountDTO>} config -
|
||||||
* An object of type {@link MoneyAmountDTO} used to configure how a money amount is retrieved. Its properties, such as `select` or `relations`, accept the
|
* The configurations determining how a money amount is retrieved. Its properties, such as `select` or `relations`, accept the
|
||||||
* attributes or relations associated with a money amount.
|
* attributes or relations associated with a money amount.
|
||||||
* @param {Context} sharedContext - An object of type {@link Context} used to share resources, such as transaction manager, between the application and the module.
|
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||||
* @returns {Promise<MoneyAmountDTO>} A promise that resolves to an object of type {@link MoneyAmountDTO} which is the retrieved money amount.
|
* @returns {Promise<MoneyAmountDTO>} The retrieved money amount.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* To retrieve a money amount by its ID:
|
* To retrieve a money amount by its ID:
|
||||||
@@ -889,12 +940,12 @@ export interface IPricingModuleService {
|
|||||||
/**
|
/**
|
||||||
* This method is used to retrieve a paginated list of money amounts based on optional filters and configuration.
|
* This method is used to retrieve a paginated list of money amounts based on optional filters and configuration.
|
||||||
*
|
*
|
||||||
* @param {FilterableMoneyAmountProps} filters - An object of type {@link FilterableMoneyAmountProps} that is used to filter the retrieved money amounts.
|
* @param {FilterableMoneyAmountProps} filters - The filtes to apply on the retrieved money amounts.
|
||||||
* @param {FindConfig<MoneyAmountDTO>} config -
|
* @param {FindConfig<MoneyAmountDTO>} config -
|
||||||
* An object of type {@link FindConfig} used to configure how the money amounts are retrieved. Its properties, such as `select` or `relations`, accept the
|
* The configurations determining how the money amounts are retrieved. Its properties, such as `select` or `relations`, accept the
|
||||||
* attributes or relations associated with a money amount.
|
* attributes or relations associated with a money amount.
|
||||||
* @param {Context} sharedContext - An object of type {@link Context} used to share resources, such as transaction manager, between the application and the module.
|
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||||
* @returns {Promise<MoneyAmountDTO[]>} A promise that resolves to an array of objects of type {@link MoneyAmountDTO}.
|
* @returns {Promise<MoneyAmountDTO[]>} The list of money amounts.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
@@ -1007,13 +1058,12 @@ export interface IPricingModuleService {
|
|||||||
/**
|
/**
|
||||||
* This method is used to retrieve a paginated list of money amounts along with the total count of available money amounts satisfying the provided filters.
|
* This method is used to retrieve a paginated list of money amounts along with the total count of available money amounts satisfying the provided filters.
|
||||||
*
|
*
|
||||||
* @param {FilterableMoneyAmountProps} filters - An object of type {@link FilterableMoneyAmountProps} that is used to filter the retrieved money amounts.
|
* @param {FilterableMoneyAmountProps} filters - The filters to apply on the retrieved money amounts.
|
||||||
* @param {FindConfig<MoneyAmountDTO>} config -
|
* @param {FindConfig<MoneyAmountDTO>} config -
|
||||||
* An object of type {@link FindConfig} used to configure how the money amounts are retrieved. Its properties, such as `select` or `relations`, accept the
|
* The configurations determining how the money amounts are retrieved. Its properties, such as `select` or `relations`, accept the
|
||||||
* attributes or relations associated with a money amount.
|
* attributes or relations associated with a money amount.
|
||||||
* @param {Context} sharedContext - An object of type {@link Context} used to share resources, such as transaction manager, between the application and the module.
|
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||||
* @returns {Promise<[MoneyAmountDTO[], number]>} A promise that resolves to an array having two items, the first item is an array of objects of type {@link MoneyAmountDTO},
|
* @returns {Promise<[MoneyAmountDTO[], number]>} The list of money amounts along with their total count.
|
||||||
* and the second item is a number indicating the total count.
|
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
@@ -1126,9 +1176,9 @@ export interface IPricingModuleService {
|
|||||||
/**
|
/**
|
||||||
* This method creates money amounts.
|
* This method creates money amounts.
|
||||||
*
|
*
|
||||||
* @param {CreateMoneyAmountDTO[]} data - An array of objects of type {@link CreateMoneyAmountDTO} that holds the necessary data to create the money amount.
|
* @param {CreateMoneyAmountDTO[]} data - The money amounts to create.
|
||||||
* @param {Context} sharedContext - An object of type {@link Context} used to share resources, such as transaction manager, between the application and the module.
|
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||||
* @returns {Promise<MoneyAmountDTO[]>} A promise that resolves to an array of objects of type {@link MoneyAmountDTO}, each being a created money amount.
|
* @returns {Promise<MoneyAmountDTO[]>} The list of created money amounts.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* import {
|
* import {
|
||||||
@@ -1162,9 +1212,9 @@ export interface IPricingModuleService {
|
|||||||
/**
|
/**
|
||||||
* This method updates existing money amounts.
|
* This method updates existing money amounts.
|
||||||
*
|
*
|
||||||
* @param {UpdateMoneyAmountDTO[]} data - An array of objects of type {@link UpdateMoneyAmountDTO}, each holding data to update in a money amount.
|
* @param {UpdateMoneyAmountDTO[]} data - The money amounts to update, each having the attributes that should be updated in a money amount.
|
||||||
* @param {Context} sharedContext - An object of type {@link Context} used to share resources, such as transaction manager, between the application and the module.
|
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||||
* @returns {Promise<MoneyAmountDTO[]>} A promise that resolves to an array of objects of type {@link MoneyAmountDTO}, each being a updated money amount.
|
* @returns {Promise<MoneyAmountDTO[]>} The list of updated money amounts.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* import {
|
* import {
|
||||||
@@ -1192,9 +1242,9 @@ export interface IPricingModuleService {
|
|||||||
/**
|
/**
|
||||||
* This method deletes money amounts by their IDs.
|
* This method deletes money amounts by their IDs.
|
||||||
*
|
*
|
||||||
* @param {string[]} ids - An array of strings, each being the ID of a money amount to delete.
|
* @param {string[]} ids - The IDs of the money amounts to delete.
|
||||||
* @param {Context} sharedContext - An object of type {@link Context} used to share resources, such as transaction manager, between the application and the module.
|
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||||
* @returns {Promise<void>} A promise that resolves when the money amounts are successfully deleted.
|
* @returns {Promise<void>} Resolves when the money amounts are successfully deleted.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* import {
|
* import {
|
||||||
@@ -1214,12 +1264,12 @@ export interface IPricingModuleService {
|
|||||||
/**
|
/**
|
||||||
* This method retrieves a currency by its code and and optionally based on the provided configurations.
|
* This method retrieves a currency by its code and and optionally based on the provided configurations.
|
||||||
*
|
*
|
||||||
* @param {string} code - A string indicating the code of the currency to retrieve.
|
* @param {string} code - The code of the currency to retrieve.
|
||||||
* @param {FindConfig<CurrencyDTO>} config -
|
* @param {FindConfig<CurrencyDTO>} config -
|
||||||
* An object of type {@link FindConfig} used to configure how the currency is retrieved. Its properties, such as `select` or `relations`, accept the
|
* The configurations determining how the currency is retrieved. Its properties, such as `select` or `relations`, accept the
|
||||||
* attributes or relations associated with a currency.
|
* attributes or relations associated with a currency.
|
||||||
* @param {Context} sharedContext - An object of type {@link Context} used to share resources, such as transaction manager, between the application and the module.
|
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||||
* @returns {Promise<CurrencyDTO>} A promise that resolves to an object of type {@link CurrencyDTO}.
|
* @returns {Promise<CurrencyDTO>} The retrieved currency.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* A simple example that retrieves a currency by its code:
|
* A simple example that retrieves a currency by its code:
|
||||||
@@ -1270,12 +1320,12 @@ export interface IPricingModuleService {
|
|||||||
/**
|
/**
|
||||||
* This method is used to retrieve a paginated list of currencies based on optional filters and configuration.
|
* This method is used to retrieve a paginated list of currencies based on optional filters and configuration.
|
||||||
*
|
*
|
||||||
* @param {FilterableCurrencyProps} filters - An object of type {@link FilterableCurrencyProps} that is used to filter the retrieved currencies.
|
* @param {FilterableCurrencyProps} filters - The filters to apply on the retrieved currencies.
|
||||||
* @param {FindConfig<CurrencyDTO>} config -
|
* @param {FindConfig<CurrencyDTO>} config -
|
||||||
* An object of type {@link FindConfig} used to configure how the currencies are retrieved. Its properties, such as `select` or `relations`, accept the
|
* The configurations determining how the currencies are retrieved. Its properties, such as `select` or `relations`, accept the
|
||||||
* attributes or relations associated with a currency.
|
* attributes or relations associated with a currency.
|
||||||
* @param {Context} sharedContext - An object of type {@link Context} used to share resources, such as transaction manager, between the application and the module.
|
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||||
* @returns {Promise<CurrencyDTO[]>} A promise that resolves to an array of objects of type {@link CurrencyDTO}.
|
* @returns {Promise<CurrencyDTO[]>} The list of currencies.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
@@ -1356,13 +1406,12 @@ export interface IPricingModuleService {
|
|||||||
/**
|
/**
|
||||||
* This method is used to retrieve a paginated list of currencies along with the total count of available currencies satisfying the provided filters.
|
* This method is used to retrieve a paginated list of currencies along with the total count of available currencies satisfying the provided filters.
|
||||||
*
|
*
|
||||||
* @param {FilterableCurrencyProps} filters - An object of type {@link FilterableCurrencyProps} that is used to filter the retrieved currencies.
|
* @param {FilterableCurrencyProps} filters - The filters to apply on the retrieved currencies.
|
||||||
* @param {FindConfig<CurrencyDTO>} config -
|
* @param {FindConfig<CurrencyDTO>} config -
|
||||||
* An object of type {@link FindConfig} used to configure how the currencies are retrieved. Its properties, such as `select` or `relations`, accept the
|
* The configurations determining how the currencies are retrieved. Its properties, such as `select` or `relations`, accept the
|
||||||
* attributes or relations associated with a currency.
|
* attributes or relations associated with a currency.
|
||||||
* @param {Context} sharedContext - An object of type {@link Context} used to share resources, such as transaction manager, between the application and the module.
|
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||||
* @returns {Promise<[CurrencyDTO[], number]>} A promise that resolves to an array having two items, the first item is an array of objects of type {@link CurrencyDTO},
|
* @returns {Promise<[CurrencyDTO[], number]>} The list of currencies along with the total count.
|
||||||
* and the second item is a number indicating the total count.
|
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
@@ -1443,9 +1492,9 @@ export interface IPricingModuleService {
|
|||||||
/**
|
/**
|
||||||
* This method is used to create new currencies.
|
* This method is used to create new currencies.
|
||||||
*
|
*
|
||||||
* @param {CreateCurrencyDTO[]} data - An array of objects of type {@link CreateCurrencyDTO}, each object holding the data of a currency to create.
|
* @param {CreateCurrencyDTO[]} data - The currencies to create.
|
||||||
* @param {Context} sharedContext - An object of type {@link Context} used to share resources, such as transaction manager, between the application and the module.
|
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||||
* @returns {Promise<CurrencyDTO[]>} A promise that resolves to an array of objects of type {@link CurrencyDTO}, each object being a created currency.
|
* @returns {Promise<CurrencyDTO[]>} The list of created currencies.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* import {
|
* import {
|
||||||
@@ -1475,9 +1524,9 @@ export interface IPricingModuleService {
|
|||||||
/**
|
/**
|
||||||
* This method is used to update existing currencies with the provided data. In each currency object, the currency code must be provided to identify which currency to update.
|
* This method is used to update existing currencies with the provided data. In each currency object, the currency code must be provided to identify which currency to update.
|
||||||
*
|
*
|
||||||
* @param {UpdateCurrencyDTO[]} data - An array of objects of type {@link UpdateCurrencyDTO}, each object containing data to be updated in a currency.
|
* @param {UpdateCurrencyDTO[]} data - The currencies to update, each having the attributes that should be updated in a currency.
|
||||||
* @param {Context} sharedContext - An object of type {@link Context} used to share resources, such as transaction manager, between the application and the module.
|
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||||
* @returns {Promise<CurrencyDTO[]>} A promise that resolves to an array of objects of type {@link CurrencyDTO}, each object being an updated currency.
|
* @returns {Promise<CurrencyDTO[]>} The list of updated currencies.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* import {
|
* import {
|
||||||
@@ -1505,9 +1554,9 @@ export interface IPricingModuleService {
|
|||||||
/**
|
/**
|
||||||
* This method is used to delete currencies based on their currency code.
|
* This method is used to delete currencies based on their currency code.
|
||||||
*
|
*
|
||||||
* @param {string[]} currencyCodes - An array of strings, each being a code of a currency to delete.
|
* @param {string[]} currencyCodes - Currency codes of the currencies to delete.
|
||||||
* @param {Context} sharedContext - An object of type {@link Context} used to share resources, such as transaction manager, between the application and the module.
|
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||||
* @returns {Promise<void>} A promise that resolves once the currencies are deleted.
|
* @returns {Promise<void>} Resolves once the currencies are deleted.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* import {
|
* import {
|
||||||
@@ -1531,10 +1580,10 @@ export interface IPricingModuleService {
|
|||||||
*
|
*
|
||||||
* @param {string} id - The ID of the rule type to retrieve.
|
* @param {string} id - The ID of the rule type to retrieve.
|
||||||
* @param {FindConfig<RuleTypeDTO>} config -
|
* @param {FindConfig<RuleTypeDTO>} config -
|
||||||
* An object of type {@link FindConfig} used to configure how the rule type is retrieved. Its properties, such as `select` or `relations`, accept the
|
* The configurations determining how the rule type is retrieved. Its properties, such as `select` or `relations`, accept the
|
||||||
* attributes or relations associated with a rule type.
|
* attributes or relations associated with a rule type.
|
||||||
* @param {Context} sharedContext - An object of type {@link Context} used to share resources, such as transaction manager, between the application and the module.
|
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||||
* @returns {Promise<RuleTypeDTO>} A promise that resolves to an object of type {@link RuleTypeDTO}.
|
* @returns {Promise<RuleTypeDTO>} The retrieved rule type.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* A simple example that retrieves a rule type by its code:
|
* A simple example that retrieves a rule type by its code:
|
||||||
@@ -1572,7 +1621,7 @@ export interface IPricingModuleService {
|
|||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
retrieveRuleType(
|
retrieveRuleType(
|
||||||
code: string,
|
id: string,
|
||||||
config?: FindConfig<RuleTypeDTO>,
|
config?: FindConfig<RuleTypeDTO>,
|
||||||
sharedContext?: Context
|
sharedContext?: Context
|
||||||
): Promise<RuleTypeDTO>
|
): Promise<RuleTypeDTO>
|
||||||
@@ -1580,12 +1629,12 @@ export interface IPricingModuleService {
|
|||||||
/**
|
/**
|
||||||
* This method is used to retrieve a paginated list of rule types based on optional filters and configuration.
|
* This method is used to retrieve a paginated list of rule types based on optional filters and configuration.
|
||||||
*
|
*
|
||||||
* @param {FilterableRuleTypeProps} filters - An object of type {@link FilterableRuleTypeProps} that is used to filter the retrieved rule types.
|
* @param {FilterableRuleTypeProps} filters - The filters to apply on the retrieved rule types.
|
||||||
* @param {FindConfig<RuleTypeDTO>} config -
|
* @param {FindConfig<RuleTypeDTO>} config -
|
||||||
* An object of type {@link FindConfig} used to configure how the rule types are retrieved. Its properties, such as `select` or `relations`, accept the
|
* The configurations determining how the rule types are retrieved. Its properties, such as `select` or `relations`, accept the
|
||||||
* attributes or relations associated with a rule type.
|
* attributes or relations associated with a rule type.
|
||||||
* @param {Context} sharedContext - An object of type {@link Context} used to share resources, such as transaction manager, between the application and the module.
|
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||||
* @returns {Promise<RuleTypeDTO[]>} A promise that resolves to an array of objects of type {@link RuleTypeDTO}.
|
* @returns {Promise<RuleTypeDTO[]>} The list of rule types.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
@@ -1693,13 +1742,12 @@ export interface IPricingModuleService {
|
|||||||
/**
|
/**
|
||||||
* This method is used to retrieve a paginated list of rule types along with the total count of available rule types satisfying the provided filters.
|
* This method is used to retrieve a paginated list of rule types along with the total count of available rule types satisfying the provided filters.
|
||||||
*
|
*
|
||||||
* @param {FilterableRuleTypeProps} filters - An object of type {@link FilterableRuleTypeProps} that is used to filter the retrieved rule types.
|
* @param {FilterableRuleTypeProps} filters - The filters to apply on the retrieved rule types.
|
||||||
* @param {FindConfig<RuleTypeDTO>} config -
|
* @param {FindConfig<RuleTypeDTO>} config -
|
||||||
* An object of type {@link FindConfig} used to configure how the rule types are retrieved. Its properties, such as `select` or `relations`, accept the
|
* The configurations determining how the rule types are retrieved. Its properties, such as `select` or `relations`, accept the
|
||||||
* attributes or relations associated with a rule type.
|
* attributes or relations associated with a rule type.
|
||||||
* @param {Context} sharedContext - An object of type {@link Context} used to share resources, such as transaction manager, between the application and the module.
|
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||||
* @returns {Promise<[RuleTypeDTO[], number]>} A promise that resolves to an array having two items, the first item is an array of objects of type {@link RuleTypeDTO},
|
* @returns {Promise<[RuleTypeDTO[], number]>} The list of rule types along with their total count.
|
||||||
* and the second item is a number indicating the total count.
|
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
@@ -1807,9 +1855,9 @@ export interface IPricingModuleService {
|
|||||||
/**
|
/**
|
||||||
* This method is used to create new rule types.
|
* This method is used to create new rule types.
|
||||||
*
|
*
|
||||||
* @param {CreateRuleTypeDTO[]} data - An array of objects of type {@link CreateRuleTypeDTO}, each being the data to use to create a rule type.
|
* @param {CreateRuleTypeDTO[]} data - The rule types to create.
|
||||||
* @param {Context} sharedContext - An object of type {@link Context} used to share resources, such as transaction manager, between the application and the module.
|
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||||
* @returns {Promise<RuleTypeDTO[]>} A promise that resolves to an array of objects of type {@link RuleTypeDTO}, each being a created rule type.
|
* @returns {Promise<RuleTypeDTO[]>} The list of created rule types.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* import {
|
* import {
|
||||||
@@ -1837,9 +1885,9 @@ export interface IPricingModuleService {
|
|||||||
/**
|
/**
|
||||||
* This method is used to update existing rule types with the provided data.
|
* This method is used to update existing rule types with the provided data.
|
||||||
*
|
*
|
||||||
* @param {UpdateRuleTypeDTO[]} data - An array of objects of type {@link UpdateRuleTypeDTO}, each object containing data to be updated in a rule type.
|
* @param {UpdateRuleTypeDTO[]} data - The rule types to update, each having the attributes that should be updated in a rule type.
|
||||||
* @param {Context} sharedContext - An object of type {@link Context} used to share resources, such as transaction manager, between the application and the module.
|
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||||
* @returns {Promise<RuleTypeDTO[]>} A promise that resolves to an array of objects of type {@link RuleTypeDTO}, each being an updated rule type.
|
* @returns {Promise<RuleTypeDTO[]>} The list of updated rule types.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* import {
|
* import {
|
||||||
@@ -1867,9 +1915,9 @@ export interface IPricingModuleService {
|
|||||||
/**
|
/**
|
||||||
* This method is used to delete rule types based on the provided IDs.
|
* This method is used to delete rule types based on the provided IDs.
|
||||||
*
|
*
|
||||||
* @param {string[]} ruleTypeIds - An array of strings, each being the ID of a rule type to delete.
|
* @param {string[]} ruleTypeIds - The IDs of the rule types to delete.
|
||||||
* @param {Context} sharedContext - An object of type {@link Context} used to share resources, such as transaction manager, between the application and the module.
|
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||||
* @returns {Promise<void>} A promise that resolves once the rule types are deleted.
|
* @returns {Promise<void>} Resolves once the rule types are deleted.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* import {
|
* import {
|
||||||
@@ -1887,12 +1935,12 @@ export interface IPricingModuleService {
|
|||||||
/**
|
/**
|
||||||
* This method is used to a price set money amount rule by its ID based on the provided configuration.
|
* This method is used to a price set money amount rule by its ID based on the provided configuration.
|
||||||
*
|
*
|
||||||
* @param {string} id - A string indicating the ID of the price set money amount rule to retrieve.
|
* @param {string} id - The ID of the price set money amount rule to retrieve.
|
||||||
* @param {FindConfig<PriceSetMoneyAmountRulesDTO>} config -
|
* @param {FindConfig<PriceSetMoneyAmountRulesDTO>} config -
|
||||||
* An object of type {@link FindConfig} used to configure how the price set money amount rule is retrieved. Its properties, such as `select` or `relations`, accept the
|
* The configurations determining how the price set money amount rule is retrieved. Its properties, such as `select` or `relations`, accept the
|
||||||
* attributes or relations associated with a price set money amount rule.
|
* attributes or relations associated with a price set money amount rule.
|
||||||
* @param {Context} sharedContext - An object of type {@link Context} used to share resources, such as transaction manager, between the application and the module.
|
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||||
* @returns {Promise<PriceSetMoneyAmountRulesDTO>} A promise that resolves to an object of type {@link PriceSetMoneyAmountRulesDTO}.
|
* @returns {Promise<PriceSetMoneyAmountRulesDTO>} The retrieved price set money amount rule.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* A simple example that retrieves a price set money amount rule by its ID:
|
* A simple example that retrieves a price set money amount rule by its ID:
|
||||||
@@ -1938,13 +1986,12 @@ export interface IPricingModuleService {
|
|||||||
/**
|
/**
|
||||||
* This method is used to retrieve a paginated list of price set money amount rules based on optional filters and configuration.
|
* This method is used to retrieve a paginated list of price set money amount rules based on optional filters and configuration.
|
||||||
*
|
*
|
||||||
* @param {FilterablePriceSetMoneyAmountRulesProps} filters -
|
* @param {FilterablePriceSetMoneyAmountRulesProps} filters - The filters to apply on the retrieved price set money amount rules.
|
||||||
* An object of type {@link FilterablePriceSetMoneyAmountRulesProps} that is used to filter the retrieved price set money amount rules.
|
|
||||||
* @param {FindConfig<PriceSetMoneyAmountRulesDTO>} config -
|
* @param {FindConfig<PriceSetMoneyAmountRulesDTO>} config -
|
||||||
* An object of type {@link FindConfig} used to configure how the price set money amount rules are retrieved. Its properties, such as `select` or `relations`, accept the
|
* The configurations determining how the price set money amount rules are retrieved. Its properties, such as `select` or `relations`, accept the
|
||||||
* attributes or relations associated with a price set money amount rule.
|
* attributes or relations associated with a price set money amount rule.
|
||||||
* @param {Context} sharedContext - An object of type {@link Context} used to share resources, such as transaction manager, between the application and the module.
|
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||||
* @returns {Promise<PriceSetMoneyAmountRulesDTO[]>} A promise that resolves to an array of objects of type {@link PriceSetMoneyAmountRulesDTO}.
|
* @returns {Promise<PriceSetMoneyAmountRulesDTO[]>} The list of price set money amount rules.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
@@ -2047,14 +2094,12 @@ export interface IPricingModuleService {
|
|||||||
* This method is used to retrieve a paginated list of price set money amount rules along with the total count of
|
* This method is used to retrieve a paginated list of price set money amount rules along with the total count of
|
||||||
* available price set money amount rules satisfying the provided filters.
|
* available price set money amount rules satisfying the provided filters.
|
||||||
*
|
*
|
||||||
* @param {FilterablePriceSetMoneyAmountRulesProps} filters -
|
* @param {FilterablePriceSetMoneyAmountRulesProps} filters - The filters to apply on the retrieved price set money amount rules.
|
||||||
* An object of type {@link FilterablePriceSetMoneyAmountRulesProps} that is used to filter the retrieved price set money amount rules.
|
|
||||||
* @param {FindConfig<PriceSetMoneyAmountRulesDTO>} config -
|
* @param {FindConfig<PriceSetMoneyAmountRulesDTO>} config -
|
||||||
* An object of type {@link FindConfig} used to configure how the price set money amount rules are retrieved. Its properties, such as `select` or `relations`, accept the
|
* The configurations determining how the price set money amount rules are retrieved. Its properties, such as `select` or `relations`, accept the
|
||||||
* attributes or relations associated with a price set money amount rule.
|
* attributes or relations associated with a price set money amount rule.
|
||||||
* @param {Context} sharedContext - An object of type {@link Context} used to share resources, such as transaction manager, between the application and the module.
|
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||||
* @returns {Promise<[PriceSetMoneyAmountRulesDTO[], number]>} A promise that resolves to an array having two items, the first item is an array of objects of type {@link PriceSetMoneyAmountRulesDTO},
|
* @returns {Promise<[PriceSetMoneyAmountRulesDTO[], number]>} The list of price set money amount rules and their total count.
|
||||||
* and the second item is a number indicating the total count.
|
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
@@ -2157,11 +2202,9 @@ export interface IPricingModuleService {
|
|||||||
* This method is used to create new price set money amount rules. A price set money amount rule creates an association between a price set money amount and
|
* This method is used to create new price set money amount rules. A price set money amount rule creates an association between a price set money amount and
|
||||||
* a rule type.
|
* a rule type.
|
||||||
*
|
*
|
||||||
* @param {CreatePriceSetMoneyAmountRulesDTO[]} data -
|
* @param {CreatePriceSetMoneyAmountRulesDTO[]} data - The price set money amount rules to create.
|
||||||
* An array of objects of type {@link CreatePriceSetMoneyAmountRulesDTO}, each containing the data of a price set money amount rule to create.
|
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||||
* @param {Context} sharedContext - An object of type {@link Context} used to share resources, such as transaction manager, between the application and the module.
|
* @returns {Promise<PriceSetMoneyAmountRulesDTO[]>} The list of created price set money amount rules.
|
||||||
* @returns {Promise<PriceSetMoneyAmountRulesDTO[]>} A promise that resolves to an array of objects of type {@link PriceSetMoneyAmountRulesDTO}, each being
|
|
||||||
* a created price set money amount rule.
|
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* import {
|
* import {
|
||||||
@@ -2191,10 +2234,9 @@ export interface IPricingModuleService {
|
|||||||
* This method is used to update price set money amount rules, each with their provided data.
|
* This method is used to update price set money amount rules, each with their provided data.
|
||||||
*
|
*
|
||||||
* @param {UpdatePriceSetMoneyAmountRulesDTO[]} data -
|
* @param {UpdatePriceSetMoneyAmountRulesDTO[]} data -
|
||||||
* An array of objects of type {@link UpdatePriceSetMoneyAmountRulesDTO}, each containing the data to update in a price set money amount rule.
|
* The price set money amounts to update, each having the attributes to update in a price set money amount.
|
||||||
* @param {Context} sharedContext - An object of type {@link Context} used to share resources, such as transaction manager, between the application and the module.
|
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||||
* @returns {Promise<PriceSetMoneyAmountRulesDTO[]>} A promise that resolves to an array of objects of type {@link PriceSetMoneyAmountRulesDTO}, each being the
|
* @returns {Promise<PriceSetMoneyAmountRulesDTO[]>} The list of updated price set money amount rules.
|
||||||
* updated price set money amount rule.
|
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* import {
|
* import {
|
||||||
@@ -2222,9 +2264,9 @@ export interface IPricingModuleService {
|
|||||||
/**
|
/**
|
||||||
* This method is used to delete price set money amount rules based on the specified IDs.
|
* This method is used to delete price set money amount rules based on the specified IDs.
|
||||||
*
|
*
|
||||||
* @param {string[]} ids - An array of strings, each representing the ID of a price set money amount rule to delete.
|
* @param {string[]} ids - The IDs of the price set money amount rules to delete.
|
||||||
* @param {Context} sharedContext - An object of type {@link Context} used to share resources, such as transaction manager, between the application and the module.
|
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||||
* @returns {Promise<void>} A promise that resolves once the price set money amount rules are deleted.
|
* @returns {Promise<void>} Resolves once the price set money amount rules are deleted.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* import {
|
* import {
|
||||||
@@ -2247,10 +2289,10 @@ export interface IPricingModuleService {
|
|||||||
*
|
*
|
||||||
* @param {string} id - The ID of the price rule to retrieve.
|
* @param {string} id - The ID of the price rule to retrieve.
|
||||||
* @param {FindConfig<PriceRuleDTO>} config -
|
* @param {FindConfig<PriceRuleDTO>} config -
|
||||||
* An object of type {@link FindConfig} used to configure how the price rule is retrieved. Its properties, such as `select` or `relations`, accept the
|
* The configurations determining how the price rule is retrieved. Its properties, such as `select` or `relations`, accept the
|
||||||
* attributes or relations associated with a price rule.
|
* attributes or relations associated with a price rule.
|
||||||
* @param {Context} sharedContext - An object of type {@link Context} used to share resources, such as transaction manager, between the application and the module.
|
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||||
* @returns {Promise<PriceRuleDTO>} A promise that resolves to an object of type {@link PriceRuleDTO}.
|
* @returns {Promise<PriceRuleDTO>} The retrieved price rule.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* A simple example that retrieves a price rule by its ID:
|
* A simple example that retrieves a price rule by its ID:
|
||||||
@@ -2296,13 +2338,12 @@ export interface IPricingModuleService {
|
|||||||
/**
|
/**
|
||||||
* This method is used to retrieve a paginated list of price rules based on optional filters and configuration.
|
* This method is used to retrieve a paginated list of price rules based on optional filters and configuration.
|
||||||
*
|
*
|
||||||
* @param {FilterablePriceRuleProps} filters -
|
* @param {FilterablePriceRuleProps} filters - The filters to apply on the retrieved price rules.
|
||||||
* An object of type {@link FilterablePriceRuleProps} that is used to filter the retrieved price rules.
|
|
||||||
* @param {FindConfig<PriceRuleDTO>} config -
|
* @param {FindConfig<PriceRuleDTO>} config -
|
||||||
* An object of type {@link FindConfig} used to configure how the price rule is retrieved. Its properties, such as `select` or `relations`, accept the
|
* The configurations determining how the price rule is retrieved. Its properties, such as `select` or `relations`, accept the
|
||||||
* attributes or relations associated with a price rule.
|
* attributes or relations associated with a price rule.
|
||||||
* @param {Context} sharedContext - An object of type {@link Context} used to share resources, such as transaction manager, between the application and the module.
|
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||||
* @returns {Promise<PriceRuleDTO[]>} A promise that resolves to an array of objects of type {@link PriceRuleDTO}.
|
* @returns {Promise<PriceRuleDTO[]>} The list of price rules.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
@@ -2404,13 +2445,12 @@ export interface IPricingModuleService {
|
|||||||
/**
|
/**
|
||||||
* This method is used to retrieve a paginated list of price rules along with the total count of available price rules satisfying the provided filters.
|
* This method is used to retrieve a paginated list of price rules along with the total count of available price rules satisfying the provided filters.
|
||||||
*
|
*
|
||||||
* @param {FilterablePriceRuleProps} filters -
|
* @param {FilterablePriceRuleProps} filters - The filters to apply on the retrieved price rules.
|
||||||
* An object of type {@link FilterablePriceRuleProps} that is used to filter the retrieved price rules.
|
|
||||||
* @param {FindConfig<PriceRuleDTO>} config -
|
* @param {FindConfig<PriceRuleDTO>} config -
|
||||||
* An object of type {@link FindConfig} used to configure how the price rule is retrieved. Its properties, such as `select` or `relations`, accept the
|
* The configurations determining how the price rule is retrieved. Its properties, such as `select` or `relations`, accept the
|
||||||
* attributes or relations associated with a price rule.
|
* attributes or relations associated with a price rule.
|
||||||
* @param {Context} sharedContext - An object of type {@link Context} used to share resources, such as transaction manager, between the application and the module.
|
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||||
* @returns {Promise<PriceRuleDTO[]>} A promise that resolves to an array of objects of type {@link PriceRuleDTO}.
|
* @returns {Promise<PriceRuleDTO[]>} The list of price rules along with their total count.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
@@ -2512,9 +2552,9 @@ export interface IPricingModuleService {
|
|||||||
/**
|
/**
|
||||||
* This method is used to create new price rules based on the provided data.
|
* This method is used to create new price rules based on the provided data.
|
||||||
*
|
*
|
||||||
* @param {CreatePriceRuleDTO[]} data - An array of objects of type {@link CreatePriceRuleDTO}, each containing the data necessary to create a price rule.
|
* @param {CreatePriceRuleDTO[]} data - The price rules to create.
|
||||||
* @param {Context} sharedContext - An object of type {@link Context} used to share resources, such as transaction manager, between the application and the module.
|
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||||
* @returns {Promise<PriceRuleDTO[]>} A promise that resolves to an array of objects of type {@link PriceRuleDTO}, each being a created price rule.
|
* @returns {Promise<PriceRuleDTO[]>} The list of created price rules.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* import {
|
* import {
|
||||||
@@ -2553,9 +2593,9 @@ export interface IPricingModuleService {
|
|||||||
/**
|
/**
|
||||||
* This method is used to update price rules, each with their provided data.
|
* This method is used to update price rules, each with their provided data.
|
||||||
*
|
*
|
||||||
* @param {UpdatePriceRuleDTO[]} data - An array of objects of type {@link UpdatePriceRuleDTO}, each containing the data to update in a price rule.
|
* @param {UpdatePriceRuleDTO[]} data - The price rules to update, each having attributes that should be updated in a price rule.
|
||||||
* @param {Context} sharedContext - An object of type {@link Context} used to share resources, such as transaction manager, between the application and the module.
|
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||||
* @returns {Promise<PriceRuleDTO[]>} A promise that resolves to an array of objects of type {@link PriceRuleDTO}, each being an updated price rule.
|
* @returns {Promise<PriceRuleDTO[]>} The list of updated price rules.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* import {
|
* import {
|
||||||
@@ -2586,9 +2626,9 @@ export interface IPricingModuleService {
|
|||||||
/**
|
/**
|
||||||
* This method is used to delete price rules based on the specified IDs.
|
* This method is used to delete price rules based on the specified IDs.
|
||||||
*
|
*
|
||||||
* @param {string[]} priceRuleIds - An array of strings, each being the ID of a price rule to delete.
|
* @param {string[]} priceRuleIds - The IDs of the price rules to delete.
|
||||||
* @param {Context} sharedContext - An object of type {@link Context} used to share resources, such as transaction manager, between the application and the module.
|
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||||
* @returns {Promise<void>} A promise that resolves once the price rules are deleted.
|
* @returns {Promise<void>} Resolves once the price rules are deleted.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* import {
|
* import {
|
||||||
|
|||||||
-258
@@ -1,258 +0,0 @@
|
|||||||
---
|
|
||||||
displayed_sidebar: pricingReference
|
|
||||||
badge:
|
|
||||||
variant: orange
|
|
||||||
text: Beta
|
|
||||||
slug: /references/pricing/addPrices
|
|
||||||
sidebar_label: addPrices
|
|
||||||
---
|
|
||||||
|
|
||||||
# addPrices - Pricing Module Reference
|
|
||||||
|
|
||||||
This documentation provides a reference to the addPrices method. This belongs to the Pricing Module.
|
|
||||||
|
|
||||||
## addPrices(data, sharedContext?): Promise<PriceSetDTO\>
|
|
||||||
|
|
||||||
This method adds prices to a price set.
|
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
- `data`: An object of type [AddPricesDTO](../../interfaces/AddPricesDTO.md) that holds the data necessary to add the prices. It accepts the following properties:
|
|
||||||
- `priceSetId`: A string indicating the ID of the price set to add prices to.
|
|
||||||
- `prices`: An array of objects of type [CreatePricesDTO](../../interfaces/CreatePricesDTO.md), each being a price to add to the price set. Its items accept the following properties:
|
|
||||||
- `amount`: (optional) A number indicating the amount of this money amount.
|
|
||||||
- `currency`: (optional) An object of type [CurrencyDTO](../../interfaces/CurrencyDTO.md) that holds the details of the money amount's currency. Since this is a relation, it will only be retrieved if it's passed to the `relations` array of the find-configuration options.
|
|
||||||
- `currency_code`: A string that indicates the currency code of this money amount.
|
|
||||||
- `id`: (optional) A string that indicates the ID of the money amount.
|
|
||||||
- `max_quantity`: (optional) A number that indicates the maximum quantity required to be purchased for this money amount to be applied.
|
|
||||||
- `min_quantity`: (optional) A number that indicates the minimum quantity required to be purchased for this money amount to be applied.
|
|
||||||
- `rules`: An object whose keys are rule types' `rule_attribute` attribute, and values are the value of that rule associated with this price.
|
|
||||||
- `sharedContext`: (optional) An object of type [Context](../../interfaces/Context.md) used to share resources, such as transaction manager, between the application and the module. It accepts the following properties:
|
|
||||||
- `enableNestedTransactions`: (optional) a boolean value indicating whether nested transactions are enabled.
|
|
||||||
- `isolationLevel`: (optional) A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.
|
|
||||||
- `manager`: (optional) An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.
|
|
||||||
- `transactionId`: (optional) a string indicating the ID of the current transaction.
|
|
||||||
- `transactionManager`: (optional) An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.
|
|
||||||
|
|
||||||
### Returns
|
|
||||||
|
|
||||||
A promise that resolves to an object of type [PriceSetDTO](../../interfaces/PriceSetDTO.md), which is the price set that the prices belong to.
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary>
|
|
||||||
PriceSetDTO
|
|
||||||
</summary>
|
|
||||||
|
|
||||||
- `id`: A string indicating the ID of the price set.
|
|
||||||
- `money_amounts`: (optional) An array of objects of type [MoneyAmountDTO](../../interfaces/MoneyAmountDTO.md), which holds the prices that belong to this price set. Its items accept the following properties:
|
|
||||||
- `amount`: (optional) A number indicating the amount of this price.
|
|
||||||
- `currency`: (optional) An object of type [CurrencyDTO](../../interfaces/CurrencyDTO.md) that holds the details of the price's currency. Since this is a relation, it will only be retrieved if it's passed to the `relations` array of the find-configuration options. It accepts the following properties:
|
|
||||||
- `code`: a string indicating the code of the currency.
|
|
||||||
- `name`: (optional) a string indicating the name of the currency.
|
|
||||||
- `symbol`: (optional) a string indicating the symbol of the currency.
|
|
||||||
- `symbol_native`: (optional) a string indicating the symbol of the currecy in its native form. This is typically the symbol used when displaying a price.
|
|
||||||
- `currency_code`: (optional) A string that indicates the currency code of this price.
|
|
||||||
- `id`: A string that indicates the ID of the money amount. A money amount represents a price.
|
|
||||||
- `max_quantity`: (optional) A number that indicates the maximum quantity required to be purchased for this price to be applied.
|
|
||||||
- `min_quantity`: (optional) A number that indicates the minimum quantity required to be purchased for this price to be applied.
|
|
||||||
- `rule_types`: (optional) An array of objects of type [RuleTypeDTO](../../interfaces/RuleTypeDTO.md), which holds the rule types applied on this price set. Its items accept the following properties:
|
|
||||||
- `default_priority`: A number indicating the priority of the rule type. This is useful when calculating the price of a price set, and multiple rules satisfy the provided context. The higher the value, the higher the priority of the rule type.
|
|
||||||
- `id`: A string indicating the ID of the rule type.
|
|
||||||
- `name`: A string indicating the display name of the rule type.
|
|
||||||
- `rule_attribute`: A string indicating a unique name used to later identify the rule_attribute. For example, it can be used in the `context` parameter of the `calculatePrices` method to specify a rule for calculating the price.
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
### Example
|
|
||||||
|
|
||||||
To add a default price to a price set, don't pass it any rules and make sure to pass it the `currency_code`:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function addPricesToPriceSet (priceSetId: string) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const priceSet = await pricingService.addPrices({
|
|
||||||
priceSetId,
|
|
||||||
prices: [
|
|
||||||
{
|
|
||||||
amount: 500,
|
|
||||||
currency_code: "USD",
|
|
||||||
rules: {},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
})
|
|
||||||
|
|
||||||
// do something with the price set or return it
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
To add prices with rules:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function addPricesToPriceSet (priceSetId: string) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const priceSet = await pricingService.addPrices({
|
|
||||||
priceSetId,
|
|
||||||
prices: [
|
|
||||||
{
|
|
||||||
amount: 300,
|
|
||||||
currency_code: "EUR",
|
|
||||||
rules: {
|
|
||||||
region_id: "PL",
|
|
||||||
city: "krakow"
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
amount: 400,
|
|
||||||
currency_code: "EUR",
|
|
||||||
min_quantity: 0,
|
|
||||||
max_quantity: 4,
|
|
||||||
rules: {
|
|
||||||
region_id: "PL"
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
amount: 450,
|
|
||||||
currency_code: "EUR",
|
|
||||||
rules: {
|
|
||||||
city: "krakow"
|
|
||||||
},
|
|
||||||
}
|
|
||||||
],
|
|
||||||
})
|
|
||||||
|
|
||||||
// do something with the price set or return it
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## addPrices(data, sharedContext?): Promise<PriceSetDTO[]\>
|
|
||||||
|
|
||||||
This method adds prices to multiple price sets.
|
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
- `data`: An array of objects of type [AddPricesDTO](../../interfaces/AddPricesDTO.md), each holding the data necessary to add the prices to the price set. Its items accept the following properties:
|
|
||||||
- `priceSetId`: A string indicating the ID of the price set to add prices to.
|
|
||||||
- `prices`: An array of objects of type [CreatePricesDTO](../../interfaces/CreatePricesDTO.md), each being a price to add to the price set. Its items accept the following properties:
|
|
||||||
- `amount`: (optional) A number indicating the amount of this money amount.
|
|
||||||
- `currency`: (optional) An object of type [CurrencyDTO](../../interfaces/CurrencyDTO.md) that holds the details of the money amount's currency. Since this is a relation, it will only be retrieved if it's passed to the `relations` array of the find-configuration options.
|
|
||||||
- `currency_code`: A string that indicates the currency code of this money amount.
|
|
||||||
- `id`: (optional) A string that indicates the ID of the money amount.
|
|
||||||
- `max_quantity`: (optional) A number that indicates the maximum quantity required to be purchased for this money amount to be applied.
|
|
||||||
- `min_quantity`: (optional) A number that indicates the minimum quantity required to be purchased for this money amount to be applied.
|
|
||||||
- `rules`: An object whose keys are rule types' `rule_attribute` attribute, and values are the value of that rule associated with this price.
|
|
||||||
- `sharedContext`: (optional) An object of type [Context](../../interfaces/Context.md) used to share resources, such as transaction manager, between the application and the module. It accepts the following properties:
|
|
||||||
- `enableNestedTransactions`: (optional) a boolean value indicating whether nested transactions are enabled.
|
|
||||||
- `isolationLevel`: (optional) A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.
|
|
||||||
- `manager`: (optional) An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.
|
|
||||||
- `transactionId`: (optional) a string indicating the ID of the current transaction.
|
|
||||||
- `transactionManager`: (optional) An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.
|
|
||||||
|
|
||||||
### Returns
|
|
||||||
|
|
||||||
A promise that resolves to an array of objects of type [PriceSetDTO](../../interfaces/PriceSetDTO.md), each being a price list that prices were added to.
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary>
|
|
||||||
PriceSetDTO
|
|
||||||
</summary>
|
|
||||||
|
|
||||||
- `id`: A string indicating the ID of the price set.
|
|
||||||
- `money_amounts`: (optional) An array of objects of type [MoneyAmountDTO](../../interfaces/MoneyAmountDTO.md), which holds the prices that belong to this price set. Its items accept the following properties:
|
|
||||||
- `amount`: (optional) A number indicating the amount of this price.
|
|
||||||
- `currency`: (optional) An object of type [CurrencyDTO](../../interfaces/CurrencyDTO.md) that holds the details of the price's currency. Since this is a relation, it will only be retrieved if it's passed to the `relations` array of the find-configuration options. It accepts the following properties:
|
|
||||||
- `code`: a string indicating the code of the currency.
|
|
||||||
- `name`: (optional) a string indicating the name of the currency.
|
|
||||||
- `symbol`: (optional) a string indicating the symbol of the currency.
|
|
||||||
- `symbol_native`: (optional) a string indicating the symbol of the currecy in its native form. This is typically the symbol used when displaying a price.
|
|
||||||
- `currency_code`: (optional) A string that indicates the currency code of this price.
|
|
||||||
- `id`: A string that indicates the ID of the money amount. A money amount represents a price.
|
|
||||||
- `max_quantity`: (optional) A number that indicates the maximum quantity required to be purchased for this price to be applied.
|
|
||||||
- `min_quantity`: (optional) A number that indicates the minimum quantity required to be purchased for this price to be applied.
|
|
||||||
- `rule_types`: (optional) An array of objects of type [RuleTypeDTO](../../interfaces/RuleTypeDTO.md), which holds the rule types applied on this price set. Its items accept the following properties:
|
|
||||||
- `default_priority`: A number indicating the priority of the rule type. This is useful when calculating the price of a price set, and multiple rules satisfy the provided context. The higher the value, the higher the priority of the rule type.
|
|
||||||
- `id`: A string indicating the ID of the rule type.
|
|
||||||
- `name`: A string indicating the display name of the rule type.
|
|
||||||
- `rule_attribute`: A string indicating a unique name used to later identify the rule_attribute. For example, it can be used in the `context` parameter of the `calculatePrices` method to specify a rule for calculating the price.
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
### Example
|
|
||||||
|
|
||||||
To add a default price to a price set, don't pass it any rules and make sure to pass it the `currency_code`:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function addPricesToPriceSet (priceSetId: string) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const priceSets = await pricingService.addPrices([{
|
|
||||||
priceSetId,
|
|
||||||
prices: [
|
|
||||||
{
|
|
||||||
amount: 500,
|
|
||||||
currency_code: "USD",
|
|
||||||
rules: {},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}])
|
|
||||||
|
|
||||||
// do something with the price sets or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
To add prices with rules:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function addPricesToPriceSet (priceSetId: string) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const priceSets = await pricingService.addPrices([{
|
|
||||||
priceSetId,
|
|
||||||
prices: [
|
|
||||||
{
|
|
||||||
amount: 300,
|
|
||||||
currency_code: "EUR",
|
|
||||||
rules: {
|
|
||||||
region_id: "PL",
|
|
||||||
city: "krakow"
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
amount: 400,
|
|
||||||
currency_code: "EUR",
|
|
||||||
min_quantity: 0,
|
|
||||||
max_quantity: 4,
|
|
||||||
rules: {
|
|
||||||
region_id: "PL"
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
amount: 450,
|
|
||||||
currency_code: "EUR",
|
|
||||||
rules: {
|
|
||||||
city: "krakow"
|
|
||||||
},
|
|
||||||
}
|
|
||||||
],
|
|
||||||
}])
|
|
||||||
|
|
||||||
// do something with the price sets or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
+180
@@ -0,0 +1,180 @@
|
|||||||
|
---
|
||||||
|
displayed_sidebar: pricingReference
|
||||||
|
badge:
|
||||||
|
variant: orange
|
||||||
|
text: Beta
|
||||||
|
slug: /references/pricing/addPrices
|
||||||
|
sidebar_label: addPrices
|
||||||
|
---
|
||||||
|
|
||||||
|
import ParameterTypes from "@site/src/components/ParameterTypes"
|
||||||
|
|
||||||
|
# addPrices - Pricing Module Reference
|
||||||
|
|
||||||
|
This documentation provides a reference to the `addPrices` method. This belongs to the Pricing Module.
|
||||||
|
|
||||||
|
## addPrices(data, sharedContext?): Promise<PriceSetDTO\>
|
||||||
|
|
||||||
|
This method adds prices to a price set.
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
To add a default price to a price set, don't pass it any rules and make sure to pass it the `currency_code`:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function addPricesToPriceSet (priceSetId: string) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const priceSet = await pricingService.addPrices({
|
||||||
|
priceSetId,
|
||||||
|
prices: [
|
||||||
|
{
|
||||||
|
amount: 500,
|
||||||
|
currency_code: "USD",
|
||||||
|
rules: {},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
|
// do something with the price set or return it
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
To add prices with rules:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function addPricesToPriceSet (priceSetId: string) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const priceSet = await pricingService.addPrices({
|
||||||
|
priceSetId,
|
||||||
|
prices: [
|
||||||
|
{
|
||||||
|
amount: 300,
|
||||||
|
currency_code: "EUR",
|
||||||
|
rules: {
|
||||||
|
region_id: "PL",
|
||||||
|
city: "krakow"
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
amount: 400,
|
||||||
|
currency_code: "EUR",
|
||||||
|
min_quantity: 0,
|
||||||
|
max_quantity: 4,
|
||||||
|
rules: {
|
||||||
|
region_id: "PL"
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
amount: 450,
|
||||||
|
currency_code: "EUR",
|
||||||
|
rules: {
|
||||||
|
city: "krakow"
|
||||||
|
},
|
||||||
|
}
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
|
// do something with the price set or return it
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"data","type":"[`AddPricesDTO`](../../interfaces/AddPricesDTO.mdx)","description":"The data defining the price set to add the prices to, along with the prices to add.","optional":false,"defaultValue":"","children":[{"name":"priceSetId","type":"`string`","description":"The ID of the price set to add prices to.","optional":false,"defaultValue":"","children":[]},{"name":"prices","type":"[`CreatePricesDTO`](../../interfaces/CreatePricesDTO.mdx)[]","description":"The prices to add to the price set.","optional":false,"defaultValue":"","children":[{"name":"amount","type":"`number`","description":"The amount of this money amount.","optional":true,"defaultValue":"","children":[]},{"name":"currency","type":"[`CreateCurrencyDTO`](../../interfaces/CreateCurrencyDTO.mdx)","description":"The currency of this money amount.","optional":true,"defaultValue":"","children":[]},{"name":"currency_code","type":"`string`","description":"The currency code of this money amount.","optional":false,"defaultValue":"","children":[]},{"name":"id","type":"`string`","description":"The ID of the money amount.","optional":true,"defaultValue":"","children":[]},{"name":"max_quantity","type":"`number`","description":"The maximum quantity required to be purchased for this money amount to be applied.","optional":true,"defaultValue":"","children":[]},{"name":"min_quantity","type":"`number`","description":"The minimum quantity required to be purchased for this money amount to be applied.","optional":true,"defaultValue":"","children":[]},{"name":"rules","type":"Record<`string`, `string`\\>","description":"The rules to add to the price. The object's keys are rule types' `rule_attribute` attribute, and values are the value of that rule associated with this price.","optional":false,"defaultValue":"","children":[]}]}]},{"name":"sharedContext","type":"[`Context`](../../interfaces/Context.mdx)","description":"A context used to share resources, such as transaction manager, between the application and the module.","optional":true,"defaultValue":"","children":[{"name":"enableNestedTransactions","type":"`boolean`","description":"a boolean value indicating whether nested transactions are enabled.","optional":true,"defaultValue":"","children":[]},{"name":"isolationLevel","type":"`string`","description":"A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.","optional":true,"defaultValue":"","children":[]},{"name":"manager","type":"`TManager`","description":"An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.","optional":true,"defaultValue":"","children":[]},{"name":"transactionId","type":"`string`","description":"a string indicating the ID of the current transaction.","optional":true,"defaultValue":"","children":[]},{"name":"transactionManager","type":"`TManager`","description":"An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.","optional":true,"defaultValue":"","children":[]}]}]} />
|
||||||
|
|
||||||
|
### Returns
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"Promise","type":"`Promise`<[`PriceSetDTO`](../../interfaces/PriceSetDTO.mdx)\\>","optional":false,"defaultValue":"","description":"The price set that the prices were added to.","children":[{"name":"PriceSetDTO","type":"`object`","description":"A price set's data.","optional":false,"defaultValue":"","children":[{"name":"id","type":"`string`","description":"The ID of the price set.","optional":false,"defaultValue":"","children":[]},{"name":"money_amounts","type":"[`MoneyAmountDTO`](../../interfaces/MoneyAmountDTO.mdx)[]","description":"The prices that belong to this price set.","optional":true,"defaultValue":"","children":[]},{"name":"rule_types","type":"[`RuleTypeDTO`](../../interfaces/RuleTypeDTO.mdx)[]","description":"The rule types applied on this price set.","optional":true,"defaultValue":"","children":[]}]}]}]} />
|
||||||
|
|
||||||
|
## addPrices(data, sharedContext?): Promise<PriceSetDTO[]\>
|
||||||
|
|
||||||
|
This method adds prices to multiple price sets.
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
To add a default price to a price set, don't pass it any rules and make sure to pass it the `currency_code`:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function addPricesToPriceSet (priceSetId: string) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const priceSets = await pricingService.addPrices([{
|
||||||
|
priceSetId,
|
||||||
|
prices: [
|
||||||
|
{
|
||||||
|
amount: 500,
|
||||||
|
currency_code: "USD",
|
||||||
|
rules: {},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}])
|
||||||
|
|
||||||
|
// do something with the price sets or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
To add prices with rules:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function addPricesToPriceSet (priceSetId: string) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const priceSets = await pricingService.addPrices([{
|
||||||
|
priceSetId,
|
||||||
|
prices: [
|
||||||
|
{
|
||||||
|
amount: 300,
|
||||||
|
currency_code: "EUR",
|
||||||
|
rules: {
|
||||||
|
region_id: "PL",
|
||||||
|
city: "krakow"
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
amount: 400,
|
||||||
|
currency_code: "EUR",
|
||||||
|
min_quantity: 0,
|
||||||
|
max_quantity: 4,
|
||||||
|
rules: {
|
||||||
|
region_id: "PL"
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
amount: 450,
|
||||||
|
currency_code: "EUR",
|
||||||
|
rules: {
|
||||||
|
city: "krakow"
|
||||||
|
},
|
||||||
|
}
|
||||||
|
],
|
||||||
|
}])
|
||||||
|
|
||||||
|
// do something with the price sets or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"data","type":"[`AddPricesDTO`](../../interfaces/AddPricesDTO.mdx)[]","description":"The data defining the prices to add per price set.","optional":false,"defaultValue":"","children":[{"name":"priceSetId","type":"`string`","description":"The ID of the price set to add prices to.","optional":false,"defaultValue":"","children":[]},{"name":"prices","type":"[`CreatePricesDTO`](../../interfaces/CreatePricesDTO.mdx)[]","description":"The prices to add to the price set.","optional":false,"defaultValue":"","children":[{"name":"amount","type":"`number`","description":"The amount of this money amount.","optional":true,"defaultValue":"","children":[]},{"name":"currency","type":"[`CreateCurrencyDTO`](../../interfaces/CreateCurrencyDTO.mdx)","description":"The currency of this money amount.","optional":true,"defaultValue":"","children":[]},{"name":"currency_code","type":"`string`","description":"The currency code of this money amount.","optional":false,"defaultValue":"","children":[]},{"name":"id","type":"`string`","description":"The ID of the money amount.","optional":true,"defaultValue":"","children":[]},{"name":"max_quantity","type":"`number`","description":"The maximum quantity required to be purchased for this money amount to be applied.","optional":true,"defaultValue":"","children":[]},{"name":"min_quantity","type":"`number`","description":"The minimum quantity required to be purchased for this money amount to be applied.","optional":true,"defaultValue":"","children":[]},{"name":"rules","type":"Record<`string`, `string`\\>","description":"The rules to add to the price. The object's keys are rule types' `rule_attribute` attribute, and values are the value of that rule associated with this price.","optional":false,"defaultValue":"","children":[]}]}]},{"name":"sharedContext","type":"[`Context`](../../interfaces/Context.mdx)","description":"A context used to share resources, such as transaction manager, between the application and the module.","optional":true,"defaultValue":"","children":[{"name":"enableNestedTransactions","type":"`boolean`","description":"a boolean value indicating whether nested transactions are enabled.","optional":true,"defaultValue":"","children":[]},{"name":"isolationLevel","type":"`string`","description":"A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.","optional":true,"defaultValue":"","children":[]},{"name":"manager","type":"`TManager`","description":"An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.","optional":true,"defaultValue":"","children":[]},{"name":"transactionId","type":"`string`","description":"a string indicating the ID of the current transaction.","optional":true,"defaultValue":"","children":[]},{"name":"transactionManager","type":"`TManager`","description":"An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.","optional":true,"defaultValue":"","children":[]}]}]} />
|
||||||
|
|
||||||
|
### Returns
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"Promise","type":"`Promise`<[`PriceSetDTO`](../../interfaces/PriceSetDTO.mdx)[]\\>","optional":false,"defaultValue":"","description":"The list of the price sets that prices were added to.","children":[{"name":"PriceSetDTO[]","type":"[`PriceSetDTO`](../../interfaces/PriceSetDTO.mdx)[]","optional":false,"defaultValue":"","description":"","children":[{"name":"PriceSetDTO","type":"`object`","description":"A price set's data.","optional":false,"defaultValue":"","children":[]}]}]}]} />
|
||||||
-144
@@ -1,144 +0,0 @@
|
|||||||
---
|
|
||||||
displayed_sidebar: pricingReference
|
|
||||||
badge:
|
|
||||||
variant: orange
|
|
||||||
text: Beta
|
|
||||||
slug: /references/pricing/addRules
|
|
||||||
sidebar_label: addRules
|
|
||||||
---
|
|
||||||
|
|
||||||
# addRules - Pricing Module Reference
|
|
||||||
|
|
||||||
This documentation provides a reference to the addRules method. This belongs to the Pricing Module.
|
|
||||||
|
|
||||||
## addRules(data, sharedContext?): Promise<PriceSetDTO\>
|
|
||||||
|
|
||||||
This method adds rules to a price set.
|
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
- `data`: An object of type [AddRulesDTO](../../interfaces/AddRulesDTO.md) that holds the necessary data to add rules to a price set. It accepts the following properties:
|
|
||||||
- `priceSetId`: A string indicating the ID of the price set to add the rules to.
|
|
||||||
- `rules`: An array of objects, each object holds a property `attribute`, with its value being the `rule_attribute` of the rule to add to the price set.
|
|
||||||
- `sharedContext`: (optional) An object of type [Context](../../interfaces/Context.md) used to share resources, such as transaction manager, between the application and the module. It accepts the following properties:
|
|
||||||
- `enableNestedTransactions`: (optional) a boolean value indicating whether nested transactions are enabled.
|
|
||||||
- `isolationLevel`: (optional) A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.
|
|
||||||
- `manager`: (optional) An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.
|
|
||||||
- `transactionId`: (optional) a string indicating the ID of the current transaction.
|
|
||||||
- `transactionManager`: (optional) An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.
|
|
||||||
|
|
||||||
### Returns
|
|
||||||
|
|
||||||
A promise that resolves to an object of type [PriceSetDTO](../../interfaces/PriceSetDTO.md), which is the price set that the rules belong to.
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary>
|
|
||||||
PriceSetDTO
|
|
||||||
</summary>
|
|
||||||
|
|
||||||
- `id`: A string indicating the ID of the price set.
|
|
||||||
- `money_amounts`: (optional) An array of objects of type [MoneyAmountDTO](../../interfaces/MoneyAmountDTO.md), which holds the prices that belong to this price set. Its items accept the following properties:
|
|
||||||
- `amount`: (optional) A number indicating the amount of this price.
|
|
||||||
- `currency`: (optional) An object of type [CurrencyDTO](../../interfaces/CurrencyDTO.md) that holds the details of the price's currency. Since this is a relation, it will only be retrieved if it's passed to the `relations` array of the find-configuration options. It accepts the following properties:
|
|
||||||
- `code`: a string indicating the code of the currency.
|
|
||||||
- `name`: (optional) a string indicating the name of the currency.
|
|
||||||
- `symbol`: (optional) a string indicating the symbol of the currency.
|
|
||||||
- `symbol_native`: (optional) a string indicating the symbol of the currecy in its native form. This is typically the symbol used when displaying a price.
|
|
||||||
- `currency_code`: (optional) A string that indicates the currency code of this price.
|
|
||||||
- `id`: A string that indicates the ID of the money amount. A money amount represents a price.
|
|
||||||
- `max_quantity`: (optional) A number that indicates the maximum quantity required to be purchased for this price to be applied.
|
|
||||||
- `min_quantity`: (optional) A number that indicates the minimum quantity required to be purchased for this price to be applied.
|
|
||||||
- `rule_types`: (optional) An array of objects of type [RuleTypeDTO](../../interfaces/RuleTypeDTO.md), which holds the rule types applied on this price set. Its items accept the following properties:
|
|
||||||
- `default_priority`: A number indicating the priority of the rule type. This is useful when calculating the price of a price set, and multiple rules satisfy the provided context. The higher the value, the higher the priority of the rule type.
|
|
||||||
- `id`: A string indicating the ID of the rule type.
|
|
||||||
- `name`: A string indicating the display name of the rule type.
|
|
||||||
- `rule_attribute`: A string indicating a unique name used to later identify the rule_attribute. For example, it can be used in the `context` parameter of the `calculatePrices` method to specify a rule for calculating the price.
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
### Example
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function addRulesToPriceSet (priceSetId: string) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const priceSet = await pricingService.addRules({
|
|
||||||
priceSetId,
|
|
||||||
rules: [{
|
|
||||||
attribute: "region_id"
|
|
||||||
}]
|
|
||||||
})
|
|
||||||
|
|
||||||
// do something with the price set or return it
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## addRules(data, sharedContext?): Promise<PriceSetDTO[]\>
|
|
||||||
|
|
||||||
This method adds rules to multiple price sets.
|
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
- `data`: An array of objects of type [AddRulesDTO](../../interfaces/AddRulesDTO.md), each holding the necessary data to add rules to a price set. Its items accept the following properties:
|
|
||||||
- `priceSetId`: A string indicating the ID of the price set to add the rules to.
|
|
||||||
- `rules`: An array of objects, each object holds a property `attribute`, with its value being the `rule_attribute` of the rule to add to the price set.
|
|
||||||
- `sharedContext`: (optional) An object of type [Context](../../interfaces/Context.md) used to share resources, such as transaction manager, between the application and the module. It accepts the following properties:
|
|
||||||
- `enableNestedTransactions`: (optional) a boolean value indicating whether nested transactions are enabled.
|
|
||||||
- `isolationLevel`: (optional) A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.
|
|
||||||
- `manager`: (optional) An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.
|
|
||||||
- `transactionId`: (optional) a string indicating the ID of the current transaction.
|
|
||||||
- `transactionManager`: (optional) An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.
|
|
||||||
|
|
||||||
### Returns
|
|
||||||
|
|
||||||
A promise that resolves to an array of objects of type [PriceSetDTO](../../interfaces/PriceSetDTO.md), each being the price set that rules were added to.
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary>
|
|
||||||
PriceSetDTO
|
|
||||||
</summary>
|
|
||||||
|
|
||||||
- `id`: A string indicating the ID of the price set.
|
|
||||||
- `money_amounts`: (optional) An array of objects of type [MoneyAmountDTO](../../interfaces/MoneyAmountDTO.md), which holds the prices that belong to this price set. Its items accept the following properties:
|
|
||||||
- `amount`: (optional) A number indicating the amount of this price.
|
|
||||||
- `currency`: (optional) An object of type [CurrencyDTO](../../interfaces/CurrencyDTO.md) that holds the details of the price's currency. Since this is a relation, it will only be retrieved if it's passed to the `relations` array of the find-configuration options. It accepts the following properties:
|
|
||||||
- `code`: a string indicating the code of the currency.
|
|
||||||
- `name`: (optional) a string indicating the name of the currency.
|
|
||||||
- `symbol`: (optional) a string indicating the symbol of the currency.
|
|
||||||
- `symbol_native`: (optional) a string indicating the symbol of the currecy in its native form. This is typically the symbol used when displaying a price.
|
|
||||||
- `currency_code`: (optional) A string that indicates the currency code of this price.
|
|
||||||
- `id`: A string that indicates the ID of the money amount. A money amount represents a price.
|
|
||||||
- `max_quantity`: (optional) A number that indicates the maximum quantity required to be purchased for this price to be applied.
|
|
||||||
- `min_quantity`: (optional) A number that indicates the minimum quantity required to be purchased for this price to be applied.
|
|
||||||
- `rule_types`: (optional) An array of objects of type [RuleTypeDTO](../../interfaces/RuleTypeDTO.md), which holds the rule types applied on this price set. Its items accept the following properties:
|
|
||||||
- `default_priority`: A number indicating the priority of the rule type. This is useful when calculating the price of a price set, and multiple rules satisfy the provided context. The higher the value, the higher the priority of the rule type.
|
|
||||||
- `id`: A string indicating the ID of the rule type.
|
|
||||||
- `name`: A string indicating the display name of the rule type.
|
|
||||||
- `rule_attribute`: A string indicating a unique name used to later identify the rule_attribute. For example, it can be used in the `context` parameter of the `calculatePrices` method to specify a rule for calculating the price.
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
### Example
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function addRulesToPriceSet (priceSetId: string) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const priceSets = await pricingService.addRules([{
|
|
||||||
priceSetId,
|
|
||||||
rules: [{
|
|
||||||
attribute: "region_id"
|
|
||||||
}]
|
|
||||||
}])
|
|
||||||
|
|
||||||
// do something with the price sets or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
+80
@@ -0,0 +1,80 @@
|
|||||||
|
---
|
||||||
|
displayed_sidebar: pricingReference
|
||||||
|
badge:
|
||||||
|
variant: orange
|
||||||
|
text: Beta
|
||||||
|
slug: /references/pricing/addRules
|
||||||
|
sidebar_label: addRules
|
||||||
|
---
|
||||||
|
|
||||||
|
import ParameterTypes from "@site/src/components/ParameterTypes"
|
||||||
|
|
||||||
|
# addRules - Pricing Module Reference
|
||||||
|
|
||||||
|
This documentation provides a reference to the `addRules` method. This belongs to the Pricing Module.
|
||||||
|
|
||||||
|
## addRules(data, sharedContext?): Promise<PriceSetDTO\>
|
||||||
|
|
||||||
|
This method adds rules to a price set.
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function addRulesToPriceSet (priceSetId: string) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const priceSet = await pricingService.addRules({
|
||||||
|
priceSetId,
|
||||||
|
rules: [{
|
||||||
|
attribute: "region_id"
|
||||||
|
}]
|
||||||
|
})
|
||||||
|
|
||||||
|
// do something with the price set or return it
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"data","type":"[`AddRulesDTO`](../../interfaces/AddRulesDTO.mdx)","description":"The data defining the price set to add the rules to, along with the rules to add.","optional":false,"defaultValue":"","children":[{"name":"priceSetId","type":"`string`","description":"The ID of the price set to add the rules to.","optional":false,"defaultValue":"","children":[]},{"name":"rules","type":"{ `attribute`: `string` }[]","description":"The rules to add to a price set. The value of `attribute` is the value of the rule's `rule_attribute` attribute.","optional":false,"defaultValue":"","children":[]}]},{"name":"sharedContext","type":"[`Context`](../../interfaces/Context.mdx)","description":"A context used to share resources, such as transaction manager, between the application and the module.","optional":true,"defaultValue":"","children":[{"name":"enableNestedTransactions","type":"`boolean`","description":"a boolean value indicating whether nested transactions are enabled.","optional":true,"defaultValue":"","children":[]},{"name":"isolationLevel","type":"`string`","description":"A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.","optional":true,"defaultValue":"","children":[]},{"name":"manager","type":"`TManager`","description":"An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.","optional":true,"defaultValue":"","children":[]},{"name":"transactionId","type":"`string`","description":"a string indicating the ID of the current transaction.","optional":true,"defaultValue":"","children":[]},{"name":"transactionManager","type":"`TManager`","description":"An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.","optional":true,"defaultValue":"","children":[]}]}]} />
|
||||||
|
|
||||||
|
### Returns
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"Promise","type":"`Promise`<[`PriceSetDTO`](../../interfaces/PriceSetDTO.mdx)\\>","optional":false,"defaultValue":"","description":"The price set that the rules were added to.","children":[{"name":"PriceSetDTO","type":"`object`","description":"A price set's data.","optional":false,"defaultValue":"","children":[{"name":"id","type":"`string`","description":"The ID of the price set.","optional":false,"defaultValue":"","children":[]},{"name":"money_amounts","type":"[`MoneyAmountDTO`](../../interfaces/MoneyAmountDTO.mdx)[]","description":"The prices that belong to this price set.","optional":true,"defaultValue":"","children":[]},{"name":"rule_types","type":"[`RuleTypeDTO`](../../interfaces/RuleTypeDTO.mdx)[]","description":"The rule types applied on this price set.","optional":true,"defaultValue":"","children":[]}]}]}]} />
|
||||||
|
|
||||||
|
## addRules(data, sharedContext?): Promise<PriceSetDTO[]\>
|
||||||
|
|
||||||
|
This method adds rules to multiple price sets.
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function addRulesToPriceSet (priceSetId: string) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const priceSets = await pricingService.addRules([{
|
||||||
|
priceSetId,
|
||||||
|
rules: [{
|
||||||
|
attribute: "region_id"
|
||||||
|
}]
|
||||||
|
}])
|
||||||
|
|
||||||
|
// do something with the price sets or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"data","type":"[`AddRulesDTO`](../../interfaces/AddRulesDTO.mdx)[]","description":"The data defining the rules to add per price set.","optional":false,"defaultValue":"","children":[{"name":"priceSetId","type":"`string`","description":"The ID of the price set to add the rules to.","optional":false,"defaultValue":"","children":[]},{"name":"rules","type":"{ `attribute`: `string` }[]","description":"The rules to add to a price set. The value of `attribute` is the value of the rule's `rule_attribute` attribute.","optional":false,"defaultValue":"","children":[]}]},{"name":"sharedContext","type":"[`Context`](../../interfaces/Context.mdx)","description":"A context used to share resources, such as transaction manager, between the application and the module.","optional":true,"defaultValue":"","children":[{"name":"enableNestedTransactions","type":"`boolean`","description":"a boolean value indicating whether nested transactions are enabled.","optional":true,"defaultValue":"","children":[]},{"name":"isolationLevel","type":"`string`","description":"A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.","optional":true,"defaultValue":"","children":[]},{"name":"manager","type":"`TManager`","description":"An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.","optional":true,"defaultValue":"","children":[]},{"name":"transactionId","type":"`string`","description":"a string indicating the ID of the current transaction.","optional":true,"defaultValue":"","children":[]},{"name":"transactionManager","type":"`TManager`","description":"An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.","optional":true,"defaultValue":"","children":[]}]}]} />
|
||||||
|
|
||||||
|
### Returns
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"Promise","type":"`Promise`<[`PriceSetDTO`](../../interfaces/PriceSetDTO.mdx)[]\\>","optional":false,"defaultValue":"","description":"The list of the price sets that the rules were added to.","children":[{"name":"PriceSetDTO[]","type":"[`PriceSetDTO`](../../interfaces/PriceSetDTO.mdx)[]","optional":false,"defaultValue":"","description":"","children":[{"name":"PriceSetDTO","type":"`object`","description":"A price set's data.","optional":false,"defaultValue":"","children":[]}]}]}]} />
|
||||||
-66
@@ -1,66 +0,0 @@
|
|||||||
---
|
|
||||||
displayed_sidebar: pricingReference
|
|
||||||
badge:
|
|
||||||
variant: orange
|
|
||||||
text: Beta
|
|
||||||
slug: /references/pricing/calculatePrices
|
|
||||||
sidebar_label: calculatePrices
|
|
||||||
---
|
|
||||||
|
|
||||||
# calculatePrices - Pricing Module Reference
|
|
||||||
|
|
||||||
This documentation provides a reference to the calculatePrices method. This belongs to the Pricing Module.
|
|
||||||
|
|
||||||
This method is used to calculate prices based on the provided filters and context.
|
|
||||||
|
|
||||||
## Parameters
|
|
||||||
|
|
||||||
- `filters`: An object of type [PricingFilters](../../interfaces/PricingFilters.md) used to filter the price sets. It accepts the following properties:
|
|
||||||
- `id`: An array of strings, each being an ID of a price set.
|
|
||||||
- `context`: (optional) An object of type [PricingContext](../../interfaces/PricingContext.md) to select prices. For example, the pricing context can specify the currency code to calculate prices in. It accepts the following properties:
|
|
||||||
- `context`: (optional) an object whose keys are the name of the context attribute. Its value can be a string or a number. For example, you can pass the `currency_code` property with its value being the currency code to calculate the price in. Another example is passing the `quantity` property to calculate the price for that specified quantity, which finds a price set whose `min_quantity` and `max_quantity` conditions match the specified quantity.
|
|
||||||
- `sharedContext`: (optional) An object of type [Context](../../interfaces/Context.md) used to share resources, such as transaction manager, between the application and the module. It accepts the following properties:
|
|
||||||
- `enableNestedTransactions`: (optional) a boolean value indicating whether nested transactions are enabled.
|
|
||||||
- `isolationLevel`: (optional) A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.
|
|
||||||
- `manager`: (optional) An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.
|
|
||||||
- `transactionId`: (optional) a string indicating the ID of the current transaction.
|
|
||||||
- `transactionManager`: (optional) An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.
|
|
||||||
|
|
||||||
## Returns
|
|
||||||
|
|
||||||
A promise that resolves to an object of type [CalculatedPriceSetDTO](../../interfaces/CalculatedPriceSetDTO.md) which includes the calculated prices.
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary>
|
|
||||||
CalculatedPriceSetDTO
|
|
||||||
</summary>
|
|
||||||
|
|
||||||
- `amount`: a number indicating the calculated amount. It can possibly be `null` if there's no price set up for the provided context.
|
|
||||||
- `currency_code`: a string indicating the currency code of the calculated price. It can possibly be `null`.
|
|
||||||
- `id`: a string indicating the ID of the price set.
|
|
||||||
- `max_quantity`: a number indicaitng the maximum quantity required to be purchased for this price to apply. It's set if the `quantity` property is provided in the context. Otherwise, its value will be `null`.
|
|
||||||
- `min_quantity`: a number indicaitng the minimum quantity required to be purchased for this price to apply. It's set if the `quantity` property is provided in the context. Otherwise, its value will be `null`.
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
## Example
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
async function calculatePrice (priceSetId: string, currencyCode: string) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const price = await pricingService.calculatePrices(
|
|
||||||
{ id: [priceSetId] },
|
|
||||||
{
|
|
||||||
context: {
|
|
||||||
currency_code: currencyCode
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
// do something with the price or return it
|
|
||||||
}
|
|
||||||
```
|
|
||||||
+94
@@ -0,0 +1,94 @@
|
|||||||
|
---
|
||||||
|
displayed_sidebar: pricingReference
|
||||||
|
badge:
|
||||||
|
variant: orange
|
||||||
|
text: Beta
|
||||||
|
slug: /references/pricing/calculatePrices
|
||||||
|
sidebar_label: calculatePrices
|
||||||
|
---
|
||||||
|
|
||||||
|
import ParameterTypes from "@site/src/components/ParameterTypes"
|
||||||
|
|
||||||
|
# calculatePrices - Pricing Module Reference
|
||||||
|
|
||||||
|
This documentation provides a reference to the `calculatePrices` method. This belongs to the Pricing Module.
|
||||||
|
|
||||||
|
This method is used to calculate prices based on the provided filters and context.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
When you calculate prices, you must at least specify the currency code:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
async function calculatePrice (priceSetId: string, currencyCode: string) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const price = await pricingService.calculatePrices(
|
||||||
|
{ id: [priceSetId] },
|
||||||
|
{
|
||||||
|
context: {
|
||||||
|
currency_code: currencyCode
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// do something with the price or return it
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
To calculate prices for specific minimum and/or maximum quantity:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
async function calculatePrice (priceSetId: string, currencyCode: string) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const price = await pricingService.calculatePrices(
|
||||||
|
{ id: [priceSetId] },
|
||||||
|
{
|
||||||
|
context: {
|
||||||
|
currency_code: currencyCode,
|
||||||
|
min_quantity: 4
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// do something with the price or return it
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
To calculate prices for custom rule types:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
async function calculatePrice (priceSetId: string, currencyCode: string) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const price = await pricingService.calculatePrices(
|
||||||
|
{ id: [priceSetId] },
|
||||||
|
{
|
||||||
|
context: {
|
||||||
|
currency_code: currencyCode,
|
||||||
|
region_id: "US"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// do something with the price or return it
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"filters","type":"[`PricingFilters`](../../interfaces/PricingFilters.mdx)","description":"The filters to apply on prices.","optional":false,"defaultValue":"","children":[{"name":"id","type":"`string`[]","description":"IDs to filter prices.","optional":false,"defaultValue":"","children":[]}]},{"name":"context","type":"[`PricingContext`](../../interfaces/PricingContext.mdx)","description":"The context used to select the prices. For example, you can specify the region ID in this context, and only prices having the same value will be retrieved.","optional":true,"defaultValue":"","children":[{"name":"context","type":"Record<`string`, `string` \\| `number`\\>","description":"an object whose keys are the name of the context attribute. Its value can be a string or a number. For example, you can pass the `currency_code` property with its value being the currency code to calculate the price in. Another example is passing the `quantity` property to calculate the price for that specified quantity, which finds a price set whose `min_quantity` and `max_quantity` conditions match the specified quantity.","optional":true,"defaultValue":"","children":[]}]},{"name":"sharedContext","type":"[`Context`](../../interfaces/Context.mdx)","description":"A context used to share resources, such as transaction manager, between the application and the module.","optional":true,"defaultValue":"","children":[{"name":"enableNestedTransactions","type":"`boolean`","description":"a boolean value indicating whether nested transactions are enabled.","optional":true,"defaultValue":"","children":[]},{"name":"isolationLevel","type":"`string`","description":"A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.","optional":true,"defaultValue":"","children":[]},{"name":"manager","type":"`TManager`","description":"An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.","optional":true,"defaultValue":"","children":[]},{"name":"transactionId","type":"`string`","description":"a string indicating the ID of the current transaction.","optional":true,"defaultValue":"","children":[]},{"name":"transactionManager","type":"`TManager`","description":"An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.","optional":true,"defaultValue":"","children":[]}]}]} />
|
||||||
|
|
||||||
|
## Returns
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"Promise","type":"`Promise`<[`CalculatedPriceSetDTO`](../../interfaces/CalculatedPriceSetDTO.mdx)\\>","optional":false,"defaultValue":"","description":"The calculated price matching the context and filters provided.","children":[{"name":"CalculatedPriceSetDTO","type":"`object`","description":"A calculated price set's data.","optional":false,"defaultValue":"","children":[{"name":"amount","type":"``null`` \\| `number`","description":"The calculated amount. It can possibly be `null` if there's no price set up for the provided context.","optional":false,"defaultValue":"","children":[]},{"name":"currency_code","type":"``null`` \\| `string`","description":"The currency code of the calculated price. It can possibly be `null`.","optional":false,"defaultValue":"","children":[]},{"name":"id","type":"`string`","description":"The ID of the price set.","optional":false,"defaultValue":"","children":[]},{"name":"max_quantity","type":"``null`` \\| `number`","description":"The maximum quantity required to be purchased for this price to apply. It's set if the `quantity` property is provided in the context. Otherwise, its value will be `null`.","optional":false,"defaultValue":"","children":[]},{"name":"min_quantity","type":"``null`` \\| `number`","description":"The minimum quantity required to be purchased for this price to apply. It's set if the `quantity` property is provided in the context. Otherwise, its value will be `null`.","optional":false,"defaultValue":"","children":[]}]}]}]} />
|
||||||
-273
@@ -1,273 +0,0 @@
|
|||||||
---
|
|
||||||
displayed_sidebar: pricingReference
|
|
||||||
badge:
|
|
||||||
variant: orange
|
|
||||||
text: Beta
|
|
||||||
slug: /references/pricing/create
|
|
||||||
sidebar_label: create
|
|
||||||
---
|
|
||||||
|
|
||||||
# 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.
|
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
- `data`: An object of type [CreatePriceSetDTO](../../interfaces/CreatePriceSetDTO.md) that holds the attribute of the price set to create. It accepts the following properties:
|
|
||||||
- `prices`: (optional) An array of objects of type [CreatePricesDTO](../../interfaces/CreatePricesDTO.md), each being a price to associate with the price set. Its items accept the following properties:
|
|
||||||
- `amount`: (optional) A number indicating the amount of this money amount.
|
|
||||||
- `currency`: (optional) An object of type [CurrencyDTO](../../interfaces/CurrencyDTO.md) that holds the details of the money amount's currency. Since this is a relation, it will only be retrieved if it's passed to the `relations` array of the find-configuration options.
|
|
||||||
- `currency_code`: A string that indicates the currency code of this money amount.
|
|
||||||
- `id`: (optional) A string that indicates the ID of the money amount.
|
|
||||||
- `max_quantity`: (optional) A number that indicates the maximum quantity required to be purchased for this money amount to be applied.
|
|
||||||
- `min_quantity`: (optional) A number that indicates the minimum quantity required to be purchased for this money amount to be applied.
|
|
||||||
- `rules`: An object whose keys are rule types' `rule_attribute` attribute, and values are the value of that rule associated with this price.
|
|
||||||
- `rules`: (optional) An array of objects, each object accepts a property `rule_attribute`, whose value is a string indicating the `rule_attribute` value of a rule type. This property is used to specify the rule types associated with the price set.
|
|
||||||
- `sharedContext`: (optional) An object of type [Context](../../interfaces/Context.md) used to share resources, such as transaction manager, between the application and the module. It accepts the following properties:
|
|
||||||
- `enableNestedTransactions`: (optional) a boolean value indicating whether nested transactions are enabled.
|
|
||||||
- `isolationLevel`: (optional) A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.
|
|
||||||
- `manager`: (optional) An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.
|
|
||||||
- `transactionId`: (optional) a string indicating the ID of the current transaction.
|
|
||||||
- `transactionManager`: (optional) An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.
|
|
||||||
|
|
||||||
### Returns
|
|
||||||
|
|
||||||
A promise that resolves to an object of type [PriceSetDTO](../../interfaces/PriceSetDTO.md), which is the created price set.
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary>
|
|
||||||
PriceSetDTO
|
|
||||||
</summary>
|
|
||||||
|
|
||||||
- `id`: A string indicating the ID of the price set.
|
|
||||||
- `money_amounts`: (optional) An array of objects of type [MoneyAmountDTO](../../interfaces/MoneyAmountDTO.md), which holds the prices that belong to this price set. Its items accept the following properties:
|
|
||||||
- `amount`: (optional) A number indicating the amount of this price.
|
|
||||||
- `currency`: (optional) An object of type [CurrencyDTO](../../interfaces/CurrencyDTO.md) that holds the details of the price's currency. Since this is a relation, it will only be retrieved if it's passed to the `relations` array of the find-configuration options. It accepts the following properties:
|
|
||||||
- `code`: a string indicating the code of the currency.
|
|
||||||
- `name`: (optional) a string indicating the name of the currency.
|
|
||||||
- `symbol`: (optional) a string indicating the symbol of the currency.
|
|
||||||
- `symbol_native`: (optional) a string indicating the symbol of the currecy in its native form. This is typically the symbol used when displaying a price.
|
|
||||||
- `currency_code`: (optional) A string that indicates the currency code of this price.
|
|
||||||
- `id`: A string that indicates the ID of the money amount. A money amount represents a price.
|
|
||||||
- `max_quantity`: (optional) A number that indicates the maximum quantity required to be purchased for this price to be applied.
|
|
||||||
- `min_quantity`: (optional) A number that indicates the minimum quantity required to be purchased for this price to be applied.
|
|
||||||
- `rule_types`: (optional) An array of objects of type [RuleTypeDTO](../../interfaces/RuleTypeDTO.md), which holds the rule types applied on this price set. Its items accept the following properties:
|
|
||||||
- `default_priority`: A number indicating the priority of the rule type. This is useful when calculating the price of a price set, and multiple rules satisfy the provided context. The higher the value, the higher the priority of the rule type.
|
|
||||||
- `id`: A string indicating the ID of the rule type.
|
|
||||||
- `name`: A string indicating the display name of the rule type.
|
|
||||||
- `rule_attribute`: A string indicating a unique name used to later identify the rule_attribute. For example, it can be used in the `context` parameter of the `calculatePrices` method to specify a rule for calculating the price.
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
### Example
|
|
||||||
|
|
||||||
To create a default price set, don't pass any rules. For example:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function createPriceSet () {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const priceSet = await pricingService.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: {},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
// do something with the price set or return it
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
To create a price set and associate it with rule types:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function createPriceSet () {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const priceSet = await pricingService.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"
|
|
||||||
},
|
|
||||||
}
|
|
||||||
],
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
// do something with the price set or return it
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## create(data, sharedContext?): Promise<PriceSetDTO[]\>
|
|
||||||
|
|
||||||
This method is used to create multiple price sets.
|
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
- `data`: An array of objects of type [CreatePriceSetDTO](../../interfaces/CreatePriceSetDTO.md), where each object holds the attribute of a price set to create. Its items accept the following properties:
|
|
||||||
- `prices`: (optional) An array of objects of type [CreatePricesDTO](../../interfaces/CreatePricesDTO.md), each being a price to associate with the price set. Its items accept the following properties:
|
|
||||||
- `amount`: (optional) A number indicating the amount of this money amount.
|
|
||||||
- `currency`: (optional) An object of type [CurrencyDTO](../../interfaces/CurrencyDTO.md) that holds the details of the money amount's currency. Since this is a relation, it will only be retrieved if it's passed to the `relations` array of the find-configuration options.
|
|
||||||
- `currency_code`: A string that indicates the currency code of this money amount.
|
|
||||||
- `id`: (optional) A string that indicates the ID of the money amount.
|
|
||||||
- `max_quantity`: (optional) A number that indicates the maximum quantity required to be purchased for this money amount to be applied.
|
|
||||||
- `min_quantity`: (optional) A number that indicates the minimum quantity required to be purchased for this money amount to be applied.
|
|
||||||
- `rules`: An object whose keys are rule types' `rule_attribute` attribute, and values are the value of that rule associated with this price.
|
|
||||||
- `rules`: (optional) An array of objects, each object accepts a property `rule_attribute`, whose value is a string indicating the `rule_attribute` value of a rule type. This property is used to specify the rule types associated with the price set.
|
|
||||||
- `sharedContext`: (optional) An object of type [Context](../../interfaces/Context.md) used to share resources, such as transaction manager, between the application and the module. It accepts the following properties:
|
|
||||||
- `enableNestedTransactions`: (optional) a boolean value indicating whether nested transactions are enabled.
|
|
||||||
- `isolationLevel`: (optional) A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.
|
|
||||||
- `manager`: (optional) An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.
|
|
||||||
- `transactionId`: (optional) a string indicating the ID of the current transaction.
|
|
||||||
- `transactionManager`: (optional) An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.
|
|
||||||
|
|
||||||
### Returns
|
|
||||||
|
|
||||||
A promise that resolves to an array of objects of type [PriceSetDTO](../../interfaces/PriceSetDTO.md), which are the created price sets.
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary>
|
|
||||||
PriceSetDTO
|
|
||||||
</summary>
|
|
||||||
|
|
||||||
- `id`: A string indicating the ID of the price set.
|
|
||||||
- `money_amounts`: (optional) An array of objects of type [MoneyAmountDTO](../../interfaces/MoneyAmountDTO.md), which holds the prices that belong to this price set. Its items accept the following properties:
|
|
||||||
- `amount`: (optional) A number indicating the amount of this price.
|
|
||||||
- `currency`: (optional) An object of type [CurrencyDTO](../../interfaces/CurrencyDTO.md) that holds the details of the price's currency. Since this is a relation, it will only be retrieved if it's passed to the `relations` array of the find-configuration options. It accepts the following properties:
|
|
||||||
- `code`: a string indicating the code of the currency.
|
|
||||||
- `name`: (optional) a string indicating the name of the currency.
|
|
||||||
- `symbol`: (optional) a string indicating the symbol of the currency.
|
|
||||||
- `symbol_native`: (optional) a string indicating the symbol of the currecy in its native form. This is typically the symbol used when displaying a price.
|
|
||||||
- `currency_code`: (optional) A string that indicates the currency code of this price.
|
|
||||||
- `id`: A string that indicates the ID of the money amount. A money amount represents a price.
|
|
||||||
- `max_quantity`: (optional) A number that indicates the maximum quantity required to be purchased for this price to be applied.
|
|
||||||
- `min_quantity`: (optional) A number that indicates the minimum quantity required to be purchased for this price to be applied.
|
|
||||||
- `rule_types`: (optional) An array of objects of type [RuleTypeDTO](../../interfaces/RuleTypeDTO.md), which holds the rule types applied on this price set. Its items accept the following properties:
|
|
||||||
- `default_priority`: A number indicating the priority of the rule type. This is useful when calculating the price of a price set, and multiple rules satisfy the provided context. The higher the value, the higher the priority of the rule type.
|
|
||||||
- `id`: A string indicating the ID of the rule type.
|
|
||||||
- `name`: A string indicating the display name of the rule type.
|
|
||||||
- `rule_attribute`: A string indicating a unique name used to later identify the rule_attribute. For example, it can be used in the `context` parameter of the `calculatePrices` method to specify a rule for calculating the price.
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
### Example
|
|
||||||
|
|
||||||
To create price sets with a default price, don't pass any rules and make sure to pass the `currency_code` of the price. For example:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function createPriceSets () {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const priceSets = await pricingService.create([
|
|
||||||
{
|
|
||||||
rules: [],
|
|
||||||
prices: [
|
|
||||||
{
|
|
||||||
amount: 500,
|
|
||||||
currency_code: "USD",
|
|
||||||
rules: {},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
])
|
|
||||||
|
|
||||||
// do something with the price sets or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
To create price sets and associate them with rule types:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function createPriceSets () {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const priceSets = await pricingService.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",
|
|
||||||
min_quantity: 0,
|
|
||||||
max_quantity: 4,
|
|
||||||
rules: {
|
|
||||||
region_id: "PL"
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
amount: 450,
|
|
||||||
currency_code: "EUR",
|
|
||||||
rules: {
|
|
||||||
city: "krakow"
|
|
||||||
},
|
|
||||||
}
|
|
||||||
],
|
|
||||||
},
|
|
||||||
])
|
|
||||||
|
|
||||||
// do something with the price sets or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
+195
@@ -0,0 +1,195 @@
|
|||||||
|
---
|
||||||
|
displayed_sidebar: pricingReference
|
||||||
|
badge:
|
||||||
|
variant: orange
|
||||||
|
text: Beta
|
||||||
|
slug: /references/pricing/create
|
||||||
|
sidebar_label: create
|
||||||
|
---
|
||||||
|
|
||||||
|
import ParameterTypes from "@site/src/components/ParameterTypes"
|
||||||
|
|
||||||
|
# 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:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function createPriceSet () {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const priceSet = await pricingService.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: {},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
// do something with the price set or return it
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
To create a price set and associate it with rule types:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function createPriceSet () {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const priceSet = await pricingService.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"
|
||||||
|
},
|
||||||
|
}
|
||||||
|
],
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
// do something with the price set or return it
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"data","type":"[`CreatePriceSetDTO`](../../interfaces/CreatePriceSetDTO.mdx)","description":"The attributes of the price set to create.","optional":false,"defaultValue":"","children":[{"name":"prices","type":"[`CreatePricesDTO`](../../interfaces/CreatePricesDTO.mdx)[]","description":"The prices to create and add to this price set.","optional":true,"defaultValue":"","children":[{"name":"amount","type":"`number`","description":"The amount of this money amount.","optional":true,"defaultValue":"","children":[]},{"name":"currency","type":"[`CreateCurrencyDTO`](../../interfaces/CreateCurrencyDTO.mdx)","description":"The currency of this money amount.","optional":true,"defaultValue":"","children":[]},{"name":"currency_code","type":"`string`","description":"The currency code of this money amount.","optional":false,"defaultValue":"","children":[]},{"name":"id","type":"`string`","description":"The ID of the money amount.","optional":true,"defaultValue":"","children":[]},{"name":"max_quantity","type":"`number`","description":"The maximum quantity required to be purchased for this money amount to be applied.","optional":true,"defaultValue":"","children":[]},{"name":"min_quantity","type":"`number`","description":"The minimum quantity required to be purchased for this money amount to be applied.","optional":true,"defaultValue":"","children":[]},{"name":"rules","type":"Record<`string`, `string`\\>","description":"The rules to add to the price. The object's keys are rule types' `rule_attribute` attribute, and values are the value of that rule associated with this price.","optional":false,"defaultValue":"","children":[]}]},{"name":"rules","type":"{ `rule_attribute`: `string` }[]","description":"The rules to associate with the price set. The value of `attribute` is the value of the rule's `rule_attribute` attribute.","optional":true,"defaultValue":"","children":[]}]},{"name":"sharedContext","type":"[`Context`](../../interfaces/Context.mdx)","description":"A context used to share resources, such as transaction manager, between the application and the module.","optional":true,"defaultValue":"","children":[{"name":"enableNestedTransactions","type":"`boolean`","description":"a boolean value indicating whether nested transactions are enabled.","optional":true,"defaultValue":"","children":[]},{"name":"isolationLevel","type":"`string`","description":"A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.","optional":true,"defaultValue":"","children":[]},{"name":"manager","type":"`TManager`","description":"An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.","optional":true,"defaultValue":"","children":[]},{"name":"transactionId","type":"`string`","description":"a string indicating the ID of the current transaction.","optional":true,"defaultValue":"","children":[]},{"name":"transactionManager","type":"`TManager`","description":"An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.","optional":true,"defaultValue":"","children":[]}]}]} />
|
||||||
|
|
||||||
|
### Returns
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"Promise","type":"`Promise`<[`PriceSetDTO`](../../interfaces/PriceSetDTO.mdx)\\>","optional":false,"defaultValue":"","description":"The created price set.","children":[{"name":"PriceSetDTO","type":"`object`","description":"A price set's data.","optional":false,"defaultValue":"","children":[{"name":"id","type":"`string`","description":"The ID of the price set.","optional":false,"defaultValue":"","children":[]},{"name":"money_amounts","type":"[`MoneyAmountDTO`](../../interfaces/MoneyAmountDTO.mdx)[]","description":"The prices that belong to this price set.","optional":true,"defaultValue":"","children":[]},{"name":"rule_types","type":"[`RuleTypeDTO`](../../interfaces/RuleTypeDTO.mdx)[]","description":"The rule types applied on this price set.","optional":true,"defaultValue":"","children":[]}]}]}]} />
|
||||||
|
|
||||||
|
## create(data, sharedContext?): Promise<PriceSetDTO[]\>
|
||||||
|
|
||||||
|
This method is used to create multiple price sets.
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
To create price sets with a default price, don't pass any rules and make sure to pass the `currency_code` of the price. For example:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function createPriceSets () {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const priceSets = await pricingService.create([
|
||||||
|
{
|
||||||
|
rules: [],
|
||||||
|
prices: [
|
||||||
|
{
|
||||||
|
amount: 500,
|
||||||
|
currency_code: "USD",
|
||||||
|
rules: {},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
|
// do something with the price sets or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
To create price sets and associate them with rule types:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function createPriceSets () {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const priceSets = await pricingService.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",
|
||||||
|
min_quantity: 0,
|
||||||
|
max_quantity: 4,
|
||||||
|
rules: {
|
||||||
|
region_id: "PL"
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
amount: 450,
|
||||||
|
currency_code: "EUR",
|
||||||
|
rules: {
|
||||||
|
city: "krakow"
|
||||||
|
},
|
||||||
|
}
|
||||||
|
],
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
|
// do something with the price sets or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"data","type":"[`CreatePriceSetDTO`](../../interfaces/CreatePriceSetDTO.mdx)[]","description":"The price sets to create.","optional":false,"defaultValue":"","children":[{"name":"prices","type":"[`CreatePricesDTO`](../../interfaces/CreatePricesDTO.mdx)[]","description":"The prices to create and add to this price set.","optional":true,"defaultValue":"","children":[{"name":"amount","type":"`number`","description":"The amount of this money amount.","optional":true,"defaultValue":"","children":[]},{"name":"currency","type":"[`CreateCurrencyDTO`](../../interfaces/CreateCurrencyDTO.mdx)","description":"The currency of this money amount.","optional":true,"defaultValue":"","children":[]},{"name":"currency_code","type":"`string`","description":"The currency code of this money amount.","optional":false,"defaultValue":"","children":[]},{"name":"id","type":"`string`","description":"The ID of the money amount.","optional":true,"defaultValue":"","children":[]},{"name":"max_quantity","type":"`number`","description":"The maximum quantity required to be purchased for this money amount to be applied.","optional":true,"defaultValue":"","children":[]},{"name":"min_quantity","type":"`number`","description":"The minimum quantity required to be purchased for this money amount to be applied.","optional":true,"defaultValue":"","children":[]},{"name":"rules","type":"Record<`string`, `string`\\>","description":"The rules to add to the price. The object's keys are rule types' `rule_attribute` attribute, and values are the value of that rule associated with this price.","optional":false,"defaultValue":"","children":[]}]},{"name":"rules","type":"{ `rule_attribute`: `string` }[]","description":"The rules to associate with the price set. The value of `attribute` is the value of the rule's `rule_attribute` attribute.","optional":true,"defaultValue":"","children":[]}]},{"name":"sharedContext","type":"[`Context`](../../interfaces/Context.mdx)","description":"A context used to share resources, such as transaction manager, between the application and the module.","optional":true,"defaultValue":"","children":[{"name":"enableNestedTransactions","type":"`boolean`","description":"a boolean value indicating whether nested transactions are enabled.","optional":true,"defaultValue":"","children":[]},{"name":"isolationLevel","type":"`string`","description":"A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.","optional":true,"defaultValue":"","children":[]},{"name":"manager","type":"`TManager`","description":"An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.","optional":true,"defaultValue":"","children":[]},{"name":"transactionId","type":"`string`","description":"a string indicating the ID of the current transaction.","optional":true,"defaultValue":"","children":[]},{"name":"transactionManager","type":"`TManager`","description":"An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.","optional":true,"defaultValue":"","children":[]}]}]} />
|
||||||
|
|
||||||
|
### Returns
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"Promise","type":"`Promise`<[`PriceSetDTO`](../../interfaces/PriceSetDTO.mdx)[]\\>","optional":false,"defaultValue":"","description":"The list of created price sets.","children":[{"name":"PriceSetDTO[]","type":"[`PriceSetDTO`](../../interfaces/PriceSetDTO.mdx)[]","optional":false,"defaultValue":"","description":"","children":[{"name":"PriceSetDTO","type":"`object`","description":"A price set's data.","optional":false,"defaultValue":"","children":[]}]}]}]} />
|
||||||
-67
@@ -1,67 +0,0 @@
|
|||||||
---
|
|
||||||
displayed_sidebar: pricingReference
|
|
||||||
badge:
|
|
||||||
variant: orange
|
|
||||||
text: Beta
|
|
||||||
slug: /references/pricing/createCurrencies
|
|
||||||
sidebar_label: createCurrencies
|
|
||||||
---
|
|
||||||
|
|
||||||
# createCurrencies - Pricing Module Reference
|
|
||||||
|
|
||||||
This documentation provides a reference to the createCurrencies method. This belongs to the Pricing Module.
|
|
||||||
|
|
||||||
This method is used to create new currencies.
|
|
||||||
|
|
||||||
## Parameters
|
|
||||||
|
|
||||||
- `data`: An array of objects of type [CreateCurrencyDTO](../../interfaces/CreateCurrencyDTO.md), each object holding the data of a currency to create. Its items accept the following properties:
|
|
||||||
- `code`: a string indicating the code of the currency.
|
|
||||||
- `name`: a string indicating the name of the currency.
|
|
||||||
- `symbol`: a string indicating the symbol of the currency.
|
|
||||||
- `symbol_native`: a string indicating the symbol of the currecy in its native form. This is typically the symbol used when displaying a price.
|
|
||||||
- `sharedContext`: (optional) An object of type [Context](../../interfaces/Context.md) used to share resources, such as transaction manager, between the application and the module. It accepts the following properties:
|
|
||||||
- `enableNestedTransactions`: (optional) a boolean value indicating whether nested transactions are enabled.
|
|
||||||
- `isolationLevel`: (optional) A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.
|
|
||||||
- `manager`: (optional) An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.
|
|
||||||
- `transactionId`: (optional) a string indicating the ID of the current transaction.
|
|
||||||
- `transactionManager`: (optional) An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.
|
|
||||||
|
|
||||||
## Returns
|
|
||||||
|
|
||||||
A promise that resolves to an array of objects of type [CurrencyDTO](../../interfaces/CurrencyDTO.md), each object being a created currency.
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary>
|
|
||||||
CurrencyDTO
|
|
||||||
</summary>
|
|
||||||
|
|
||||||
- `code`: a string indicating the code of the currency.
|
|
||||||
- `name`: (optional) a string indicating the name of the currency.
|
|
||||||
- `symbol`: (optional) a string indicating the symbol of the currency.
|
|
||||||
- `symbol_native`: (optional) a string indicating the symbol of the currecy in its native form. This is typically the symbol used when displaying a price.
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
## Example
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function createCurrencies () {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const currencies = await pricingService.createCurrencies([
|
|
||||||
{
|
|
||||||
code: "USD",
|
|
||||||
symbol: "$",
|
|
||||||
symbol_native: "$",
|
|
||||||
name: "US Dollar",
|
|
||||||
}
|
|
||||||
])
|
|
||||||
|
|
||||||
// do something with the currencies or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
+47
@@ -0,0 +1,47 @@
|
|||||||
|
---
|
||||||
|
displayed_sidebar: pricingReference
|
||||||
|
badge:
|
||||||
|
variant: orange
|
||||||
|
text: Beta
|
||||||
|
slug: /references/pricing/createCurrencies
|
||||||
|
sidebar_label: createCurrencies
|
||||||
|
---
|
||||||
|
|
||||||
|
import ParameterTypes from "@site/src/components/ParameterTypes"
|
||||||
|
|
||||||
|
# createCurrencies - Pricing Module Reference
|
||||||
|
|
||||||
|
This documentation provides a reference to the `createCurrencies` method. This belongs to the Pricing Module.
|
||||||
|
|
||||||
|
This method is used to create new currencies.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function createCurrencies () {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const currencies = await pricingService.createCurrencies([
|
||||||
|
{
|
||||||
|
code: "USD",
|
||||||
|
symbol: "$",
|
||||||
|
symbol_native: "$",
|
||||||
|
name: "US Dollar",
|
||||||
|
}
|
||||||
|
])
|
||||||
|
|
||||||
|
// do something with the currencies or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"data","type":"[`CreateCurrencyDTO`](../../interfaces/CreateCurrencyDTO.mdx)[]","description":"The currencies to create.","optional":false,"defaultValue":"","children":[{"name":"code","type":"`string`","description":"The code of the currency.","optional":false,"defaultValue":"","children":[]},{"name":"name","type":"`string`","description":"The name of the currency.","optional":false,"defaultValue":"","children":[]},{"name":"symbol","type":"`string`","description":"The symbol of the currency.","optional":false,"defaultValue":"","children":[]},{"name":"symbol_native","type":"`string`","description":"The symbol of the currecy in its native form. This is typically the symbol used when displaying a price.","optional":false,"defaultValue":"","children":[]}]},{"name":"sharedContext","type":"[`Context`](../../interfaces/Context.mdx)","description":"A context used to share resources, such as transaction manager, between the application and the module.","optional":true,"defaultValue":"","children":[{"name":"enableNestedTransactions","type":"`boolean`","description":"a boolean value indicating whether nested transactions are enabled.","optional":true,"defaultValue":"","children":[]},{"name":"isolationLevel","type":"`string`","description":"A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.","optional":true,"defaultValue":"","children":[]},{"name":"manager","type":"`TManager`","description":"An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.","optional":true,"defaultValue":"","children":[]},{"name":"transactionId","type":"`string`","description":"a string indicating the ID of the current transaction.","optional":true,"defaultValue":"","children":[]},{"name":"transactionManager","type":"`TManager`","description":"An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.","optional":true,"defaultValue":"","children":[]}]}]} />
|
||||||
|
|
||||||
|
## Returns
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"Promise","type":"`Promise`<[`CurrencyDTO`](../../interfaces/CurrencyDTO.mdx)[]\\>","optional":false,"defaultValue":"","description":"The list of created currencies.","children":[{"name":"CurrencyDTO[]","type":"[`CurrencyDTO`](../../interfaces/CurrencyDTO.mdx)[]","optional":false,"defaultValue":"","description":"","children":[{"name":"CurrencyDTO","type":"`object`","description":"A currency's data.","optional":false,"defaultValue":"","children":[]}]}]}]} />
|
||||||
-83
@@ -1,83 +0,0 @@
|
|||||||
---
|
|
||||||
displayed_sidebar: pricingReference
|
|
||||||
badge:
|
|
||||||
variant: orange
|
|
||||||
text: Beta
|
|
||||||
slug: /references/pricing/createMoneyAmounts
|
|
||||||
sidebar_label: createMoneyAmounts
|
|
||||||
---
|
|
||||||
|
|
||||||
# createMoneyAmounts - Pricing Module Reference
|
|
||||||
|
|
||||||
This documentation provides a reference to the createMoneyAmounts method. This belongs to the Pricing Module.
|
|
||||||
|
|
||||||
This method creates money amounts.
|
|
||||||
|
|
||||||
## Parameters
|
|
||||||
|
|
||||||
- `data`: An array of objects of type [CreateMoneyAmountDTO](../../interfaces/CreateMoneyAmountDTO.md) that holds the necessary data to create the money amount. Its items accept the following properties:
|
|
||||||
- `amount`: (optional) A number indicating the amount of this money amount.
|
|
||||||
- `currency`: (optional) An object of type [CurrencyDTO](../../interfaces/CurrencyDTO.md) that holds the details of the money amount's currency. Since this is a relation, it will only be retrieved if it's passed to the `relations` array of the find-configuration options. It accepts the following properties:
|
|
||||||
- `code`: a string indicating the code of the currency.
|
|
||||||
- `name`: (optional) a string indicating the name of the currency.
|
|
||||||
- `symbol`: (optional) a string indicating the symbol of the currency.
|
|
||||||
- `symbol_native`: (optional) a string indicating the symbol of the currecy in its native form. This is typically the symbol used when displaying a price.
|
|
||||||
- `currency_code`: A string that indicates the currency code of this money amount.
|
|
||||||
- `id`: (optional) A string that indicates the ID of the money amount.
|
|
||||||
- `max_quantity`: (optional) A number that indicates the maximum quantity required to be purchased for this money amount to be applied.
|
|
||||||
- `min_quantity`: (optional) A number that indicates the minimum quantity required to be purchased for this money amount to be applied.
|
|
||||||
- `sharedContext`: (optional) An object of type [Context](../../interfaces/Context.md) used to share resources, such as transaction manager, between the application and the module. It accepts the following properties:
|
|
||||||
- `enableNestedTransactions`: (optional) a boolean value indicating whether nested transactions are enabled.
|
|
||||||
- `isolationLevel`: (optional) A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.
|
|
||||||
- `manager`: (optional) An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.
|
|
||||||
- `transactionId`: (optional) a string indicating the ID of the current transaction.
|
|
||||||
- `transactionManager`: (optional) An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.
|
|
||||||
|
|
||||||
## Returns
|
|
||||||
|
|
||||||
A promise that resolves to an array of objects of type [MoneyAmountDTO](../../interfaces/MoneyAmountDTO.md), each being a created money amount.
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary>
|
|
||||||
MoneyAmountDTO
|
|
||||||
</summary>
|
|
||||||
|
|
||||||
- `amount`: (optional) A number indicating the amount of this price.
|
|
||||||
- `currency`: (optional) An object of type [CurrencyDTO](../../interfaces/CurrencyDTO.md) that holds the details of the price's currency. Since this is a relation, it will only be retrieved if it's passed to the `relations` array of the find-configuration options. It accepts the following properties:
|
|
||||||
- `code`: a string indicating the code of the currency.
|
|
||||||
- `name`: (optional) a string indicating the name of the currency.
|
|
||||||
- `symbol`: (optional) a string indicating the symbol of the currency.
|
|
||||||
- `symbol_native`: (optional) a string indicating the symbol of the currecy in its native form. This is typically the symbol used when displaying a price.
|
|
||||||
- `currency_code`: (optional) A string that indicates the currency code of this price.
|
|
||||||
- `id`: A string that indicates the ID of the money amount. A money amount represents a price.
|
|
||||||
- `max_quantity`: (optional) A number that indicates the maximum quantity required to be purchased for this price to be applied.
|
|
||||||
- `min_quantity`: (optional) A number that indicates the minimum quantity required to be purchased for this price to be applied.
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
## Example
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function retrieveMoneyAmounts () {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const moneyAmounts = await pricingService.createMoneyAmounts([
|
|
||||||
{
|
|
||||||
amount: 500,
|
|
||||||
currency_code: "USD",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
amount: 400,
|
|
||||||
currency_code: "USD",
|
|
||||||
min_quantity: 0,
|
|
||||||
max_quantity: 4
|
|
||||||
}
|
|
||||||
])
|
|
||||||
|
|
||||||
// do something with the money amounts or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
+51
@@ -0,0 +1,51 @@
|
|||||||
|
---
|
||||||
|
displayed_sidebar: pricingReference
|
||||||
|
badge:
|
||||||
|
variant: orange
|
||||||
|
text: Beta
|
||||||
|
slug: /references/pricing/createMoneyAmounts
|
||||||
|
sidebar_label: createMoneyAmounts
|
||||||
|
---
|
||||||
|
|
||||||
|
import ParameterTypes from "@site/src/components/ParameterTypes"
|
||||||
|
|
||||||
|
# createMoneyAmounts - Pricing Module Reference
|
||||||
|
|
||||||
|
This documentation provides a reference to the `createMoneyAmounts` method. This belongs to the Pricing Module.
|
||||||
|
|
||||||
|
This method creates money amounts.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function retrieveMoneyAmounts () {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const moneyAmounts = await pricingService.createMoneyAmounts([
|
||||||
|
{
|
||||||
|
amount: 500,
|
||||||
|
currency_code: "USD",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
amount: 400,
|
||||||
|
currency_code: "USD",
|
||||||
|
min_quantity: 0,
|
||||||
|
max_quantity: 4
|
||||||
|
}
|
||||||
|
])
|
||||||
|
|
||||||
|
// do something with the money amounts or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"data","type":"[`CreateMoneyAmountDTO`](../../interfaces/CreateMoneyAmountDTO.mdx)[]","description":"The money amounts to create.","optional":false,"defaultValue":"","children":[{"name":"amount","type":"`number`","description":"The amount of this money amount.","optional":true,"defaultValue":"","children":[]},{"name":"currency","type":"[`CreateCurrencyDTO`](../../interfaces/CreateCurrencyDTO.mdx)","description":"The currency of this money amount.","optional":true,"defaultValue":"","children":[{"name":"code","type":"`string`","description":"The code of the currency.","optional":false,"defaultValue":"","children":[]},{"name":"name","type":"`string`","description":"The name of the currency.","optional":false,"defaultValue":"","children":[]},{"name":"symbol","type":"`string`","description":"The symbol of the currency.","optional":false,"defaultValue":"","children":[]},{"name":"symbol_native","type":"`string`","description":"The symbol of the currecy in its native form. This is typically the symbol used when displaying a price.","optional":false,"defaultValue":"","children":[]}]},{"name":"currency_code","type":"`string`","description":"The currency code of this money amount.","optional":false,"defaultValue":"","children":[]},{"name":"id","type":"`string`","description":"The ID of the money amount.","optional":true,"defaultValue":"","children":[]},{"name":"max_quantity","type":"`number`","description":"The maximum quantity required to be purchased for this money amount to be applied.","optional":true,"defaultValue":"","children":[]},{"name":"min_quantity","type":"`number`","description":"The minimum quantity required to be purchased for this money amount to be applied.","optional":true,"defaultValue":"","children":[]}]},{"name":"sharedContext","type":"[`Context`](../../interfaces/Context.mdx)","description":"A context used to share resources, such as transaction manager, between the application and the module.","optional":true,"defaultValue":"","children":[{"name":"enableNestedTransactions","type":"`boolean`","description":"a boolean value indicating whether nested transactions are enabled.","optional":true,"defaultValue":"","children":[]},{"name":"isolationLevel","type":"`string`","description":"A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.","optional":true,"defaultValue":"","children":[]},{"name":"manager","type":"`TManager`","description":"An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.","optional":true,"defaultValue":"","children":[]},{"name":"transactionId","type":"`string`","description":"a string indicating the ID of the current transaction.","optional":true,"defaultValue":"","children":[]},{"name":"transactionManager","type":"`TManager`","description":"An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.","optional":true,"defaultValue":"","children":[]}]}]} />
|
||||||
|
|
||||||
|
## Returns
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"Promise","type":"`Promise`<[`MoneyAmountDTO`](../../interfaces/MoneyAmountDTO.mdx)[]\\>","optional":false,"defaultValue":"","description":"The list of created money amounts.","children":[{"name":"MoneyAmountDTO[]","type":"[`MoneyAmountDTO`](../../interfaces/MoneyAmountDTO.mdx)[]","optional":false,"defaultValue":"","description":"","children":[{"name":"MoneyAmountDTO","type":"`object`","description":"A money amount's data. A money amount represents a price.","optional":false,"defaultValue":"","children":[]}]}]}]} />
|
||||||
-103
@@ -1,103 +0,0 @@
|
|||||||
---
|
|
||||||
displayed_sidebar: pricingReference
|
|
||||||
badge:
|
|
||||||
variant: orange
|
|
||||||
text: Beta
|
|
||||||
slug: /references/pricing/createPriceRules
|
|
||||||
sidebar_label: createPriceRules
|
|
||||||
---
|
|
||||||
|
|
||||||
# createPriceRules - Pricing Module Reference
|
|
||||||
|
|
||||||
This documentation provides a reference to the createPriceRules method. This belongs to the Pricing Module.
|
|
||||||
|
|
||||||
This method is used to create new price rules based on the provided data.
|
|
||||||
|
|
||||||
## Parameters
|
|
||||||
|
|
||||||
- `data`: An array of objects of type [CreatePriceRuleDTO](../../interfaces/CreatePriceRuleDTO.md), each containing the data necessary to create a price rule. Its items accept the following properties:
|
|
||||||
- `id`: A string indicating the ID of the price rule.
|
|
||||||
- `is_dynamic`: (optional) A boolean indicating whether the price rule is dynamic.
|
|
||||||
- `price_list_id`: A string indicating the ID of the associated price list.
|
|
||||||
- `price_set_id`: A string indicating the ID of the associated price set.
|
|
||||||
- `price_set_money_amount_id`: A string indicating the ID of the associated price set money amount.
|
|
||||||
- `priority`: (optional) A number indicating the priority of the price rule in comparison to other applicable price rules.
|
|
||||||
- `rule_type_id`: A string indicating the ID of the associated rule type.
|
|
||||||
- `value`: A string indicating the value of the price rule.
|
|
||||||
- `sharedContext`: (optional) An object of type [Context](../../interfaces/Context.md) used to share resources, such as transaction manager, between the application and the module. It accepts the following properties:
|
|
||||||
- `enableNestedTransactions`: (optional) a boolean value indicating whether nested transactions are enabled.
|
|
||||||
- `isolationLevel`: (optional) A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.
|
|
||||||
- `manager`: (optional) An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.
|
|
||||||
- `transactionId`: (optional) a string indicating the ID of the current transaction.
|
|
||||||
- `transactionManager`: (optional) An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.
|
|
||||||
|
|
||||||
## Returns
|
|
||||||
|
|
||||||
A promise that resolves to an array of objects of type [PriceRuleDTO](../../interfaces/PriceRuleDTO.md), each being a created price rule.
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary>
|
|
||||||
PriceRuleDTO
|
|
||||||
</summary>
|
|
||||||
|
|
||||||
- `id`: A string indicating the ID of the price rule.
|
|
||||||
- `is_dynamic`: A boolean indicating whether the price rule is dynamic.
|
|
||||||
- `price_list_id`: A string indicating the ID of the associated price list.
|
|
||||||
- `price_set`: An object of type [PriceSetDTO](../../interfaces/PriceSetDTO.md) that holds the data of the associated price set. It may only be available if the relation `price_set` is expanded. It accepts the following properties:
|
|
||||||
- `id`: A string indicating the ID of the price set.
|
|
||||||
- `money_amounts`: (optional) An array of objects of type [MoneyAmountDTO](../../interfaces/MoneyAmountDTO.md), which holds the prices that belong to this price set. Its items accept the following properties:
|
|
||||||
- `amount`: (optional) A number indicating the amount of this price.
|
|
||||||
- `currency`: (optional) An object of type [CurrencyDTO](../../interfaces/CurrencyDTO.md) that holds the details of the price's currency. Since this is a relation, it will only be retrieved if it's passed to the `relations` array of the find-configuration options.
|
|
||||||
- `currency_code`: (optional) A string that indicates the currency code of this price.
|
|
||||||
- `id`: A string that indicates the ID of the money amount. A money amount represents a price.
|
|
||||||
- `max_quantity`: (optional) A number that indicates the maximum quantity required to be purchased for this price to be applied.
|
|
||||||
- `min_quantity`: (optional) A number that indicates the minimum quantity required to be purchased for this price to be applied.
|
|
||||||
- `rule_types`: (optional) An array of objects of type [RuleTypeDTO](../../interfaces/RuleTypeDTO.md), which holds the rule types applied on this price set. Its items accept the following properties:
|
|
||||||
- `default_priority`: A number indicating the priority of the rule type. This is useful when calculating the price of a price set, and multiple rules satisfy the provided context. The higher the value, the higher the priority of the rule type.
|
|
||||||
- `id`: A string indicating the ID of the rule type.
|
|
||||||
- `name`: A string indicating the display name of the rule type.
|
|
||||||
- `rule_attribute`: A string indicating a unique name used to later identify the rule_attribute. For example, it can be used in the `context` parameter of the `calculatePrices` method to specify a rule for calculating the price.
|
|
||||||
- `price_set_id`: A string indicating the ID of the associated price set.
|
|
||||||
- `price_set_money_amount_id`: A string indicating the ID of the associated price set money amount.
|
|
||||||
- `priority`: A number indicating the priority of the price rule in comparison to other applicable price rules.
|
|
||||||
- `rule_type`: An object of type [RuleTypeDTO](../../interfaces/RuleTypeDTO.md) that holds the data of the associated rule type. It may only be available if the relation `rule_type` is expanded. It accepts the following properties:
|
|
||||||
- `default_priority`: A number indicating the priority of the rule type. This is useful when calculating the price of a price set, and multiple rules satisfy the provided context. The higher the value, the higher the priority of the rule type.
|
|
||||||
- `id`: A string indicating the ID of the rule type.
|
|
||||||
- `name`: A string indicating the display name of the rule type.
|
|
||||||
- `rule_attribute`: A string indicating a unique name used to later identify the rule_attribute. For example, it can be used in the `context` parameter of the `calculatePrices` method to specify a rule for calculating the price.
|
|
||||||
- `rule_type_id`: A string indicating the ID of the associated rule type.
|
|
||||||
- `value`: A string indicating the value of the price rule.
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
## Example
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function createPriceRules (
|
|
||||||
id: string,
|
|
||||||
priceSetId: string,
|
|
||||||
ruleTypeId: string,
|
|
||||||
value: string,
|
|
||||||
priceSetMoneyAmountId: string,
|
|
||||||
priceListId: string
|
|
||||||
) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const priceRules = await pricingService.createPriceRules([
|
|
||||||
{
|
|
||||||
id,
|
|
||||||
price_set_id: priceSetId,
|
|
||||||
rule_type_id: ruleTypeId,
|
|
||||||
value,
|
|
||||||
price_set_money_amount_id: priceSetMoneyAmountId,
|
|
||||||
price_list_id: priceListId
|
|
||||||
}
|
|
||||||
])
|
|
||||||
|
|
||||||
// do something with the price rules or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
+56
@@ -0,0 +1,56 @@
|
|||||||
|
---
|
||||||
|
displayed_sidebar: pricingReference
|
||||||
|
badge:
|
||||||
|
variant: orange
|
||||||
|
text: Beta
|
||||||
|
slug: /references/pricing/createPriceRules
|
||||||
|
sidebar_label: createPriceRules
|
||||||
|
---
|
||||||
|
|
||||||
|
import ParameterTypes from "@site/src/components/ParameterTypes"
|
||||||
|
|
||||||
|
# createPriceRules - Pricing Module Reference
|
||||||
|
|
||||||
|
This documentation provides a reference to the `createPriceRules` method. This belongs to the Pricing Module.
|
||||||
|
|
||||||
|
This method is used to create new price rules based on the provided data.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function createPriceRules (
|
||||||
|
id: string,
|
||||||
|
priceSetId: string,
|
||||||
|
ruleTypeId: string,
|
||||||
|
value: string,
|
||||||
|
priceSetMoneyAmountId: string,
|
||||||
|
priceListId: string
|
||||||
|
) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const priceRules = await pricingService.createPriceRules([
|
||||||
|
{
|
||||||
|
id,
|
||||||
|
price_set_id: priceSetId,
|
||||||
|
rule_type_id: ruleTypeId,
|
||||||
|
value,
|
||||||
|
price_set_money_amount_id: priceSetMoneyAmountId,
|
||||||
|
price_list_id: priceListId
|
||||||
|
}
|
||||||
|
])
|
||||||
|
|
||||||
|
// do something with the price rules or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"data","type":"[`CreatePriceRuleDTO`](../../interfaces/CreatePriceRuleDTO.mdx)[]","description":"The price rules to create.","optional":false,"defaultValue":"","children":[{"name":"id","type":"`string`","description":"The ID of the price rule.","optional":false,"defaultValue":"","children":[]},{"name":"price_list_id","type":"`string`","description":"The ID of the associated price list.","optional":false,"defaultValue":"","children":[]},{"name":"price_set_id","type":"`string`","description":"The ID of the associated price set.","optional":false,"defaultValue":"","children":[]},{"name":"price_set_money_amount_id","type":"`string`","description":"The ID of the associated price set money amount.","optional":false,"defaultValue":"","children":[]},{"name":"priority","type":"`number`","description":"The priority of the price rule in comparison to other applicable price rules.","optional":true,"defaultValue":"","children":[]},{"name":"rule_type_id","type":"`string`","description":"The ID of the associated rule type.","optional":false,"defaultValue":"","children":[]},{"name":"value","type":"`string`","description":"The value of the price rule.","optional":false,"defaultValue":"","children":[]}]},{"name":"sharedContext","type":"[`Context`](../../interfaces/Context.mdx)","description":"A context used to share resources, such as transaction manager, between the application and the module.","optional":true,"defaultValue":"","children":[{"name":"enableNestedTransactions","type":"`boolean`","description":"a boolean value indicating whether nested transactions are enabled.","optional":true,"defaultValue":"","children":[]},{"name":"isolationLevel","type":"`string`","description":"A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.","optional":true,"defaultValue":"","children":[]},{"name":"manager","type":"`TManager`","description":"An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.","optional":true,"defaultValue":"","children":[]},{"name":"transactionId","type":"`string`","description":"a string indicating the ID of the current transaction.","optional":true,"defaultValue":"","children":[]},{"name":"transactionManager","type":"`TManager`","description":"An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.","optional":true,"defaultValue":"","children":[]}]}]} />
|
||||||
|
|
||||||
|
## Returns
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"Promise","type":"`Promise`<[`PriceRuleDTO`](../../interfaces/PriceRuleDTO.mdx)[]\\>","optional":false,"defaultValue":"","description":"The list of created price rules.","children":[{"name":"PriceRuleDTO[]","type":"[`PriceRuleDTO`](../../interfaces/PriceRuleDTO.mdx)[]","optional":false,"defaultValue":"","description":"","children":[{"name":"PriceRuleDTO","type":"`object`","description":"A price rule's data.","optional":false,"defaultValue":"","children":[]}]}]}]} />
|
||||||
-84
@@ -1,84 +0,0 @@
|
|||||||
---
|
|
||||||
displayed_sidebar: pricingReference
|
|
||||||
badge:
|
|
||||||
variant: orange
|
|
||||||
text: Beta
|
|
||||||
slug: /references/pricing/createPriceSetMoneyAmountRules
|
|
||||||
sidebar_label: createPriceSetMoneyAmountRules
|
|
||||||
---
|
|
||||||
|
|
||||||
# createPriceSetMoneyAmountRules - Pricing Module Reference
|
|
||||||
|
|
||||||
This documentation provides a reference to the createPriceSetMoneyAmountRules method. This belongs to the Pricing Module.
|
|
||||||
|
|
||||||
This method is used to create new price set money amount rules. A price set money amount rule creates an association between a price set money amount and
|
|
||||||
a rule type.
|
|
||||||
|
|
||||||
## Parameters
|
|
||||||
|
|
||||||
- `data`: An array of objects of type [CreatePriceSetMoneyAmountRulesDTO](../../interfaces/CreatePriceSetMoneyAmountRulesDTO.md), each containing the data of a price set money amount rule to create. Its items accept the following properties:
|
|
||||||
- `price_set_money_amount`: A string indicating the ID of a price set money amount.
|
|
||||||
- `rule_type`: A string indicating the ID of a rule type.
|
|
||||||
- `value`: A string indicating the value of the price set money amount rule.
|
|
||||||
- `sharedContext`: (optional) An object of type [Context](../../interfaces/Context.md) used to share resources, such as transaction manager, between the application and the module. It accepts the following properties:
|
|
||||||
- `enableNestedTransactions`: (optional) a boolean value indicating whether nested transactions are enabled.
|
|
||||||
- `isolationLevel`: (optional) A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.
|
|
||||||
- `manager`: (optional) An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.
|
|
||||||
- `transactionId`: (optional) a string indicating the ID of the current transaction.
|
|
||||||
- `transactionManager`: (optional) An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.
|
|
||||||
|
|
||||||
## Returns
|
|
||||||
|
|
||||||
A promise that resolves to an array of objects of type [PriceSetMoneyAmountRulesDTO](../../interfaces/PriceSetMoneyAmountRulesDTO.md), each being
|
|
||||||
a created price set money amount rule.
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary>
|
|
||||||
PriceSetMoneyAmountRulesDTO
|
|
||||||
</summary>
|
|
||||||
|
|
||||||
- `id`: A string indicating the ID of the price set money amount.
|
|
||||||
- `price_set_money_amount`: an object of type [PriceSetMoneyAmountDTO](../../interfaces/PriceSetMoneyAmountDTO.md) holding the data of the associated price set money amount. It accepts the following properties:
|
|
||||||
- `id`: a string indicating the ID of a price set money amount.
|
|
||||||
- `money_amount`: (optional) an object of type [MoneyAmountDTO](../../interfaces/MoneyAmountDTO.md) holding the data of the associated money amount. It accepts the following properties:
|
|
||||||
- `amount`: (optional) A number indicating the amount of this price.
|
|
||||||
- `currency`: (optional) An object of type [CurrencyDTO](../../interfaces/CurrencyDTO.md) that holds the details of the price's currency. Since this is a relation, it will only be retrieved if it's passed to the `relations` array of the find-configuration options.
|
|
||||||
- `currency_code`: (optional) A string that indicates the currency code of this price.
|
|
||||||
- `id`: A string that indicates the ID of the money amount. A money amount represents a price.
|
|
||||||
- `max_quantity`: (optional) A number that indicates the maximum quantity required to be purchased for this price to be applied.
|
|
||||||
- `min_quantity`: (optional) A number that indicates the minimum quantity required to be purchased for this price to be applied.
|
|
||||||
- `price_set`: (optional) an object of type [PriceSetDTO](../../interfaces/PriceSetDTO.md) holding the data of the associated price set. It accepts the following properties:
|
|
||||||
- `id`: A string indicating the ID of the price set.
|
|
||||||
- `money_amounts`: (optional) An array of objects of type [MoneyAmountDTO](../../interfaces/MoneyAmountDTO.md), which holds the prices that belong to this price set.
|
|
||||||
- `rule_types`: (optional) An array of objects of type [RuleTypeDTO](../../interfaces/RuleTypeDTO.md), which holds the rule types applied on this price set.
|
|
||||||
- `title`: (optional) a string indicating the title of the price set money amount.
|
|
||||||
- `rule_type`: an object of type [RuleTypeDTO](../../interfaces/RuleTypeDTO.md) holding the data of the associated rule type. It accepts the following properties:
|
|
||||||
- `default_priority`: A number indicating the priority of the rule type. This is useful when calculating the price of a price set, and multiple rules satisfy the provided context. The higher the value, the higher the priority of the rule type.
|
|
||||||
- `id`: A string indicating the ID of the rule type.
|
|
||||||
- `name`: A string indicating the display name of the rule type.
|
|
||||||
- `rule_attribute`: A string indicating a unique name used to later identify the rule_attribute. For example, it can be used in the `context` parameter of the `calculatePrices` method to specify a rule for calculating the price.
|
|
||||||
- `value`: a string indicating the value of the price set money amount rule.
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
## Example
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function createPriceSetMoneyAmountRules (priceSetMoneyAmountId: string, ruleTypeId: string, value: string) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const priceSetMoneyAmountRules = await pricingService.createPriceSetMoneyAmountRules([
|
|
||||||
{
|
|
||||||
price_set_money_amount: priceSetMoneyAmountId,
|
|
||||||
rule_type: ruleTypeId,
|
|
||||||
value
|
|
||||||
}
|
|
||||||
])
|
|
||||||
|
|
||||||
// do something with the price set money amount rules or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
+47
@@ -0,0 +1,47 @@
|
|||||||
|
---
|
||||||
|
displayed_sidebar: pricingReference
|
||||||
|
badge:
|
||||||
|
variant: orange
|
||||||
|
text: Beta
|
||||||
|
slug: /references/pricing/createPriceSetMoneyAmountRules
|
||||||
|
sidebar_label: createPriceSetMoneyAmountRules
|
||||||
|
---
|
||||||
|
|
||||||
|
import ParameterTypes from "@site/src/components/ParameterTypes"
|
||||||
|
|
||||||
|
# createPriceSetMoneyAmountRules - Pricing Module Reference
|
||||||
|
|
||||||
|
This documentation provides a reference to the `createPriceSetMoneyAmountRules` method. This belongs to the Pricing Module.
|
||||||
|
|
||||||
|
This method is used to create new price set money amount rules. A price set money amount rule creates an association between a price set money amount and
|
||||||
|
a rule type.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function createPriceSetMoneyAmountRules (priceSetMoneyAmountId: string, ruleTypeId: string, value: string) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const priceSetMoneyAmountRules = await pricingService.createPriceSetMoneyAmountRules([
|
||||||
|
{
|
||||||
|
price_set_money_amount: priceSetMoneyAmountId,
|
||||||
|
rule_type: ruleTypeId,
|
||||||
|
value
|
||||||
|
}
|
||||||
|
])
|
||||||
|
|
||||||
|
// do something with the price set money amount rules or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"data","type":"[`CreatePriceSetMoneyAmountRulesDTO`](../../interfaces/CreatePriceSetMoneyAmountRulesDTO.mdx)[]","description":"The price set money amount rules to create.","optional":false,"defaultValue":"","children":[{"name":"price_set_money_amount","type":"`string`","description":"The ID of a price set money amount.","optional":false,"defaultValue":"","children":[]},{"name":"rule_type","type":"`string`","description":"The ID of a rule type.","optional":false,"defaultValue":"","children":[]},{"name":"value","type":"`string`","description":"The value of the price set money amount rule.","optional":false,"defaultValue":"","children":[]}]},{"name":"sharedContext","type":"[`Context`](../../interfaces/Context.mdx)","description":"A context used to share resources, such as transaction manager, between the application and the module.","optional":true,"defaultValue":"","children":[{"name":"enableNestedTransactions","type":"`boolean`","description":"a boolean value indicating whether nested transactions are enabled.","optional":true,"defaultValue":"","children":[]},{"name":"isolationLevel","type":"`string`","description":"A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.","optional":true,"defaultValue":"","children":[]},{"name":"manager","type":"`TManager`","description":"An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.","optional":true,"defaultValue":"","children":[]},{"name":"transactionId","type":"`string`","description":"a string indicating the ID of the current transaction.","optional":true,"defaultValue":"","children":[]},{"name":"transactionManager","type":"`TManager`","description":"An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.","optional":true,"defaultValue":"","children":[]}]}]} />
|
||||||
|
|
||||||
|
## Returns
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"Promise","type":"`Promise`<[`PriceSetMoneyAmountRulesDTO`](../../interfaces/PriceSetMoneyAmountRulesDTO.mdx)[]\\>","optional":false,"defaultValue":"","description":"The list of created price set money amount rules.","children":[{"name":"PriceSetMoneyAmountRulesDTO[]","type":"[`PriceSetMoneyAmountRulesDTO`](../../interfaces/PriceSetMoneyAmountRulesDTO.mdx)[]","optional":false,"defaultValue":"","description":"","children":[{"name":"PriceSetMoneyAmountRulesDTO","type":"`object`","description":"A price set money amount rule's data.","optional":false,"defaultValue":"","children":[]}]}]}]} />
|
||||||
-65
@@ -1,65 +0,0 @@
|
|||||||
---
|
|
||||||
displayed_sidebar: pricingReference
|
|
||||||
badge:
|
|
||||||
variant: orange
|
|
||||||
text: Beta
|
|
||||||
slug: /references/pricing/createRuleTypes
|
|
||||||
sidebar_label: createRuleTypes
|
|
||||||
---
|
|
||||||
|
|
||||||
# createRuleTypes - Pricing Module Reference
|
|
||||||
|
|
||||||
This documentation provides a reference to the createRuleTypes method. This belongs to the Pricing Module.
|
|
||||||
|
|
||||||
This method is used to create new rule types.
|
|
||||||
|
|
||||||
## Parameters
|
|
||||||
|
|
||||||
- `data`: An array of objects of type [CreateRuleTypeDTO](../../interfaces/CreateRuleTypeDTO.md), each being the data to use to create a rule type. Its items accept the following properties:
|
|
||||||
- `default_priority`: (optional) A number indicating the priority of the rule type. This is useful when calculating the price of a price set, and multiple rules satisfy the provided context. The higher the value, the higher the priority of the rule type.
|
|
||||||
- `id`: (optional) A string indicating the ID of the rule type.
|
|
||||||
- `name`: A string indicating the display name of the rule type.
|
|
||||||
- `rule_attribute`: A string indicating a unique name used to later identify the rule_attribute. For example, it can be used in the `context` parameter of the `calculatePrices` method to specify a rule for calculating the price.
|
|
||||||
- `sharedContext`: (optional) An object of type [Context](../../interfaces/Context.md) used to share resources, such as transaction manager, between the application and the module. It accepts the following properties:
|
|
||||||
- `enableNestedTransactions`: (optional) a boolean value indicating whether nested transactions are enabled.
|
|
||||||
- `isolationLevel`: (optional) A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.
|
|
||||||
- `manager`: (optional) An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.
|
|
||||||
- `transactionId`: (optional) a string indicating the ID of the current transaction.
|
|
||||||
- `transactionManager`: (optional) An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.
|
|
||||||
|
|
||||||
## Returns
|
|
||||||
|
|
||||||
A promise that resolves to an array of objects of type [RuleTypeDTO](../../interfaces/RuleTypeDTO.md), each being a created rule type.
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary>
|
|
||||||
RuleTypeDTO
|
|
||||||
</summary>
|
|
||||||
|
|
||||||
- `default_priority`: A number indicating the priority of the rule type. This is useful when calculating the price of a price set, and multiple rules satisfy the provided context. The higher the value, the higher the priority of the rule type.
|
|
||||||
- `id`: A string indicating the ID of the rule type.
|
|
||||||
- `name`: A string indicating the display name of the rule type.
|
|
||||||
- `rule_attribute`: A string indicating a unique name used to later identify the rule_attribute. For example, it can be used in the `context` parameter of the `calculatePrices` method to specify a rule for calculating the price.
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
## Example
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function createRuleTypes () {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const ruleTypes = await pricingService.createRuleTypes([
|
|
||||||
{
|
|
||||||
name: "Region",
|
|
||||||
rule_attribute: "region_id"
|
|
||||||
}
|
|
||||||
])
|
|
||||||
|
|
||||||
// do something with the rule types or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
+45
@@ -0,0 +1,45 @@
|
|||||||
|
---
|
||||||
|
displayed_sidebar: pricingReference
|
||||||
|
badge:
|
||||||
|
variant: orange
|
||||||
|
text: Beta
|
||||||
|
slug: /references/pricing/createRuleTypes
|
||||||
|
sidebar_label: createRuleTypes
|
||||||
|
---
|
||||||
|
|
||||||
|
import ParameterTypes from "@site/src/components/ParameterTypes"
|
||||||
|
|
||||||
|
# createRuleTypes - Pricing Module Reference
|
||||||
|
|
||||||
|
This documentation provides a reference to the `createRuleTypes` method. This belongs to the Pricing Module.
|
||||||
|
|
||||||
|
This method is used to create new rule types.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function createRuleTypes () {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const ruleTypes = await pricingService.createRuleTypes([
|
||||||
|
{
|
||||||
|
name: "Region",
|
||||||
|
rule_attribute: "region_id"
|
||||||
|
}
|
||||||
|
])
|
||||||
|
|
||||||
|
// do something with the rule types or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"data","type":"[`CreateRuleTypeDTO`](../../interfaces/CreateRuleTypeDTO.mdx)[]","description":"The rule types to create.","optional":false,"defaultValue":"","children":[{"name":"default_priority","type":"`number`","description":"The priority of the rule type. This is useful when calculating the price of a price set, and multiple rules satisfy the provided context. The higher the value, the higher the priority of the rule type.","optional":true,"defaultValue":"","children":[]},{"name":"id","type":"`string`","description":"The ID of the rule type.","optional":true,"defaultValue":"","children":[]},{"name":"name","type":"`string`","description":"The display name of the rule type.","optional":false,"defaultValue":"","children":[]},{"name":"rule_attribute","type":"`string`","description":"The unique name used to later identify the rule_attribute. For example, it can be used in the `context` parameter of the `calculatePrices` method to specify a rule for calculating the price.","optional":false,"defaultValue":"","children":[]}]},{"name":"sharedContext","type":"[`Context`](../../interfaces/Context.mdx)","description":"A context used to share resources, such as transaction manager, between the application and the module.","optional":true,"defaultValue":"","children":[{"name":"enableNestedTransactions","type":"`boolean`","description":"a boolean value indicating whether nested transactions are enabled.","optional":true,"defaultValue":"","children":[]},{"name":"isolationLevel","type":"`string`","description":"A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.","optional":true,"defaultValue":"","children":[]},{"name":"manager","type":"`TManager`","description":"An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.","optional":true,"defaultValue":"","children":[]},{"name":"transactionId","type":"`string`","description":"a string indicating the ID of the current transaction.","optional":true,"defaultValue":"","children":[]},{"name":"transactionManager","type":"`TManager`","description":"An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.","optional":true,"defaultValue":"","children":[]}]}]} />
|
||||||
|
|
||||||
|
## Returns
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"Promise","type":"`Promise`<[`RuleTypeDTO`](../../interfaces/RuleTypeDTO.mdx)[]\\>","optional":false,"defaultValue":"","description":"The list of created rule types.","children":[{"name":"RuleTypeDTO[]","type":"[`RuleTypeDTO`](../../interfaces/RuleTypeDTO.mdx)[]","optional":false,"defaultValue":"","description":"","children":[{"name":"RuleTypeDTO","type":"`object`","description":"A rule type's data.","optional":false,"defaultValue":"","children":[]}]}]}]} />
|
||||||
-42
@@ -1,42 +0,0 @@
|
|||||||
---
|
|
||||||
displayed_sidebar: pricingReference
|
|
||||||
badge:
|
|
||||||
variant: orange
|
|
||||||
text: Beta
|
|
||||||
slug: /references/pricing/delete
|
|
||||||
sidebar_label: delete
|
|
||||||
---
|
|
||||||
|
|
||||||
# delete - Pricing Module Reference
|
|
||||||
|
|
||||||
This documentation provides a reference to the delete method. This belongs to the Pricing Module.
|
|
||||||
|
|
||||||
This method deletes price sets by their IDs.
|
|
||||||
|
|
||||||
## Parameters
|
|
||||||
|
|
||||||
- `ids`: An array of strings, each being the ID for a price set to delete.
|
|
||||||
- `sharedContext`: (optional) An object of type [Context](../../interfaces/Context.md) used to share resources, such as transaction manager, between the application and the module. It accepts the following properties:
|
|
||||||
- `enableNestedTransactions`: (optional) a boolean value indicating whether nested transactions are enabled.
|
|
||||||
- `isolationLevel`: (optional) A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.
|
|
||||||
- `manager`: (optional) An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.
|
|
||||||
- `transactionId`: (optional) a string indicating the ID of the current transaction.
|
|
||||||
- `transactionManager`: (optional) An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.
|
|
||||||
|
|
||||||
## Returns
|
|
||||||
|
|
||||||
A promise that resolves when the price sets are successfully deleted.
|
|
||||||
|
|
||||||
## Example
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function removePriceSetRule (priceSetIds: string[]) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
await pricingService.delete(priceSetIds)
|
|
||||||
}
|
|
||||||
```
|
|
||||||
+38
@@ -0,0 +1,38 @@
|
|||||||
|
---
|
||||||
|
displayed_sidebar: pricingReference
|
||||||
|
badge:
|
||||||
|
variant: orange
|
||||||
|
text: Beta
|
||||||
|
slug: /references/pricing/delete
|
||||||
|
sidebar_label: delete
|
||||||
|
---
|
||||||
|
|
||||||
|
import ParameterTypes from "@site/src/components/ParameterTypes"
|
||||||
|
|
||||||
|
# delete - Pricing Module Reference
|
||||||
|
|
||||||
|
This documentation provides a reference to the `delete` method. This belongs to the Pricing Module.
|
||||||
|
|
||||||
|
This method deletes price sets by their IDs.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function removePriceSetRule (priceSetIds: string[]) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
await pricingService.delete(priceSetIds)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"ids","type":"`string`[]","description":"The IDs of the price sets to delete.","optional":false,"defaultValue":"","children":[]},{"name":"sharedContext","type":"[`Context`](../../interfaces/Context.mdx)","description":"A context used to share resources, such as transaction manager, between the application and the module.","optional":true,"defaultValue":"","children":[{"name":"enableNestedTransactions","type":"`boolean`","description":"a boolean value indicating whether nested transactions are enabled.","optional":true,"defaultValue":"","children":[]},{"name":"isolationLevel","type":"`string`","description":"A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.","optional":true,"defaultValue":"","children":[]},{"name":"manager","type":"`TManager`","description":"An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.","optional":true,"defaultValue":"","children":[]},{"name":"transactionId","type":"`string`","description":"a string indicating the ID of the current transaction.","optional":true,"defaultValue":"","children":[]},{"name":"transactionManager","type":"`TManager`","description":"An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.","optional":true,"defaultValue":"","children":[]}]}]} />
|
||||||
|
|
||||||
|
## Returns
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"Promise","type":"`Promise`<`void`\\>","optional":false,"defaultValue":"","description":"Resolves when the price sets are successfully deleted.","children":[]}]} />
|
||||||
-43
@@ -1,43 +0,0 @@
|
|||||||
---
|
|
||||||
displayed_sidebar: pricingReference
|
|
||||||
badge:
|
|
||||||
variant: orange
|
|
||||||
text: Beta
|
|
||||||
slug: /references/pricing/deleteCurrencies
|
|
||||||
sidebar_label: deleteCurrencies
|
|
||||||
---
|
|
||||||
|
|
||||||
# deleteCurrencies - Pricing Module Reference
|
|
||||||
|
|
||||||
This documentation provides a reference to the deleteCurrencies method. This belongs to the Pricing Module.
|
|
||||||
|
|
||||||
This method is used to delete currencies based on their currency code.
|
|
||||||
|
|
||||||
## Parameters
|
|
||||||
|
|
||||||
- `currencyCodes`: An array of strings, each being a code of a currency to delete.
|
|
||||||
- `sharedContext`: (optional) An object of type [Context](../../interfaces/Context.md) used to share resources, such as transaction manager, between the application and the module. It accepts the following properties:
|
|
||||||
- `enableNestedTransactions`: (optional) a boolean value indicating whether nested transactions are enabled.
|
|
||||||
- `isolationLevel`: (optional) A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.
|
|
||||||
- `manager`: (optional) An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.
|
|
||||||
- `transactionId`: (optional) a string indicating the ID of the current transaction.
|
|
||||||
- `transactionManager`: (optional) An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.
|
|
||||||
|
|
||||||
## Returns
|
|
||||||
|
|
||||||
A promise that resolves once the currencies are deleted.
|
|
||||||
|
|
||||||
## Example
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function deleteCurrencies () {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
await pricingService.deleteCurrencies(["USD"])
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
|
||||||
+39
@@ -0,0 +1,39 @@
|
|||||||
|
---
|
||||||
|
displayed_sidebar: pricingReference
|
||||||
|
badge:
|
||||||
|
variant: orange
|
||||||
|
text: Beta
|
||||||
|
slug: /references/pricing/deleteCurrencies
|
||||||
|
sidebar_label: deleteCurrencies
|
||||||
|
---
|
||||||
|
|
||||||
|
import ParameterTypes from "@site/src/components/ParameterTypes"
|
||||||
|
|
||||||
|
# deleteCurrencies - Pricing Module Reference
|
||||||
|
|
||||||
|
This documentation provides a reference to the `deleteCurrencies` method. This belongs to the Pricing Module.
|
||||||
|
|
||||||
|
This method is used to delete currencies based on their currency code.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function deleteCurrencies () {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
await pricingService.deleteCurrencies(["USD"])
|
||||||
|
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"currencyCodes","type":"`string`[]","description":"Currency codes of the currencies to delete.","optional":false,"defaultValue":"","children":[]},{"name":"sharedContext","type":"[`Context`](../../interfaces/Context.mdx)","description":"A context used to share resources, such as transaction manager, between the application and the module.","optional":true,"defaultValue":"","children":[{"name":"enableNestedTransactions","type":"`boolean`","description":"a boolean value indicating whether nested transactions are enabled.","optional":true,"defaultValue":"","children":[]},{"name":"isolationLevel","type":"`string`","description":"A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.","optional":true,"defaultValue":"","children":[]},{"name":"manager","type":"`TManager`","description":"An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.","optional":true,"defaultValue":"","children":[]},{"name":"transactionId","type":"`string`","description":"a string indicating the ID of the current transaction.","optional":true,"defaultValue":"","children":[]},{"name":"transactionManager","type":"`TManager`","description":"An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.","optional":true,"defaultValue":"","children":[]}]}]} />
|
||||||
|
|
||||||
|
## Returns
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"Promise","type":"`Promise`<`void`\\>","optional":false,"defaultValue":"","description":"Resolves once the currencies are deleted.","children":[]}]} />
|
||||||
-44
@@ -1,44 +0,0 @@
|
|||||||
---
|
|
||||||
displayed_sidebar: pricingReference
|
|
||||||
badge:
|
|
||||||
variant: orange
|
|
||||||
text: Beta
|
|
||||||
slug: /references/pricing/deleteMoneyAmounts
|
|
||||||
sidebar_label: deleteMoneyAmounts
|
|
||||||
---
|
|
||||||
|
|
||||||
# deleteMoneyAmounts - Pricing Module Reference
|
|
||||||
|
|
||||||
This documentation provides a reference to the deleteMoneyAmounts method. This belongs to the Pricing Module.
|
|
||||||
|
|
||||||
This method deletes money amounts by their IDs.
|
|
||||||
|
|
||||||
## Parameters
|
|
||||||
|
|
||||||
- `ids`: An array of strings, each being the ID of a money amount to delete.
|
|
||||||
- `sharedContext`: (optional) An object of type [Context](../../interfaces/Context.md) used to share resources, such as transaction manager, between the application and the module. It accepts the following properties:
|
|
||||||
- `enableNestedTransactions`: (optional) a boolean value indicating whether nested transactions are enabled.
|
|
||||||
- `isolationLevel`: (optional) A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.
|
|
||||||
- `manager`: (optional) An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.
|
|
||||||
- `transactionId`: (optional) a string indicating the ID of the current transaction.
|
|
||||||
- `transactionManager`: (optional) An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.
|
|
||||||
|
|
||||||
## Returns
|
|
||||||
|
|
||||||
A promise that resolves when the money amounts are successfully deleted.
|
|
||||||
|
|
||||||
## Example
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function deleteMoneyAmounts (moneyAmountIds: string[]) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
await pricingService.deleteMoneyAmounts(
|
|
||||||
moneyAmountIds
|
|
||||||
)
|
|
||||||
}
|
|
||||||
```
|
|
||||||
+40
@@ -0,0 +1,40 @@
|
|||||||
|
---
|
||||||
|
displayed_sidebar: pricingReference
|
||||||
|
badge:
|
||||||
|
variant: orange
|
||||||
|
text: Beta
|
||||||
|
slug: /references/pricing/deleteMoneyAmounts
|
||||||
|
sidebar_label: deleteMoneyAmounts
|
||||||
|
---
|
||||||
|
|
||||||
|
import ParameterTypes from "@site/src/components/ParameterTypes"
|
||||||
|
|
||||||
|
# deleteMoneyAmounts - Pricing Module Reference
|
||||||
|
|
||||||
|
This documentation provides a reference to the `deleteMoneyAmounts` method. This belongs to the Pricing Module.
|
||||||
|
|
||||||
|
This method deletes money amounts by their IDs.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function deleteMoneyAmounts (moneyAmountIds: string[]) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
await pricingService.deleteMoneyAmounts(
|
||||||
|
moneyAmountIds
|
||||||
|
)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"ids","type":"`string`[]","description":"The IDs of the money amounts to delete.","optional":false,"defaultValue":"","children":[]},{"name":"sharedContext","type":"[`Context`](../../interfaces/Context.mdx)","description":"A context used to share resources, such as transaction manager, between the application and the module.","optional":true,"defaultValue":"","children":[{"name":"enableNestedTransactions","type":"`boolean`","description":"a boolean value indicating whether nested transactions are enabled.","optional":true,"defaultValue":"","children":[]},{"name":"isolationLevel","type":"`string`","description":"A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.","optional":true,"defaultValue":"","children":[]},{"name":"manager","type":"`TManager`","description":"An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.","optional":true,"defaultValue":"","children":[]},{"name":"transactionId","type":"`string`","description":"a string indicating the ID of the current transaction.","optional":true,"defaultValue":"","children":[]},{"name":"transactionManager","type":"`TManager`","description":"An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.","optional":true,"defaultValue":"","children":[]}]}]} />
|
||||||
|
|
||||||
|
## Returns
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"Promise","type":"`Promise`<`void`\\>","optional":false,"defaultValue":"","description":"Resolves when the money amounts are successfully deleted.","children":[]}]} />
|
||||||
-44
@@ -1,44 +0,0 @@
|
|||||||
---
|
|
||||||
displayed_sidebar: pricingReference
|
|
||||||
badge:
|
|
||||||
variant: orange
|
|
||||||
text: Beta
|
|
||||||
slug: /references/pricing/deletePriceRules
|
|
||||||
sidebar_label: deletePriceRules
|
|
||||||
---
|
|
||||||
|
|
||||||
# deletePriceRules - Pricing Module Reference
|
|
||||||
|
|
||||||
This documentation provides a reference to the deletePriceRules method. This belongs to the Pricing Module.
|
|
||||||
|
|
||||||
This method is used to delete price rules based on the specified IDs.
|
|
||||||
|
|
||||||
## Parameters
|
|
||||||
|
|
||||||
- `priceRuleIds`: An array of strings, each being the ID of a price rule to delete.
|
|
||||||
- `sharedContext`: (optional) An object of type [Context](../../interfaces/Context.md) used to share resources, such as transaction manager, between the application and the module. It accepts the following properties:
|
|
||||||
- `enableNestedTransactions`: (optional) a boolean value indicating whether nested transactions are enabled.
|
|
||||||
- `isolationLevel`: (optional) A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.
|
|
||||||
- `manager`: (optional) An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.
|
|
||||||
- `transactionId`: (optional) a string indicating the ID of the current transaction.
|
|
||||||
- `transactionManager`: (optional) An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.
|
|
||||||
|
|
||||||
## Returns
|
|
||||||
|
|
||||||
A promise that resolves once the price rules are deleted.
|
|
||||||
|
|
||||||
## Example
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function deletePriceRules (
|
|
||||||
id: string,
|
|
||||||
) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
await pricingService.deletePriceRules([id])
|
|
||||||
}
|
|
||||||
```
|
|
||||||
+40
@@ -0,0 +1,40 @@
|
|||||||
|
---
|
||||||
|
displayed_sidebar: pricingReference
|
||||||
|
badge:
|
||||||
|
variant: orange
|
||||||
|
text: Beta
|
||||||
|
slug: /references/pricing/deletePriceRules
|
||||||
|
sidebar_label: deletePriceRules
|
||||||
|
---
|
||||||
|
|
||||||
|
import ParameterTypes from "@site/src/components/ParameterTypes"
|
||||||
|
|
||||||
|
# deletePriceRules - Pricing Module Reference
|
||||||
|
|
||||||
|
This documentation provides a reference to the `deletePriceRules` method. This belongs to the Pricing Module.
|
||||||
|
|
||||||
|
This method is used to delete price rules based on the specified IDs.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function deletePriceRules (
|
||||||
|
id: string,
|
||||||
|
) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
await pricingService.deletePriceRules([id])
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"priceRuleIds","type":"`string`[]","description":"The IDs of the price rules to delete.","optional":false,"defaultValue":"","children":[]},{"name":"sharedContext","type":"[`Context`](../../interfaces/Context.mdx)","description":"A context used to share resources, such as transaction manager, between the application and the module.","optional":true,"defaultValue":"","children":[{"name":"enableNestedTransactions","type":"`boolean`","description":"a boolean value indicating whether nested transactions are enabled.","optional":true,"defaultValue":"","children":[]},{"name":"isolationLevel","type":"`string`","description":"A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.","optional":true,"defaultValue":"","children":[]},{"name":"manager","type":"`TManager`","description":"An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.","optional":true,"defaultValue":"","children":[]},{"name":"transactionId","type":"`string`","description":"a string indicating the ID of the current transaction.","optional":true,"defaultValue":"","children":[]},{"name":"transactionManager","type":"`TManager`","description":"An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.","optional":true,"defaultValue":"","children":[]}]}]} />
|
||||||
|
|
||||||
|
## Returns
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"Promise","type":"`Promise`<`void`\\>","optional":false,"defaultValue":"","description":"Resolves once the price rules are deleted.","children":[]}]} />
|
||||||
-42
@@ -1,42 +0,0 @@
|
|||||||
---
|
|
||||||
displayed_sidebar: pricingReference
|
|
||||||
badge:
|
|
||||||
variant: orange
|
|
||||||
text: Beta
|
|
||||||
slug: /references/pricing/deletePriceSetMoneyAmountRules
|
|
||||||
sidebar_label: deletePriceSetMoneyAmountRules
|
|
||||||
---
|
|
||||||
|
|
||||||
# deletePriceSetMoneyAmountRules - Pricing Module Reference
|
|
||||||
|
|
||||||
This documentation provides a reference to the deletePriceSetMoneyAmountRules method. This belongs to the Pricing Module.
|
|
||||||
|
|
||||||
This method is used to delete price set money amount rules based on the specified IDs.
|
|
||||||
|
|
||||||
## Parameters
|
|
||||||
|
|
||||||
- `ids`: An array of strings, each representing the ID of a price set money amount rule to delete.
|
|
||||||
- `sharedContext`: (optional) An object of type [Context](../../interfaces/Context.md) used to share resources, such as transaction manager, between the application and the module. It accepts the following properties:
|
|
||||||
- `enableNestedTransactions`: (optional) a boolean value indicating whether nested transactions are enabled.
|
|
||||||
- `isolationLevel`: (optional) A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.
|
|
||||||
- `manager`: (optional) An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.
|
|
||||||
- `transactionId`: (optional) a string indicating the ID of the current transaction.
|
|
||||||
- `transactionManager`: (optional) An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.
|
|
||||||
|
|
||||||
## Returns
|
|
||||||
|
|
||||||
A promise that resolves once the price set money amount rules are deleted.
|
|
||||||
|
|
||||||
## Example
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function deletePriceSetMoneyAmountRule (id: string) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
await pricingService.deletePriceSetMoneyAmountRules([id])
|
|
||||||
}
|
|
||||||
```
|
|
||||||
+38
@@ -0,0 +1,38 @@
|
|||||||
|
---
|
||||||
|
displayed_sidebar: pricingReference
|
||||||
|
badge:
|
||||||
|
variant: orange
|
||||||
|
text: Beta
|
||||||
|
slug: /references/pricing/deletePriceSetMoneyAmountRules
|
||||||
|
sidebar_label: deletePriceSetMoneyAmountRules
|
||||||
|
---
|
||||||
|
|
||||||
|
import ParameterTypes from "@site/src/components/ParameterTypes"
|
||||||
|
|
||||||
|
# deletePriceSetMoneyAmountRules - Pricing Module Reference
|
||||||
|
|
||||||
|
This documentation provides a reference to the `deletePriceSetMoneyAmountRules` method. This belongs to the Pricing Module.
|
||||||
|
|
||||||
|
This method is used to delete price set money amount rules based on the specified IDs.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function deletePriceSetMoneyAmountRule (id: string) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
await pricingService.deletePriceSetMoneyAmountRules([id])
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"ids","type":"`string`[]","description":"The IDs of the price set money amount rules to delete.","optional":false,"defaultValue":"","children":[]},{"name":"sharedContext","type":"[`Context`](../../interfaces/Context.mdx)","description":"A context used to share resources, such as transaction manager, between the application and the module.","optional":true,"defaultValue":"","children":[{"name":"enableNestedTransactions","type":"`boolean`","description":"a boolean value indicating whether nested transactions are enabled.","optional":true,"defaultValue":"","children":[]},{"name":"isolationLevel","type":"`string`","description":"A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.","optional":true,"defaultValue":"","children":[]},{"name":"manager","type":"`TManager`","description":"An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.","optional":true,"defaultValue":"","children":[]},{"name":"transactionId","type":"`string`","description":"a string indicating the ID of the current transaction.","optional":true,"defaultValue":"","children":[]},{"name":"transactionManager","type":"`TManager`","description":"An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.","optional":true,"defaultValue":"","children":[]}]}]} />
|
||||||
|
|
||||||
|
## Returns
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"Promise","type":"`Promise`<`void`\\>","optional":false,"defaultValue":"","description":"Resolves once the price set money amount rules are deleted.","children":[]}]} />
|
||||||
-42
@@ -1,42 +0,0 @@
|
|||||||
---
|
|
||||||
displayed_sidebar: pricingReference
|
|
||||||
badge:
|
|
||||||
variant: orange
|
|
||||||
text: Beta
|
|
||||||
slug: /references/pricing/deleteRuleTypes
|
|
||||||
sidebar_label: deleteRuleTypes
|
|
||||||
---
|
|
||||||
|
|
||||||
# deleteRuleTypes - Pricing Module Reference
|
|
||||||
|
|
||||||
This documentation provides a reference to the deleteRuleTypes method. This belongs to the Pricing Module.
|
|
||||||
|
|
||||||
This method is used to delete rule types based on the provided IDs.
|
|
||||||
|
|
||||||
## Parameters
|
|
||||||
|
|
||||||
- `ruleTypeIds`: An array of strings, each being the ID of a rule type to delete.
|
|
||||||
- `sharedContext`: (optional) An object of type [Context](../../interfaces/Context.md) used to share resources, such as transaction manager, between the application and the module. It accepts the following properties:
|
|
||||||
- `enableNestedTransactions`: (optional) a boolean value indicating whether nested transactions are enabled.
|
|
||||||
- `isolationLevel`: (optional) A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.
|
|
||||||
- `manager`: (optional) An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.
|
|
||||||
- `transactionId`: (optional) a string indicating the ID of the current transaction.
|
|
||||||
- `transactionManager`: (optional) An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.
|
|
||||||
|
|
||||||
## Returns
|
|
||||||
|
|
||||||
A promise that resolves once the rule types are deleted.
|
|
||||||
|
|
||||||
## Example
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function deleteRuleTypes (ruleTypeId: string) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
await pricingService.deleteRuleTypes([ruleTypeId])
|
|
||||||
}
|
|
||||||
```
|
|
||||||
+38
@@ -0,0 +1,38 @@
|
|||||||
|
---
|
||||||
|
displayed_sidebar: pricingReference
|
||||||
|
badge:
|
||||||
|
variant: orange
|
||||||
|
text: Beta
|
||||||
|
slug: /references/pricing/deleteRuleTypes
|
||||||
|
sidebar_label: deleteRuleTypes
|
||||||
|
---
|
||||||
|
|
||||||
|
import ParameterTypes from "@site/src/components/ParameterTypes"
|
||||||
|
|
||||||
|
# deleteRuleTypes - Pricing Module Reference
|
||||||
|
|
||||||
|
This documentation provides a reference to the `deleteRuleTypes` method. This belongs to the Pricing Module.
|
||||||
|
|
||||||
|
This method is used to delete rule types based on the provided IDs.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function deleteRuleTypes (ruleTypeId: string) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
await pricingService.deleteRuleTypes([ruleTypeId])
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"ruleTypeIds","type":"`string`[]","description":"The IDs of the rule types to delete.","optional":false,"defaultValue":"","children":[]},{"name":"sharedContext","type":"[`Context`](../../interfaces/Context.mdx)","description":"A context used to share resources, such as transaction manager, between the application and the module.","optional":true,"defaultValue":"","children":[{"name":"enableNestedTransactions","type":"`boolean`","description":"a boolean value indicating whether nested transactions are enabled.","optional":true,"defaultValue":"","children":[]},{"name":"isolationLevel","type":"`string`","description":"A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.","optional":true,"defaultValue":"","children":[]},{"name":"manager","type":"`TManager`","description":"An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.","optional":true,"defaultValue":"","children":[]},{"name":"transactionId","type":"`string`","description":"a string indicating the ID of the current transaction.","optional":true,"defaultValue":"","children":[]},{"name":"transactionManager","type":"`TManager`","description":"An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.","optional":true,"defaultValue":"","children":[]}]}]} />
|
||||||
|
|
||||||
|
## Returns
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"Promise","type":"`Promise`<`void`\\>","optional":false,"defaultValue":"","description":"Resolves once the rule types are deleted.","children":[]}]} />
|
||||||
-172
@@ -1,172 +0,0 @@
|
|||||||
---
|
|
||||||
displayed_sidebar: pricingReference
|
|
||||||
badge:
|
|
||||||
variant: orange
|
|
||||||
text: Beta
|
|
||||||
slug: /references/pricing/list
|
|
||||||
sidebar_label: list
|
|
||||||
---
|
|
||||||
|
|
||||||
# list - Pricing Module Reference
|
|
||||||
|
|
||||||
This documentation provides a reference to the list method. This belongs to the Pricing Module.
|
|
||||||
|
|
||||||
This method is used to retrieve a paginated list of price sets based on optional filters and configuration.
|
|
||||||
|
|
||||||
## Parameters
|
|
||||||
|
|
||||||
- `filters`: (optional) An object of type [FilterablePriceSetProps](../../interfaces/FilterablePriceSetProps.md) that is used to filter the retrieved price lists. It accepts the following properties:
|
|
||||||
- `$and`: (optional) An array of filters to apply on the entity, where each item in the array is joined with an "and" condition.
|
|
||||||
- `$or`: (optional) An array of filters to apply on the entity, where each item in the array is joined with an "or" condition.
|
|
||||||
- `id`: (optional) An array of strings, each being an ID to filter price sets.
|
|
||||||
- `money_amounts`: (optional) An object of type [FilterableMoneyAmountProps](../../interfaces/FilterableMoneyAmountProps.md) that is used to filter the price sets by their associated money amounts. It accepts the following properties:
|
|
||||||
- `$and`: (optional) An array of filters to apply on the entity, where each item in the array is joined with an "and" condition.
|
|
||||||
- `$or`: (optional) An array of filters to apply on the entity, where each item in the array is joined with an "or" condition.
|
|
||||||
- `currency_code`: (optional) A string or an array of strings, each being a currency code to filter money amounts.
|
|
||||||
- `id`: (optional) An array of strings, each being an ID to filter money amounts.
|
|
||||||
- `config`: (optional) An object of type [FindConfig](../../interfaces/FindConfig.md) used to configure how the price sets are retrieved. Its properties, such as `select` or `relations`, accept the attributes or relations associated with a price set. It accepts the following properties:
|
|
||||||
- `order`: (optional) An object used to specify how to sort the returned records. Its keys are the names of attributes of the entity, and a key's value can either be `ASC` to sort retrieved records in an ascending order, or `DESC` to sort retrieved records in a descending order.
|
|
||||||
- `relations`: (optional) An array of strings, each being relation names of the entity to retrieve in the result.
|
|
||||||
- `select`: (optional) An array of strings, each being attribute names of the entity to retrieve in the result.
|
|
||||||
- `skip`: (optional) A number indicating the number of records to skip before retrieving the results.
|
|
||||||
- `take`: (optional) A number indicating the number of records to return in the result.
|
|
||||||
- `withDeleted`: (optional) A boolean indicating whether deleted records should also be retrieved as part of the result. This only works if the entity extends the `SoftDeletableEntity` class.
|
|
||||||
- `sharedContext`: (optional) An object of type [Context](../../interfaces/Context.md) used to share resources, such as transaction manager, between the application and the module. It accepts the following properties:
|
|
||||||
- `enableNestedTransactions`: (optional) a boolean value indicating whether nested transactions are enabled.
|
|
||||||
- `isolationLevel`: (optional) A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.
|
|
||||||
- `manager`: (optional) An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.
|
|
||||||
- `transactionId`: (optional) a string indicating the ID of the current transaction.
|
|
||||||
- `transactionManager`: (optional) An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.
|
|
||||||
|
|
||||||
## Returns
|
|
||||||
|
|
||||||
A promise that resolves to an array of objects of type [PriceSetDTO](../../interfaces/PriceSetDTO.md).
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary>
|
|
||||||
PriceSetDTO
|
|
||||||
</summary>
|
|
||||||
|
|
||||||
- `id`: A string indicating the ID of the price set.
|
|
||||||
- `money_amounts`: (optional) An array of objects of type [MoneyAmountDTO](../../interfaces/MoneyAmountDTO.md), which holds the prices that belong to this price set. Its items accept the following properties:
|
|
||||||
- `amount`: (optional) A number indicating the amount of this price.
|
|
||||||
- `currency`: (optional) An object of type [CurrencyDTO](../../interfaces/CurrencyDTO.md) that holds the details of the price's currency. Since this is a relation, it will only be retrieved if it's passed to the `relations` array of the find-configuration options. It accepts the following properties:
|
|
||||||
- `code`: a string indicating the code of the currency.
|
|
||||||
- `name`: (optional) a string indicating the name of the currency.
|
|
||||||
- `symbol`: (optional) a string indicating the symbol of the currency.
|
|
||||||
- `symbol_native`: (optional) a string indicating the symbol of the currecy in its native form. This is typically the symbol used when displaying a price.
|
|
||||||
- `currency_code`: (optional) A string that indicates the currency code of this price.
|
|
||||||
- `id`: A string that indicates the ID of the money amount. A money amount represents a price.
|
|
||||||
- `max_quantity`: (optional) A number that indicates the maximum quantity required to be purchased for this price to be applied.
|
|
||||||
- `min_quantity`: (optional) A number that indicates the minimum quantity required to be purchased for this price to be applied.
|
|
||||||
- `rule_types`: (optional) An array of objects of type [RuleTypeDTO](../../interfaces/RuleTypeDTO.md), which holds the rule types applied on this price set. Its items accept the following properties:
|
|
||||||
- `default_priority`: A number indicating the priority of the rule type. This is useful when calculating the price of a price set, and multiple rules satisfy the provided context. The higher the value, the higher the priority of the rule type.
|
|
||||||
- `id`: A string indicating the ID of the rule type.
|
|
||||||
- `name`: A string indicating the display name of the rule type.
|
|
||||||
- `rule_attribute`: A string indicating a unique name used to later identify the rule_attribute. For example, it can be used in the `context` parameter of the `calculatePrices` method to specify a rule for calculating the price.
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
## Example
|
|
||||||
|
|
||||||
To retrieve a list of price sets using their IDs:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function retrievePriceSets (priceSetIds: string[]) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const priceSets = await pricingService.list(
|
|
||||||
{
|
|
||||||
id: priceSetIds
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
// do something with the price sets or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
To specify relations that should be retrieved within the price sets:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function retrievePriceSets (priceSetIds: string[]) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const priceSets = await pricingService.list(
|
|
||||||
{
|
|
||||||
id: priceSetIds
|
|
||||||
},
|
|
||||||
{
|
|
||||||
relations: ["money_amounts"]
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
// do something with the price sets or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
By default, only the first `15` records are retrieved. You can control pagination by specifying the `skip` and `take` properties of the `config` parameter:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function retrievePriceSets (priceSetIds: string[], skip: number, take: number) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const priceSets = await pricingService.list(
|
|
||||||
{
|
|
||||||
id: priceSetIds
|
|
||||||
},
|
|
||||||
{
|
|
||||||
relations: ["money_amounts"],
|
|
||||||
skip,
|
|
||||||
take
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
// do something with the price sets or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
You can also use the `$and` or `$or` properties of the `filter` parameter to use and/or conditions in your filters. For example:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function retrievePriceSets (priceSetIds: string[], moneyAmountIds: string[], skip: number, take: number) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const priceSets = await pricingService.list(
|
|
||||||
{
|
|
||||||
$and: [
|
|
||||||
{
|
|
||||||
id: priceSetIds
|
|
||||||
},
|
|
||||||
{
|
|
||||||
money_amounts: {
|
|
||||||
id: moneyAmountIds
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
relations: ["money_amounts"],
|
|
||||||
skip,
|
|
||||||
take
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
// do something with the price sets or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
+128
@@ -0,0 +1,128 @@
|
|||||||
|
---
|
||||||
|
displayed_sidebar: pricingReference
|
||||||
|
badge:
|
||||||
|
variant: orange
|
||||||
|
text: Beta
|
||||||
|
slug: /references/pricing/list
|
||||||
|
sidebar_label: list
|
||||||
|
---
|
||||||
|
|
||||||
|
import ParameterTypes from "@site/src/components/ParameterTypes"
|
||||||
|
|
||||||
|
# list - Pricing Module Reference
|
||||||
|
|
||||||
|
This documentation provides a reference to the `list` method. This belongs to the Pricing Module.
|
||||||
|
|
||||||
|
This method is used to retrieve a paginated list of price sets based on optional filters and configuration.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
To retrieve a list of price sets using their IDs:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function retrievePriceSets (priceSetIds: string[]) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const priceSets = await pricingService.list(
|
||||||
|
{
|
||||||
|
id: priceSetIds
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
// do something with the price sets or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
To specify relations that should be retrieved within the price sets:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function retrievePriceSets (priceSetIds: string[]) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const priceSets = await pricingService.list(
|
||||||
|
{
|
||||||
|
id: priceSetIds
|
||||||
|
},
|
||||||
|
{
|
||||||
|
relations: ["money_amounts"]
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// do something with the price sets or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
By default, only the first `15` records are retrieved. You can control pagination by specifying the `skip` and `take` properties of the `config` parameter:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function retrievePriceSets (priceSetIds: string[], skip: number, take: number) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const priceSets = await pricingService.list(
|
||||||
|
{
|
||||||
|
id: priceSetIds
|
||||||
|
},
|
||||||
|
{
|
||||||
|
relations: ["money_amounts"],
|
||||||
|
skip,
|
||||||
|
take
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// do something with the price sets or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
You can also use the `$and` or `$or` properties of the `filter` parameter to use and/or conditions in your filters. For example:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function retrievePriceSets (priceSetIds: string[], moneyAmountIds: string[], skip: number, take: number) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const priceSets = await pricingService.list(
|
||||||
|
{
|
||||||
|
$and: [
|
||||||
|
{
|
||||||
|
id: priceSetIds
|
||||||
|
},
|
||||||
|
{
|
||||||
|
money_amounts: {
|
||||||
|
id: moneyAmountIds
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
relations: ["money_amounts"],
|
||||||
|
skip,
|
||||||
|
take
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// do something with the price sets or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"filters","type":"[`FilterablePriceSetProps`](../../interfaces/FilterablePriceSetProps.mdx)","description":"The filters to apply on the retrieved price lists.","optional":true,"defaultValue":"","children":[{"name":"$and","type":"([`FilterablePriceSetProps`](../../interfaces/FilterablePriceSetProps.mdx) \\| [`BaseFilterable`](../../interfaces/BaseFilterable.mdx)<[`FilterablePriceSetProps`](../../interfaces/FilterablePriceSetProps.mdx)\\>)[]","description":"An array of filters to apply on the entity, where each item in the array is joined with an \"and\" condition.","optional":true,"defaultValue":"","children":[]},{"name":"$or","type":"([`FilterablePriceSetProps`](../../interfaces/FilterablePriceSetProps.mdx) \\| [`BaseFilterable`](../../interfaces/BaseFilterable.mdx)<[`FilterablePriceSetProps`](../../interfaces/FilterablePriceSetProps.mdx)\\>)[]","description":"An array of filters to apply on the entity, where each item in the array is joined with an \"or\" condition.","optional":true,"defaultValue":"","children":[]},{"name":"id","type":"`string`[]","description":"IDs to filter price sets by.","optional":true,"defaultValue":"","children":[]},{"name":"money_amounts","type":"[`FilterableMoneyAmountProps`](../../interfaces/FilterableMoneyAmountProps.mdx)","description":"Filters to apply on a price set's associated money amounts.","optional":true,"defaultValue":"","children":[{"name":"$and","type":"([`FilterableMoneyAmountProps`](../../interfaces/FilterableMoneyAmountProps.mdx) \\| [`BaseFilterable`](../../interfaces/BaseFilterable.mdx)<[`FilterableMoneyAmountProps`](../../interfaces/FilterableMoneyAmountProps.mdx)\\>)[]","description":"An array of filters to apply on the entity, where each item in the array is joined with an \"and\" condition.","optional":true,"defaultValue":"","children":[]},{"name":"$or","type":"([`FilterableMoneyAmountProps`](../../interfaces/FilterableMoneyAmountProps.mdx) \\| [`BaseFilterable`](../../interfaces/BaseFilterable.mdx)<[`FilterableMoneyAmountProps`](../../interfaces/FilterableMoneyAmountProps.mdx)\\>)[]","description":"An array of filters to apply on the entity, where each item in the array is joined with an \"or\" condition.","optional":true,"defaultValue":"","children":[]},{"name":"currency_code","type":"`string` \\| `string`[]","description":"Currency codes to filter money amounts by.","optional":true,"defaultValue":"","children":[]},{"name":"id","type":"`string`[]","description":"IDs to filter money amounts by.","optional":true,"defaultValue":"","children":[]}]}]},{"name":"config","type":"[`FindConfig`](../../interfaces/FindConfig.mdx)<[`PriceSetDTO`](../../interfaces/PriceSetDTO.mdx)\\>","description":"The configurations determining how the price sets are retrieved. Its properties, such as `select` or `relations`, accept the attributes or relations associated with a price set.","optional":true,"defaultValue":"","children":[{"name":"order","type":"`object`","description":"An object used to specify how to sort the returned records. Its keys are the names of attributes of the entity, and a key's value can either be `ASC` to sort retrieved records in an ascending order, or `DESC` to sort retrieved records in a descending order.","optional":true,"defaultValue":"","children":[]},{"name":"relations","type":"`string`[]","description":"An array of strings, each being relation names of the entity to retrieve in the result.","optional":true,"defaultValue":"","children":[]},{"name":"select","type":"(`string` \\| keyof `Entity`)[]","description":"An array of strings, each being attribute names of the entity to retrieve in the result.","optional":true,"defaultValue":"","children":[]},{"name":"skip","type":"`number`","description":"A number indicating the number of records to skip before retrieving the results.","optional":true,"defaultValue":"","children":[]},{"name":"take","type":"`number`","description":"A number indicating the number of records to return in the result.","optional":true,"defaultValue":"","children":[]},{"name":"withDeleted","type":"`boolean`","description":"A boolean indicating whether deleted records should also be retrieved as part of the result. This only works if the entity extends the `SoftDeletableEntity` class.","optional":true,"defaultValue":"","children":[]}]},{"name":"sharedContext","type":"[`Context`](../../interfaces/Context.mdx)","description":"A context used to share resources, such as transaction manager, between the application and the module.","optional":true,"defaultValue":"","children":[{"name":"enableNestedTransactions","type":"`boolean`","description":"a boolean value indicating whether nested transactions are enabled.","optional":true,"defaultValue":"","children":[]},{"name":"isolationLevel","type":"`string`","description":"A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.","optional":true,"defaultValue":"","Line truncated
|
||||||
|
|
||||||
|
## Returns
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"Promise","type":"`Promise`<[`PriceSetDTO`](../../interfaces/PriceSetDTO.mdx)[]\\>","optional":false,"defaultValue":"","description":"The list of price sets.","children":[{"name":"PriceSetDTO[]","type":"[`PriceSetDTO`](../../interfaces/PriceSetDTO.mdx)[]","optional":false,"defaultValue":"","description":"","children":[{"name":"PriceSetDTO","type":"`object`","description":"A price set's data.","optional":false,"defaultValue":"","children":[]}]}]}]} />
|
||||||
-173
@@ -1,173 +0,0 @@
|
|||||||
---
|
|
||||||
displayed_sidebar: pricingReference
|
|
||||||
badge:
|
|
||||||
variant: orange
|
|
||||||
text: Beta
|
|
||||||
slug: /references/pricing/listAndCount
|
|
||||||
sidebar_label: listAndCount
|
|
||||||
---
|
|
||||||
|
|
||||||
# listAndCount - Pricing Module Reference
|
|
||||||
|
|
||||||
This documentation provides a reference to the listAndCount method. This belongs to the Pricing Module.
|
|
||||||
|
|
||||||
This method is used to retrieve a paginated list of price sets along with the total count of available price sets satisfying the provided filters.
|
|
||||||
|
|
||||||
## Parameters
|
|
||||||
|
|
||||||
- `filters`: (optional) An object of type [FilterablePriceSetProps](../../interfaces/FilterablePriceSetProps.md) that is used to filter the retrieved price lists. It accepts the following properties:
|
|
||||||
- `$and`: (optional) An array of filters to apply on the entity, where each item in the array is joined with an "and" condition.
|
|
||||||
- `$or`: (optional) An array of filters to apply on the entity, where each item in the array is joined with an "or" condition.
|
|
||||||
- `id`: (optional) An array of strings, each being an ID to filter price sets.
|
|
||||||
- `money_amounts`: (optional) An object of type [FilterableMoneyAmountProps](../../interfaces/FilterableMoneyAmountProps.md) that is used to filter the price sets by their associated money amounts. It accepts the following properties:
|
|
||||||
- `$and`: (optional) An array of filters to apply on the entity, where each item in the array is joined with an "and" condition.
|
|
||||||
- `$or`: (optional) An array of filters to apply on the entity, where each item in the array is joined with an "or" condition.
|
|
||||||
- `currency_code`: (optional) A string or an array of strings, each being a currency code to filter money amounts.
|
|
||||||
- `id`: (optional) An array of strings, each being an ID to filter money amounts.
|
|
||||||
- `config`: (optional) An object of type [FindConfig](../../interfaces/FindConfig.md) used to configure how the price sets are retrieved. Its properties, such as `select` or `relations`, accept the attributes or relations associated with a price set. It accepts the following properties:
|
|
||||||
- `order`: (optional) An object used to specify how to sort the returned records. Its keys are the names of attributes of the entity, and a key's value can either be `ASC` to sort retrieved records in an ascending order, or `DESC` to sort retrieved records in a descending order.
|
|
||||||
- `relations`: (optional) An array of strings, each being relation names of the entity to retrieve in the result.
|
|
||||||
- `select`: (optional) An array of strings, each being attribute names of the entity to retrieve in the result.
|
|
||||||
- `skip`: (optional) A number indicating the number of records to skip before retrieving the results.
|
|
||||||
- `take`: (optional) A number indicating the number of records to return in the result.
|
|
||||||
- `withDeleted`: (optional) A boolean indicating whether deleted records should also be retrieved as part of the result. This only works if the entity extends the `SoftDeletableEntity` class.
|
|
||||||
- `sharedContext`: (optional) An object of type [Context](../../interfaces/Context.md) used to share resources, such as transaction manager, between the application and the module. It accepts the following properties:
|
|
||||||
- `enableNestedTransactions`: (optional) a boolean value indicating whether nested transactions are enabled.
|
|
||||||
- `isolationLevel`: (optional) A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.
|
|
||||||
- `manager`: (optional) An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.
|
|
||||||
- `transactionId`: (optional) a string indicating the ID of the current transaction.
|
|
||||||
- `transactionManager`: (optional) An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.
|
|
||||||
|
|
||||||
## Returns
|
|
||||||
|
|
||||||
A promise that resolves to an array having two items, the first item is an array of objects of type [PriceSetDTO](../../interfaces/PriceSetDTO.md),
|
|
||||||
and the second item is a number indicating the total count.
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary>
|
|
||||||
PriceSetDTO
|
|
||||||
</summary>
|
|
||||||
|
|
||||||
- `id`: A string indicating the ID of the price set.
|
|
||||||
- `money_amounts`: (optional) An array of objects of type [MoneyAmountDTO](../../interfaces/MoneyAmountDTO.md), which holds the prices that belong to this price set. Its items accept the following properties:
|
|
||||||
- `amount`: (optional) A number indicating the amount of this price.
|
|
||||||
- `currency`: (optional) An object of type [CurrencyDTO](../../interfaces/CurrencyDTO.md) that holds the details of the price's currency. Since this is a relation, it will only be retrieved if it's passed to the `relations` array of the find-configuration options. It accepts the following properties:
|
|
||||||
- `code`: a string indicating the code of the currency.
|
|
||||||
- `name`: (optional) a string indicating the name of the currency.
|
|
||||||
- `symbol`: (optional) a string indicating the symbol of the currency.
|
|
||||||
- `symbol_native`: (optional) a string indicating the symbol of the currecy in its native form. This is typically the symbol used when displaying a price.
|
|
||||||
- `currency_code`: (optional) A string that indicates the currency code of this price.
|
|
||||||
- `id`: A string that indicates the ID of the money amount. A money amount represents a price.
|
|
||||||
- `max_quantity`: (optional) A number that indicates the maximum quantity required to be purchased for this price to be applied.
|
|
||||||
- `min_quantity`: (optional) A number that indicates the minimum quantity required to be purchased for this price to be applied.
|
|
||||||
- `rule_types`: (optional) An array of objects of type [RuleTypeDTO](../../interfaces/RuleTypeDTO.md), which holds the rule types applied on this price set. Its items accept the following properties:
|
|
||||||
- `default_priority`: A number indicating the priority of the rule type. This is useful when calculating the price of a price set, and multiple rules satisfy the provided context. The higher the value, the higher the priority of the rule type.
|
|
||||||
- `id`: A string indicating the ID of the rule type.
|
|
||||||
- `name`: A string indicating the display name of the rule type.
|
|
||||||
- `rule_attribute`: A string indicating a unique name used to later identify the rule_attribute. For example, it can be used in the `context` parameter of the `calculatePrices` method to specify a rule for calculating the price.
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
## Example
|
|
||||||
|
|
||||||
To retrieve a list of prices sets using their IDs:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function retrievePriceSets (priceSetIds: string[]) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const [priceSets, count] = await pricingService.listAndCount(
|
|
||||||
{
|
|
||||||
id: priceSetIds
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
// do something with the price sets or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
To specify relations that should be retrieved within the price sets:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function retrievePriceSets (priceSetIds: string[]) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const [priceSets, count] = await pricingService.listAndCount(
|
|
||||||
{
|
|
||||||
id: priceSetIds
|
|
||||||
},
|
|
||||||
{
|
|
||||||
relations: ["money_amounts"]
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
// do something with the price sets or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
By default, only the first `15` records are retrieved. You can control pagination by specifying the `skip` and `take` properties of the `config` parameter:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function retrievePriceSets (priceSetIds: string[], skip: number, take: number) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const [priceSets, count] = await pricingService.listAndCount(
|
|
||||||
{
|
|
||||||
id: priceSetIds
|
|
||||||
},
|
|
||||||
{
|
|
||||||
relations: ["money_amounts"],
|
|
||||||
skip,
|
|
||||||
take
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
// do something with the price sets or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
You can also use the `$and` or `$or` properties of the `filter` parameter to use and/or conditions in your filters. For example:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function retrievePriceSets (priceSetIds: string[], moneyAmountIds: string[], skip: number, take: number) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const [priceSets, count] = await pricingService.listAndCount(
|
|
||||||
{
|
|
||||||
$and: [
|
|
||||||
{
|
|
||||||
id: priceSetIds
|
|
||||||
},
|
|
||||||
{
|
|
||||||
money_amounts: {
|
|
||||||
id: moneyAmountIds
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
relations: ["money_amounts"],
|
|
||||||
skip,
|
|
||||||
take
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
// do something with the price sets or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
+128
@@ -0,0 +1,128 @@
|
|||||||
|
---
|
||||||
|
displayed_sidebar: pricingReference
|
||||||
|
badge:
|
||||||
|
variant: orange
|
||||||
|
text: Beta
|
||||||
|
slug: /references/pricing/listAndCount
|
||||||
|
sidebar_label: listAndCount
|
||||||
|
---
|
||||||
|
|
||||||
|
import ParameterTypes from "@site/src/components/ParameterTypes"
|
||||||
|
|
||||||
|
# listAndCount - Pricing Module Reference
|
||||||
|
|
||||||
|
This documentation provides a reference to the `listAndCount` method. This belongs to the Pricing Module.
|
||||||
|
|
||||||
|
This method is used to retrieve a paginated list of price sets along with the total count of available price sets satisfying the provided filters.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
To retrieve a list of prices sets using their IDs:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function retrievePriceSets (priceSetIds: string[]) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const [priceSets, count] = await pricingService.listAndCount(
|
||||||
|
{
|
||||||
|
id: priceSetIds
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
// do something with the price sets or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
To specify relations that should be retrieved within the price sets:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function retrievePriceSets (priceSetIds: string[]) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const [priceSets, count] = await pricingService.listAndCount(
|
||||||
|
{
|
||||||
|
id: priceSetIds
|
||||||
|
},
|
||||||
|
{
|
||||||
|
relations: ["money_amounts"]
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// do something with the price sets or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
By default, only the first `15` records are retrieved. You can control pagination by specifying the `skip` and `take` properties of the `config` parameter:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function retrievePriceSets (priceSetIds: string[], skip: number, take: number) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const [priceSets, count] = await pricingService.listAndCount(
|
||||||
|
{
|
||||||
|
id: priceSetIds
|
||||||
|
},
|
||||||
|
{
|
||||||
|
relations: ["money_amounts"],
|
||||||
|
skip,
|
||||||
|
take
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// do something with the price sets or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
You can also use the `$and` or `$or` properties of the `filter` parameter to use and/or conditions in your filters. For example:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function retrievePriceSets (priceSetIds: string[], moneyAmountIds: string[], skip: number, take: number) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const [priceSets, count] = await pricingService.listAndCount(
|
||||||
|
{
|
||||||
|
$and: [
|
||||||
|
{
|
||||||
|
id: priceSetIds
|
||||||
|
},
|
||||||
|
{
|
||||||
|
money_amounts: {
|
||||||
|
id: moneyAmountIds
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
relations: ["money_amounts"],
|
||||||
|
skip,
|
||||||
|
take
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// do something with the price sets or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"filters","type":"[`FilterablePriceSetProps`](../../interfaces/FilterablePriceSetProps.mdx)","description":"The filters to apply on the retrieved price lists.","optional":true,"defaultValue":"","children":[{"name":"$and","type":"([`FilterablePriceSetProps`](../../interfaces/FilterablePriceSetProps.mdx) \\| [`BaseFilterable`](../../interfaces/BaseFilterable.mdx)<[`FilterablePriceSetProps`](../../interfaces/FilterablePriceSetProps.mdx)\\>)[]","description":"An array of filters to apply on the entity, where each item in the array is joined with an \"and\" condition.","optional":true,"defaultValue":"","children":[]},{"name":"$or","type":"([`FilterablePriceSetProps`](../../interfaces/FilterablePriceSetProps.mdx) \\| [`BaseFilterable`](../../interfaces/BaseFilterable.mdx)<[`FilterablePriceSetProps`](../../interfaces/FilterablePriceSetProps.mdx)\\>)[]","description":"An array of filters to apply on the entity, where each item in the array is joined with an \"or\" condition.","optional":true,"defaultValue":"","children":[]},{"name":"id","type":"`string`[]","description":"IDs to filter price sets by.","optional":true,"defaultValue":"","children":[]},{"name":"money_amounts","type":"[`FilterableMoneyAmountProps`](../../interfaces/FilterableMoneyAmountProps.mdx)","description":"Filters to apply on a price set's associated money amounts.","optional":true,"defaultValue":"","children":[{"name":"$and","type":"([`FilterableMoneyAmountProps`](../../interfaces/FilterableMoneyAmountProps.mdx) \\| [`BaseFilterable`](../../interfaces/BaseFilterable.mdx)<[`FilterableMoneyAmountProps`](../../interfaces/FilterableMoneyAmountProps.mdx)\\>)[]","description":"An array of filters to apply on the entity, where each item in the array is joined with an \"and\" condition.","optional":true,"defaultValue":"","children":[]},{"name":"$or","type":"([`FilterableMoneyAmountProps`](../../interfaces/FilterableMoneyAmountProps.mdx) \\| [`BaseFilterable`](../../interfaces/BaseFilterable.mdx)<[`FilterableMoneyAmountProps`](../../interfaces/FilterableMoneyAmountProps.mdx)\\>)[]","description":"An array of filters to apply on the entity, where each item in the array is joined with an \"or\" condition.","optional":true,"defaultValue":"","children":[]},{"name":"currency_code","type":"`string` \\| `string`[]","description":"Currency codes to filter money amounts by.","optional":true,"defaultValue":"","children":[]},{"name":"id","type":"`string`[]","description":"IDs to filter money amounts by.","optional":true,"defaultValue":"","children":[]}]}]},{"name":"config","type":"[`FindConfig`](../../interfaces/FindConfig.mdx)<[`PriceSetDTO`](../../interfaces/PriceSetDTO.mdx)\\>","description":"The configurations determining how the price sets are retrieved. Its properties, such as `select` or `relations`, accept the attributes or relations associated with a price set.","optional":true,"defaultValue":"","children":[{"name":"order","type":"`object`","description":"An object used to specify how to sort the returned records. Its keys are the names of attributes of the entity, and a key's value can either be `ASC` to sort retrieved records in an ascending order, or `DESC` to sort retrieved records in a descending order.","optional":true,"defaultValue":"","children":[]},{"name":"relations","type":"`string`[]","description":"An array of strings, each being relation names of the entity to retrieve in the result.","optional":true,"defaultValue":"","children":[]},{"name":"select","type":"(`string` \\| keyof `Entity`)[]","description":"An array of strings, each being attribute names of the entity to retrieve in the result.","optional":true,"defaultValue":"","children":[]},{"name":"skip","type":"`number`","description":"A number indicating the number of records to skip before retrieving the results.","optional":true,"defaultValue":"","children":[]},{"name":"take","type":"`number`","description":"A number indicating the number of records to return in the result.","optional":true,"defaultValue":"","children":[]},{"name":"withDeleted","type":"`boolean`","description":"A boolean indicating whether deleted records should also be retrieved as part of the result. This only works if the entity extends the `SoftDeletableEntity` class.","optional":true,"defaultValue":"","children":[]}]},{"name":"sharedContext","type":"[`Context`](../../interfaces/Context.mdx)","description":"A context used to share resources, such as transaction manager, between the application and the module.","optional":true,"defaultValue":"","children":[{"name":"enableNestedTransactions","type":"`boolean`","description":"a boolean value indicating whether nested transactions are enabled.","optional":true,"defaultValue":"","children":[]},{"name":"isolationLevel","type":"`string`","description":"A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.","optional":true,"defaultValue":"","Line truncated
|
||||||
|
|
||||||
|
## Returns
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"Promise","type":"`Promise`<[[`PriceSetDTO`](../../interfaces/PriceSetDTO.mdx)[], `number`]\\>","optional":false,"defaultValue":"","description":"The list of price sets along with their total count.","children":[{"name":"PriceSetDTO[]","type":"[`PriceSetDTO`](../../interfaces/PriceSetDTO.mdx)[]","optional":false,"defaultValue":"","description":"","children":[]},{"name":"number","type":"`number`","optional":true,"defaultValue":"","description":"","children":[]}]}]} />
|
||||||
-121
@@ -1,121 +0,0 @@
|
|||||||
---
|
|
||||||
displayed_sidebar: pricingReference
|
|
||||||
badge:
|
|
||||||
variant: orange
|
|
||||||
text: Beta
|
|
||||||
slug: /references/pricing/listAndCountCurrencies
|
|
||||||
sidebar_label: listAndCountCurrencies
|
|
||||||
---
|
|
||||||
|
|
||||||
# listAndCountCurrencies - Pricing Module Reference
|
|
||||||
|
|
||||||
This documentation provides a reference to the listAndCountCurrencies method. This belongs to the Pricing Module.
|
|
||||||
|
|
||||||
This method is used to retrieve a paginated list of currencies along with the total count of available currencies satisfying the provided filters.
|
|
||||||
|
|
||||||
## Parameters
|
|
||||||
|
|
||||||
- `filters`: (optional) An object of type [FilterableCurrencyProps](../../interfaces/FilterableCurrencyProps.md) that is used to filter the retrieved currencies. It accepts the following properties:
|
|
||||||
- `$and`: (optional) An array of filters to apply on the entity, where each item in the array is joined with an "and" condition.
|
|
||||||
- `$or`: (optional) An array of filters to apply on the entity, where each item in the array is joined with an "or" condition.
|
|
||||||
- `code`: (optional) an array of strings, each being a currency code to filter the currencies.
|
|
||||||
- `config`: (optional) An object of type [FindConfig](../../interfaces/FindConfig.md) used to configure how the currencies are retrieved. Its properties, such as `select` or `relations`, accept the attributes or relations associated with a currency. It accepts the following properties:
|
|
||||||
- `order`: (optional) An object used to specify how to sort the returned records. Its keys are the names of attributes of the entity, and a key's value can either be `ASC` to sort retrieved records in an ascending order, or `DESC` to sort retrieved records in a descending order.
|
|
||||||
- `relations`: (optional) An array of strings, each being relation names of the entity to retrieve in the result.
|
|
||||||
- `select`: (optional) An array of strings, each being attribute names of the entity to retrieve in the result.
|
|
||||||
- `skip`: (optional) A number indicating the number of records to skip before retrieving the results.
|
|
||||||
- `take`: (optional) A number indicating the number of records to return in the result.
|
|
||||||
- `withDeleted`: (optional) A boolean indicating whether deleted records should also be retrieved as part of the result. This only works if the entity extends the `SoftDeletableEntity` class.
|
|
||||||
- `sharedContext`: (optional) An object of type [Context](../../interfaces/Context.md) used to share resources, such as transaction manager, between the application and the module. It accepts the following properties:
|
|
||||||
- `enableNestedTransactions`: (optional) a boolean value indicating whether nested transactions are enabled.
|
|
||||||
- `isolationLevel`: (optional) A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.
|
|
||||||
- `manager`: (optional) An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.
|
|
||||||
- `transactionId`: (optional) a string indicating the ID of the current transaction.
|
|
||||||
- `transactionManager`: (optional) An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.
|
|
||||||
|
|
||||||
## Returns
|
|
||||||
|
|
||||||
A promise that resolves to an array having two items, the first item is an array of objects of type [CurrencyDTO](../../interfaces/CurrencyDTO.md),
|
|
||||||
and the second item is a number indicating the total count.
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary>
|
|
||||||
CurrencyDTO
|
|
||||||
</summary>
|
|
||||||
|
|
||||||
- `code`: a string indicating the code of the currency.
|
|
||||||
- `name`: (optional) a string indicating the name of the currency.
|
|
||||||
- `symbol`: (optional) a string indicating the symbol of the currency.
|
|
||||||
- `symbol_native`: (optional) a string indicating the symbol of the currecy in its native form. This is typically the symbol used when displaying a price.
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
## Example
|
|
||||||
|
|
||||||
To retrieve a list of currencies using their codes:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function retrieveCurrencies (codes: string[]) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const [currencies, count] = await pricingService.listAndCountCurrencies(
|
|
||||||
{
|
|
||||||
code: codes
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
// do something with the currencies or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
To specify attributes that should be retrieved within the money amounts:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function retrieveCurrencies (codes: string[]) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const [currencies, count] = await pricingService.listAndCountCurrencies(
|
|
||||||
{
|
|
||||||
code: codes
|
|
||||||
},
|
|
||||||
{
|
|
||||||
select: ["symbol_native"]
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
// do something with the currencies or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
By default, only the first `15` records are retrieved. You can control pagination by specifying the `skip` and `take` properties of the `config` parameter:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function retrieveCurrencies (codes: string[], skip: number, take: number) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const [currencies, count] = await pricingService.listAndCountCurrencies(
|
|
||||||
{
|
|
||||||
code: codes
|
|
||||||
},
|
|
||||||
{
|
|
||||||
select: ["symbol_native"],
|
|
||||||
skip,
|
|
||||||
take
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
// do something with the currencies or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
+94
@@ -0,0 +1,94 @@
|
|||||||
|
---
|
||||||
|
displayed_sidebar: pricingReference
|
||||||
|
badge:
|
||||||
|
variant: orange
|
||||||
|
text: Beta
|
||||||
|
slug: /references/pricing/listAndCountCurrencies
|
||||||
|
sidebar_label: listAndCountCurrencies
|
||||||
|
---
|
||||||
|
|
||||||
|
import ParameterTypes from "@site/src/components/ParameterTypes"
|
||||||
|
|
||||||
|
# listAndCountCurrencies - Pricing Module Reference
|
||||||
|
|
||||||
|
This documentation provides a reference to the `listAndCountCurrencies` method. This belongs to the Pricing Module.
|
||||||
|
|
||||||
|
This method is used to retrieve a paginated list of currencies along with the total count of available currencies satisfying the provided filters.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
To retrieve a list of currencies using their codes:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function retrieveCurrencies (codes: string[]) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const [currencies, count] = await pricingService.listAndCountCurrencies(
|
||||||
|
{
|
||||||
|
code: codes
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
// do something with the currencies or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
To specify attributes that should be retrieved within the money amounts:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function retrieveCurrencies (codes: string[]) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const [currencies, count] = await pricingService.listAndCountCurrencies(
|
||||||
|
{
|
||||||
|
code: codes
|
||||||
|
},
|
||||||
|
{
|
||||||
|
select: ["symbol_native"]
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// do something with the currencies or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
By default, only the first `15` records are retrieved. You can control pagination by specifying the `skip` and `take` properties of the `config` parameter:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function retrieveCurrencies (codes: string[], skip: number, take: number) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const [currencies, count] = await pricingService.listAndCountCurrencies(
|
||||||
|
{
|
||||||
|
code: codes
|
||||||
|
},
|
||||||
|
{
|
||||||
|
select: ["symbol_native"],
|
||||||
|
skip,
|
||||||
|
take
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// do something with the currencies or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"filters","type":"[`FilterableCurrencyProps`](../../interfaces/FilterableCurrencyProps.mdx)","description":"The filters to apply on the retrieved currencies.","optional":true,"defaultValue":"","children":[{"name":"$and","type":"([`FilterableCurrencyProps`](../../interfaces/FilterableCurrencyProps.mdx) \\| [`BaseFilterable`](../../interfaces/BaseFilterable.mdx)<[`FilterableCurrencyProps`](../../interfaces/FilterableCurrencyProps.mdx)\\>)[]","description":"An array of filters to apply on the entity, where each item in the array is joined with an \"and\" condition.","optional":true,"defaultValue":"","children":[]},{"name":"$or","type":"([`FilterableCurrencyProps`](../../interfaces/FilterableCurrencyProps.mdx) \\| [`BaseFilterable`](../../interfaces/BaseFilterable.mdx)<[`FilterableCurrencyProps`](../../interfaces/FilterableCurrencyProps.mdx)\\>)[]","description":"An array of filters to apply on the entity, where each item in the array is joined with an \"or\" condition.","optional":true,"defaultValue":"","children":[]},{"name":"code","type":"`string`[]","description":"The codes to filter the currencies by.","optional":true,"defaultValue":"","children":[]}]},{"name":"config","type":"[`FindConfig`](../../interfaces/FindConfig.mdx)<[`CurrencyDTO`](../../interfaces/CurrencyDTO.mdx)\\>","description":"The configurations determining how the currencies are retrieved. Its properties, such as `select` or `relations`, accept the attributes or relations associated with a currency.","optional":true,"defaultValue":"","children":[{"name":"order","type":"`object`","description":"An object used to specify how to sort the returned records. Its keys are the names of attributes of the entity, and a key's value can either be `ASC` to sort retrieved records in an ascending order, or `DESC` to sort retrieved records in a descending order.","optional":true,"defaultValue":"","children":[]},{"name":"relations","type":"`string`[]","description":"An array of strings, each being relation names of the entity to retrieve in the result.","optional":true,"defaultValue":"","children":[]},{"name":"select","type":"(`string` \\| keyof `Entity`)[]","description":"An array of strings, each being attribute names of the entity to retrieve in the result.","optional":true,"defaultValue":"","children":[]},{"name":"skip","type":"`number`","description":"A number indicating the number of records to skip before retrieving the results.","optional":true,"defaultValue":"","children":[]},{"name":"take","type":"`number`","description":"A number indicating the number of records to return in the result.","optional":true,"defaultValue":"","children":[]},{"name":"withDeleted","type":"`boolean`","description":"A boolean indicating whether deleted records should also be retrieved as part of the result. This only works if the entity extends the `SoftDeletableEntity` class.","optional":true,"defaultValue":"","children":[]}]},{"name":"sharedContext","type":"[`Context`](../../interfaces/Context.mdx)","description":"A context used to share resources, such as transaction manager, between the application and the module.","optional":true,"defaultValue":"","children":[{"name":"enableNestedTransactions","type":"`boolean`","description":"a boolean value indicating whether nested transactions are enabled.","optional":true,"defaultValue":"","children":[]},{"name":"isolationLevel","type":"`string`","description":"A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.","optional":true,"defaultValue":"","children":[]},{"name":"manager","type":"`TManager`","description":"An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.","optional":true,"defaultValue":"","children":[]},{"name":"transactionId","type":"`string`","description":"a string indicating the ID of the current transaction.","optional":true,"defaultValue":"","children":[]},{"name":"transactionManager","type":"`TManager`","description":"An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.","optional":true,"defaultValue":"","children":[]}]}]} />
|
||||||
|
|
||||||
|
## Returns
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"Promise","type":"`Promise`<[[`CurrencyDTO`](../../interfaces/CurrencyDTO.mdx)[], `number`]\\>","optional":false,"defaultValue":"","description":"The list of currencies along with the total count.","children":[{"name":"CurrencyDTO[]","type":"[`CurrencyDTO`](../../interfaces/CurrencyDTO.mdx)[]","optional":false,"defaultValue":"","description":"","children":[]},{"name":"number","type":"`number`","optional":true,"defaultValue":"","description":"","children":[]}]}]} />
|
||||||
-160
@@ -1,160 +0,0 @@
|
|||||||
---
|
|
||||||
displayed_sidebar: pricingReference
|
|
||||||
badge:
|
|
||||||
variant: orange
|
|
||||||
text: Beta
|
|
||||||
slug: /references/pricing/listAndCountMoneyAmounts
|
|
||||||
sidebar_label: listAndCountMoneyAmounts
|
|
||||||
---
|
|
||||||
|
|
||||||
# listAndCountMoneyAmounts - Pricing Module Reference
|
|
||||||
|
|
||||||
This documentation provides a reference to the listAndCountMoneyAmounts method. This belongs to the Pricing Module.
|
|
||||||
|
|
||||||
This method is used to retrieve a paginated list of money amounts along with the total count of available money amounts satisfying the provided filters.
|
|
||||||
|
|
||||||
## Parameters
|
|
||||||
|
|
||||||
- `filters`: (optional) An object of type [FilterableMoneyAmountProps](../../interfaces/FilterableMoneyAmountProps.md) that is used to filter the retrieved money amounts. It accepts the following properties:
|
|
||||||
- `$and`: (optional) An array of filters to apply on the entity, where each item in the array is joined with an "and" condition.
|
|
||||||
- `$or`: (optional) An array of filters to apply on the entity, where each item in the array is joined with an "or" condition.
|
|
||||||
- `currency_code`: (optional) A string or an array of strings, each being a currency code to filter money amounts.
|
|
||||||
- `id`: (optional) An array of strings, each being an ID to filter money amounts.
|
|
||||||
- `config`: (optional) An object of type [FindConfig](../../interfaces/FindConfig.md) used to configure how the money amounts are retrieved. Its properties, such as `select` or `relations`, accept the attributes or relations associated with a money amount. It accepts the following properties:
|
|
||||||
- `order`: (optional) An object used to specify how to sort the returned records. Its keys are the names of attributes of the entity, and a key's value can either be `ASC` to sort retrieved records in an ascending order, or `DESC` to sort retrieved records in a descending order.
|
|
||||||
- `relations`: (optional) An array of strings, each being relation names of the entity to retrieve in the result.
|
|
||||||
- `select`: (optional) An array of strings, each being attribute names of the entity to retrieve in the result.
|
|
||||||
- `skip`: (optional) A number indicating the number of records to skip before retrieving the results.
|
|
||||||
- `take`: (optional) A number indicating the number of records to return in the result.
|
|
||||||
- `withDeleted`: (optional) A boolean indicating whether deleted records should also be retrieved as part of the result. This only works if the entity extends the `SoftDeletableEntity` class.
|
|
||||||
- `sharedContext`: (optional) An object of type [Context](../../interfaces/Context.md) used to share resources, such as transaction manager, between the application and the module. It accepts the following properties:
|
|
||||||
- `enableNestedTransactions`: (optional) a boolean value indicating whether nested transactions are enabled.
|
|
||||||
- `isolationLevel`: (optional) A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.
|
|
||||||
- `manager`: (optional) An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.
|
|
||||||
- `transactionId`: (optional) a string indicating the ID of the current transaction.
|
|
||||||
- `transactionManager`: (optional) An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.
|
|
||||||
|
|
||||||
## Returns
|
|
||||||
|
|
||||||
A promise that resolves to an array having two items, the first item is an array of objects of type [MoneyAmountDTO](../../interfaces/MoneyAmountDTO.md),
|
|
||||||
and the second item is a number indicating the total count.
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary>
|
|
||||||
MoneyAmountDTO
|
|
||||||
</summary>
|
|
||||||
|
|
||||||
- `amount`: (optional) A number indicating the amount of this price.
|
|
||||||
- `currency`: (optional) An object of type [CurrencyDTO](../../interfaces/CurrencyDTO.md) that holds the details of the price's currency. Since this is a relation, it will only be retrieved if it's passed to the `relations` array of the find-configuration options. It accepts the following properties:
|
|
||||||
- `code`: a string indicating the code of the currency.
|
|
||||||
- `name`: (optional) a string indicating the name of the currency.
|
|
||||||
- `symbol`: (optional) a string indicating the symbol of the currency.
|
|
||||||
- `symbol_native`: (optional) a string indicating the symbol of the currecy in its native form. This is typically the symbol used when displaying a price.
|
|
||||||
- `currency_code`: (optional) A string that indicates the currency code of this price.
|
|
||||||
- `id`: A string that indicates the ID of the money amount. A money amount represents a price.
|
|
||||||
- `max_quantity`: (optional) A number that indicates the maximum quantity required to be purchased for this price to be applied.
|
|
||||||
- `min_quantity`: (optional) A number that indicates the minimum quantity required to be purchased for this price to be applied.
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
## Example
|
|
||||||
|
|
||||||
To retrieve a list of money amounts using their IDs:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function retrieveMoneyAmounts (moneyAmountIds: string[]) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const [moneyAmounts, count] = await pricingService.listAndCountMoneyAmounts(
|
|
||||||
{
|
|
||||||
id: moneyAmountIds
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
// do something with the money amounts or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
To specify relations that should be retrieved within the money amounts:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function retrieveMoneyAmounts (moneyAmountIds: string[]) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const [moneyAmounts, count] = await pricingService.listAndCountMoneyAmounts(
|
|
||||||
{
|
|
||||||
id: moneyAmountIds
|
|
||||||
},
|
|
||||||
{
|
|
||||||
relations: ["currency"]
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
// do something with the money amounts or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
By default, only the first `15` records are retrieved. You can control pagination by specifying the `skip` and `take` properties of the `config` parameter:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function retrieveMoneyAmounts (moneyAmountIds: string[], skip: number, take: number) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const [moneyAmounts, count] = await pricingService.listAndCountMoneyAmounts(
|
|
||||||
{
|
|
||||||
id: moneyAmountIds
|
|
||||||
},
|
|
||||||
{
|
|
||||||
relations: ["currency"],
|
|
||||||
skip,
|
|
||||||
take
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
// do something with the money amounts or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
You can also use the `$and` or `$or` properties of the `filter` parameter to use and/or conditions in your filters. For example:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function retrieveMoneyAmounts (moneyAmountIds: string[], currencyCode: string[], skip: number, take: number) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const [moneyAmounts, count] = await pricingService.listAndCountMoneyAmounts(
|
|
||||||
{
|
|
||||||
$and: [
|
|
||||||
{
|
|
||||||
id: moneyAmountIds
|
|
||||||
},
|
|
||||||
{
|
|
||||||
currency_code: currencyCode
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
relations: ["currency"],
|
|
||||||
skip,
|
|
||||||
take
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
// do something with the money amounts or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
+126
@@ -0,0 +1,126 @@
|
|||||||
|
---
|
||||||
|
displayed_sidebar: pricingReference
|
||||||
|
badge:
|
||||||
|
variant: orange
|
||||||
|
text: Beta
|
||||||
|
slug: /references/pricing/listAndCountMoneyAmounts
|
||||||
|
sidebar_label: listAndCountMoneyAmounts
|
||||||
|
---
|
||||||
|
|
||||||
|
import ParameterTypes from "@site/src/components/ParameterTypes"
|
||||||
|
|
||||||
|
# listAndCountMoneyAmounts - Pricing Module Reference
|
||||||
|
|
||||||
|
This documentation provides a reference to the `listAndCountMoneyAmounts` method. This belongs to the Pricing Module.
|
||||||
|
|
||||||
|
This method is used to retrieve a paginated list of money amounts along with the total count of available money amounts satisfying the provided filters.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
To retrieve a list of money amounts using their IDs:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function retrieveMoneyAmounts (moneyAmountIds: string[]) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const [moneyAmounts, count] = await pricingService.listAndCountMoneyAmounts(
|
||||||
|
{
|
||||||
|
id: moneyAmountIds
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// do something with the money amounts or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
To specify relations that should be retrieved within the money amounts:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function retrieveMoneyAmounts (moneyAmountIds: string[]) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const [moneyAmounts, count] = await pricingService.listAndCountMoneyAmounts(
|
||||||
|
{
|
||||||
|
id: moneyAmountIds
|
||||||
|
},
|
||||||
|
{
|
||||||
|
relations: ["currency"]
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// do something with the money amounts or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
By default, only the first `15` records are retrieved. You can control pagination by specifying the `skip` and `take` properties of the `config` parameter:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function retrieveMoneyAmounts (moneyAmountIds: string[], skip: number, take: number) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const [moneyAmounts, count] = await pricingService.listAndCountMoneyAmounts(
|
||||||
|
{
|
||||||
|
id: moneyAmountIds
|
||||||
|
},
|
||||||
|
{
|
||||||
|
relations: ["currency"],
|
||||||
|
skip,
|
||||||
|
take
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// do something with the money amounts or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
You can also use the `$and` or `$or` properties of the `filter` parameter to use and/or conditions in your filters. For example:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function retrieveMoneyAmounts (moneyAmountIds: string[], currencyCode: string[], skip: number, take: number) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const [moneyAmounts, count] = await pricingService.listAndCountMoneyAmounts(
|
||||||
|
{
|
||||||
|
$and: [
|
||||||
|
{
|
||||||
|
id: moneyAmountIds
|
||||||
|
},
|
||||||
|
{
|
||||||
|
currency_code: currencyCode
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
relations: ["currency"],
|
||||||
|
skip,
|
||||||
|
take
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// do something with the money amounts or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"filters","type":"[`FilterableMoneyAmountProps`](../../interfaces/FilterableMoneyAmountProps.mdx)","description":"The filters to apply on the retrieved money amounts.","optional":true,"defaultValue":"","children":[{"name":"$and","type":"([`FilterableMoneyAmountProps`](../../interfaces/FilterableMoneyAmountProps.mdx) \\| [`BaseFilterable`](../../interfaces/BaseFilterable.mdx)<[`FilterableMoneyAmountProps`](../../interfaces/FilterableMoneyAmountProps.mdx)\\>)[]","description":"An array of filters to apply on the entity, where each item in the array is joined with an \"and\" condition.","optional":true,"defaultValue":"","children":[]},{"name":"$or","type":"([`FilterableMoneyAmountProps`](../../interfaces/FilterableMoneyAmountProps.mdx) \\| [`BaseFilterable`](../../interfaces/BaseFilterable.mdx)<[`FilterableMoneyAmountProps`](../../interfaces/FilterableMoneyAmountProps.mdx)\\>)[]","description":"An array of filters to apply on the entity, where each item in the array is joined with an \"or\" condition.","optional":true,"defaultValue":"","children":[]},{"name":"currency_code","type":"`string` \\| `string`[]","description":"Currency codes to filter money amounts by.","optional":true,"defaultValue":"","children":[]},{"name":"id","type":"`string`[]","description":"IDs to filter money amounts by.","optional":true,"defaultValue":"","children":[]}]},{"name":"config","type":"[`FindConfig`](../../interfaces/FindConfig.mdx)<[`MoneyAmountDTO`](../../interfaces/MoneyAmountDTO.mdx)\\>","description":"The configurations determining how the money amounts are retrieved. Its properties, such as `select` or `relations`, accept the attributes or relations associated with a money amount.","optional":true,"defaultValue":"","children":[{"name":"order","type":"`object`","description":"An object used to specify how to sort the returned records. Its keys are the names of attributes of the entity, and a key's value can either be `ASC` to sort retrieved records in an ascending order, or `DESC` to sort retrieved records in a descending order.","optional":true,"defaultValue":"","children":[]},{"name":"relations","type":"`string`[]","description":"An array of strings, each being relation names of the entity to retrieve in the result.","optional":true,"defaultValue":"","children":[]},{"name":"select","type":"(`string` \\| keyof `Entity`)[]","description":"An array of strings, each being attribute names of the entity to retrieve in the result.","optional":true,"defaultValue":"","children":[]},{"name":"skip","type":"`number`","description":"A number indicating the number of records to skip before retrieving the results.","optional":true,"defaultValue":"","children":[]},{"name":"take","type":"`number`","description":"A number indicating the number of records to return in the result.","optional":true,"defaultValue":"","children":[]},{"name":"withDeleted","type":"`boolean`","description":"A boolean indicating whether deleted records should also be retrieved as part of the result. This only works if the entity extends the `SoftDeletableEntity` class.","optional":true,"defaultValue":"","children":[]}]},{"name":"sharedContext","type":"[`Context`](../../interfaces/Context.mdx)","description":"A context used to share resources, such as transaction manager, between the application and the module.","optional":true,"defaultValue":"","children":[{"name":"enableNestedTransactions","type":"`boolean`","description":"a boolean value indicating whether nested transactions are enabled.","optional":true,"defaultValue":"","children":[]},{"name":"isolationLevel","type":"`string`","description":"A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.","optional":true,"defaultValue":"","children":[]},{"name":"manager","type":"`TManager`","description":"An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.","optional":true,"defaultValue":"","children":[]},{"name":"transactionId","type":"`string`","description":"a string indicating the ID of the current transaction.","optional":true,"defaultValue":"","children":[]},{"name":"transactionManager","type":"`TManager`","description":"An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.","optional":true,"defaultValue":"","children":[]}]}]} />
|
||||||
|
|
||||||
|
## Returns
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"Promise","type":"`Promise`<[[`MoneyAmountDTO`](../../interfaces/MoneyAmountDTO.mdx)[], `number`]\\>","optional":false,"defaultValue":"","description":"The list of money amounts along with their total count.","children":[{"name":"MoneyAmountDTO[]","type":"[`MoneyAmountDTO`](../../interfaces/MoneyAmountDTO.mdx)[]","optional":false,"defaultValue":"","description":"","children":[]},{"name":"number","type":"`number`","optional":true,"defaultValue":"","description":"","children":[]}]}]} />
|
||||||
-167
@@ -1,167 +0,0 @@
|
|||||||
---
|
|
||||||
displayed_sidebar: pricingReference
|
|
||||||
badge:
|
|
||||||
variant: orange
|
|
||||||
text: Beta
|
|
||||||
slug: /references/pricing/listAndCountPriceRules
|
|
||||||
sidebar_label: listAndCountPriceRules
|
|
||||||
---
|
|
||||||
|
|
||||||
# listAndCountPriceRules - Pricing Module Reference
|
|
||||||
|
|
||||||
This documentation provides a reference to the listAndCountPriceRules method. This belongs to the Pricing Module.
|
|
||||||
|
|
||||||
This method is used to retrieve a paginated list of price rules along with the total count of available price rules satisfying the provided filters.
|
|
||||||
|
|
||||||
## Parameters
|
|
||||||
|
|
||||||
- `filters`: (optional) An object of type [FilterablePriceRuleProps](../../interfaces/FilterablePriceRuleProps.md) that is used to filter the retrieved price rules. It accepts the following properties:
|
|
||||||
- `$and`: (optional) An array of filters to apply on the entity, where each item in the array is joined with an "and" condition.
|
|
||||||
- `$or`: (optional) An array of filters to apply on the entity, where each item in the array is joined with an "or" condition.
|
|
||||||
- `id`: (optional) An array of strings, each indicating an ID to filter price rules.
|
|
||||||
- `name`: (optional) An array of strings, each indicating a name to filter price rules.
|
|
||||||
- `price_set_id`: (optional) An array of strings, each indicating a price set ID to filter price rules.
|
|
||||||
- `rule_type_id`: (optional) An array of strings, each indicating a rule type ID to filter rule types.
|
|
||||||
- `config`: (optional) An object of type [FindConfig](../../interfaces/FindConfig.md) used to configure how the price rule is retrieved. Its properties, such as `select` or `relations`, accept the attributes or relations associated with a price rule. It accepts the following properties:
|
|
||||||
- `order`: (optional) An object used to specify how to sort the returned records. Its keys are the names of attributes of the entity, and a key's value can either be `ASC` to sort retrieved records in an ascending order, or `DESC` to sort retrieved records in a descending order.
|
|
||||||
- `relations`: (optional) An array of strings, each being relation names of the entity to retrieve in the result.
|
|
||||||
- `select`: (optional) An array of strings, each being attribute names of the entity to retrieve in the result.
|
|
||||||
- `skip`: (optional) A number indicating the number of records to skip before retrieving the results.
|
|
||||||
- `take`: (optional) A number indicating the number of records to return in the result.
|
|
||||||
- `withDeleted`: (optional) A boolean indicating whether deleted records should also be retrieved as part of the result. This only works if the entity extends the `SoftDeletableEntity` class.
|
|
||||||
- `sharedContext`: (optional) An object of type [Context](../../interfaces/Context.md) used to share resources, such as transaction manager, between the application and the module. It accepts the following properties:
|
|
||||||
- `enableNestedTransactions`: (optional) a boolean value indicating whether nested transactions are enabled.
|
|
||||||
- `isolationLevel`: (optional) A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.
|
|
||||||
- `manager`: (optional) An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.
|
|
||||||
- `transactionId`: (optional) a string indicating the ID of the current transaction.
|
|
||||||
- `transactionManager`: (optional) An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.
|
|
||||||
|
|
||||||
## Returns
|
|
||||||
|
|
||||||
A promise that resolves to an array of objects of type [PriceRuleDTO](../../interfaces/PriceRuleDTO.md).
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary>
|
|
||||||
PriceRuleDTO
|
|
||||||
</summary>
|
|
||||||
|
|
||||||
- `id`: A string indicating the ID of the price rule.
|
|
||||||
- `is_dynamic`: A boolean indicating whether the price rule is dynamic.
|
|
||||||
- `price_list_id`: A string indicating the ID of the associated price list.
|
|
||||||
- `price_set`: An object of type [PriceSetDTO](../../interfaces/PriceSetDTO.md) that holds the data of the associated price set. It may only be available if the relation `price_set` is expanded. It accepts the following properties:
|
|
||||||
- `id`: A string indicating the ID of the price set.
|
|
||||||
- `money_amounts`: (optional) An array of objects of type [MoneyAmountDTO](../../interfaces/MoneyAmountDTO.md), which holds the prices that belong to this price set. Its items accept the following properties:
|
|
||||||
- `amount`: (optional) A number indicating the amount of this price.
|
|
||||||
- `currency`: (optional) An object of type [CurrencyDTO](../../interfaces/CurrencyDTO.md) that holds the details of the price's currency. Since this is a relation, it will only be retrieved if it's passed to the `relations` array of the find-configuration options.
|
|
||||||
- `currency_code`: (optional) A string that indicates the currency code of this price.
|
|
||||||
- `id`: A string that indicates the ID of the money amount. A money amount represents a price.
|
|
||||||
- `max_quantity`: (optional) A number that indicates the maximum quantity required to be purchased for this price to be applied.
|
|
||||||
- `min_quantity`: (optional) A number that indicates the minimum quantity required to be purchased for this price to be applied.
|
|
||||||
- `rule_types`: (optional) An array of objects of type [RuleTypeDTO](../../interfaces/RuleTypeDTO.md), which holds the rule types applied on this price set. Its items accept the following properties:
|
|
||||||
- `default_priority`: A number indicating the priority of the rule type. This is useful when calculating the price of a price set, and multiple rules satisfy the provided context. The higher the value, the higher the priority of the rule type.
|
|
||||||
- `id`: A string indicating the ID of the rule type.
|
|
||||||
- `name`: A string indicating the display name of the rule type.
|
|
||||||
- `rule_attribute`: A string indicating a unique name used to later identify the rule_attribute. For example, it can be used in the `context` parameter of the `calculatePrices` method to specify a rule for calculating the price.
|
|
||||||
- `price_set_id`: A string indicating the ID of the associated price set.
|
|
||||||
- `price_set_money_amount_id`: A string indicating the ID of the associated price set money amount.
|
|
||||||
- `priority`: A number indicating the priority of the price rule in comparison to other applicable price rules.
|
|
||||||
- `rule_type`: An object of type [RuleTypeDTO](../../interfaces/RuleTypeDTO.md) that holds the data of the associated rule type. It may only be available if the relation `rule_type` is expanded. It accepts the following properties:
|
|
||||||
- `default_priority`: A number indicating the priority of the rule type. This is useful when calculating the price of a price set, and multiple rules satisfy the provided context. The higher the value, the higher the priority of the rule type.
|
|
||||||
- `id`: A string indicating the ID of the rule type.
|
|
||||||
- `name`: A string indicating the display name of the rule type.
|
|
||||||
- `rule_attribute`: A string indicating a unique name used to later identify the rule_attribute. For example, it can be used in the `context` parameter of the `calculatePrices` method to specify a rule for calculating the price.
|
|
||||||
- `rule_type_id`: A string indicating the ID of the associated rule type.
|
|
||||||
- `value`: A string indicating the value of the price rule.
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
## Example
|
|
||||||
|
|
||||||
To retrieve a list of price rules using their IDs:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function retrievePriceRules (id: string) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const [priceRules, count] = await pricingService.listAndCountPriceRules({
|
|
||||||
id: [id]
|
|
||||||
})
|
|
||||||
|
|
||||||
// do something with the price rules or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
To specify relations that should be retrieved within the price rules:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function retrievePriceRules (id: string) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const [priceRules, count] = await pricingService.listAndCountPriceRules({
|
|
||||||
id: [id],
|
|
||||||
}, {
|
|
||||||
relations: ["price_set"]
|
|
||||||
})
|
|
||||||
|
|
||||||
// do something with the price rules or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
By default, only the first `15` records are retrieved. You can control pagination by specifying the `skip` and `take` properties of the `config` parameter:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function retrievePriceRules (id: string, skip: number, take: number) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const [priceRules, count] = await pricingService.listAndCountPriceRules({
|
|
||||||
id: [id],
|
|
||||||
}, {
|
|
||||||
relations: ["price_set"],
|
|
||||||
skip,
|
|
||||||
take
|
|
||||||
})
|
|
||||||
|
|
||||||
// do something with the price rules or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
You can also use the `$and` or `$or` properties of the `filter` parameter to use and/or conditions in your filters. For example:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function retrievePriceRules (ids: string[], name: string[], skip: number, take: number) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const [priceRules, count] = await pricingService.listAndCountPriceRules({
|
|
||||||
$and: [
|
|
||||||
{
|
|
||||||
id: ids
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}, {
|
|
||||||
relations: ["price_set"],
|
|
||||||
skip,
|
|
||||||
take
|
|
||||||
})
|
|
||||||
|
|
||||||
// do something with the price rules or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
+115
@@ -0,0 +1,115 @@
|
|||||||
|
---
|
||||||
|
displayed_sidebar: pricingReference
|
||||||
|
badge:
|
||||||
|
variant: orange
|
||||||
|
text: Beta
|
||||||
|
slug: /references/pricing/listAndCountPriceRules
|
||||||
|
sidebar_label: listAndCountPriceRules
|
||||||
|
---
|
||||||
|
|
||||||
|
import ParameterTypes from "@site/src/components/ParameterTypes"
|
||||||
|
|
||||||
|
# listAndCountPriceRules - Pricing Module Reference
|
||||||
|
|
||||||
|
This documentation provides a reference to the `listAndCountPriceRules` method. This belongs to the Pricing Module.
|
||||||
|
|
||||||
|
This method is used to retrieve a paginated list of price rules along with the total count of available price rules satisfying the provided filters.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
To retrieve a list of price rules using their IDs:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function retrievePriceRules (id: string) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const [priceRules, count] = await pricingService.listAndCountPriceRules({
|
||||||
|
id: [id]
|
||||||
|
})
|
||||||
|
|
||||||
|
// do something with the price rules or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
To specify relations that should be retrieved within the price rules:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function retrievePriceRules (id: string) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const [priceRules, count] = await pricingService.listAndCountPriceRules({
|
||||||
|
id: [id],
|
||||||
|
}, {
|
||||||
|
relations: ["price_set"]
|
||||||
|
})
|
||||||
|
|
||||||
|
// do something with the price rules or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
By default, only the first `15` records are retrieved. You can control pagination by specifying the `skip` and `take` properties of the `config` parameter:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function retrievePriceRules (id: string, skip: number, take: number) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const [priceRules, count] = await pricingService.listAndCountPriceRules({
|
||||||
|
id: [id],
|
||||||
|
}, {
|
||||||
|
relations: ["price_set"],
|
||||||
|
skip,
|
||||||
|
take
|
||||||
|
})
|
||||||
|
|
||||||
|
// do something with the price rules or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
You can also use the `$and` or `$or` properties of the `filter` parameter to use and/or conditions in your filters. For example:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function retrievePriceRules (ids: string[], name: string[], skip: number, take: number) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const [priceRules, count] = await pricingService.listAndCountPriceRules({
|
||||||
|
$and: [
|
||||||
|
{
|
||||||
|
id: ids
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}, {
|
||||||
|
relations: ["price_set"],
|
||||||
|
skip,
|
||||||
|
take
|
||||||
|
})
|
||||||
|
|
||||||
|
// do something with the price rules or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"filters","type":"[`FilterablePriceRuleProps`](../../interfaces/FilterablePriceRuleProps.mdx)","description":"The filters to apply on the retrieved price rules.","optional":true,"defaultValue":"","children":[{"name":"$and","type":"([`FilterablePriceRuleProps`](../../interfaces/FilterablePriceRuleProps.mdx) \\| [`BaseFilterable`](../../interfaces/BaseFilterable.mdx)<[`FilterablePriceRuleProps`](../../interfaces/FilterablePriceRuleProps.mdx)\\>)[]","description":"An array of filters to apply on the entity, where each item in the array is joined with an \"and\" condition.","optional":true,"defaultValue":"","children":[]},{"name":"$or","type":"([`FilterablePriceRuleProps`](../../interfaces/FilterablePriceRuleProps.mdx) \\| [`BaseFilterable`](../../interfaces/BaseFilterable.mdx)<[`FilterablePriceRuleProps`](../../interfaces/FilterablePriceRuleProps.mdx)\\>)[]","description":"An array of filters to apply on the entity, where each item in the array is joined with an \"or\" condition.","optional":true,"defaultValue":"","children":[]},{"name":"id","type":"`string`[]","description":"The IDs to filter price rules by.","optional":true,"defaultValue":"","children":[]},{"name":"name","type":"`string`[]","description":"The names to filter price rules by.","optional":true,"defaultValue":"","children":[]},{"name":"price_set_id","type":"`string`[]","description":"The IDs to filter the price rule's associated price set.","optional":true,"defaultValue":"","children":[]},{"name":"rule_type_id","type":"`string`[]","description":"The IDs to filter the price rule's associated rule type.","optional":true,"defaultValue":"","children":[]}]},{"name":"config","type":"[`FindConfig`](../../interfaces/FindConfig.mdx)<[`PriceRuleDTO`](../../interfaces/PriceRuleDTO.mdx)\\>","description":"The configurations determining how the price rule is retrieved. Its properties, such as `select` or `relations`, accept the attributes or relations associated with a price rule.","optional":true,"defaultValue":"","children":[{"name":"order","type":"`object`","description":"An object used to specify how to sort the returned records. Its keys are the names of attributes of the entity, and a key's value can either be `ASC` to sort retrieved records in an ascending order, or `DESC` to sort retrieved records in a descending order.","optional":true,"defaultValue":"","children":[]},{"name":"relations","type":"`string`[]","description":"An array of strings, each being relation names of the entity to retrieve in the result.","optional":true,"defaultValue":"","children":[]},{"name":"select","type":"(`string` \\| keyof `Entity`)[]","description":"An array of strings, each being attribute names of the entity to retrieve in the result.","optional":true,"defaultValue":"","children":[]},{"name":"skip","type":"`number`","description":"A number indicating the number of records to skip before retrieving the results.","optional":true,"defaultValue":"","children":[]},{"name":"take","type":"`number`","description":"A number indicating the number of records to return in the result.","optional":true,"defaultValue":"","children":[]},{"name":"withDeleted","type":"`boolean`","description":"A boolean indicating whether deleted records should also be retrieved as part of the result. This only works if the entity extends the `SoftDeletableEntity` class.","optional":true,"defaultValue":"","children":[]}]},{"name":"sharedContext","type":"[`Context`](../../interfaces/Context.mdx)","description":"A context used to share resources, such as transaction manager, between the application and the module.","optional":true,"defaultValue":"","children":[{"name":"enableNestedTransactions","type":"`boolean`","description":"a boolean value indicating whether nested transactions are enabled.","optional":true,"defaultValue":"","children":[]},{"name":"isolationLevel","type":"`string`","description":"A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.","optional":true,"defaultValue":"","children":[]},{"name":"manager","type":"`TManager`","description":"An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.","optional":true,"defaultValue":"","children":[]},{"name":"transactionId","type":"`string`","description":"a string indicating the ID of the current transaction.","optional":true,"defaultValue":"","children":[]},{"name":"transactionManager","type":"`TManager`","description":"An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.","optional":true,"defaultValue":"","children":[]}]}]} />
|
||||||
|
|
||||||
|
## Returns
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"Promise","type":"`Promise`<[[`PriceRuleDTO`](../../interfaces/PriceRuleDTO.mdx)[], `number`]\\>","optional":false,"defaultValue":"","description":"The list of price rules along with their total count.","children":[{"name":"PriceRuleDTO[]","type":"[`PriceRuleDTO`](../../interfaces/PriceRuleDTO.mdx)[]","optional":false,"defaultValue":"","description":"","children":[]},{"name":"number","type":"`number`","optional":true,"defaultValue":"","description":"","children":[]}]}]} />
|
||||||
-163
@@ -1,163 +0,0 @@
|
|||||||
---
|
|
||||||
displayed_sidebar: pricingReference
|
|
||||||
badge:
|
|
||||||
variant: orange
|
|
||||||
text: Beta
|
|
||||||
slug: /references/pricing/listAndCountPriceSetMoneyAmountRules
|
|
||||||
sidebar_label: listAndCountPriceSetMoneyAmountRules
|
|
||||||
---
|
|
||||||
|
|
||||||
# listAndCountPriceSetMoneyAmountRules - Pricing Module Reference
|
|
||||||
|
|
||||||
This documentation provides a reference to the listAndCountPriceSetMoneyAmountRules method. This belongs to the Pricing Module.
|
|
||||||
|
|
||||||
This method is used to retrieve a paginated list of price set money amount rules along with the total count of
|
|
||||||
available price set money amount rules satisfying the provided filters.
|
|
||||||
|
|
||||||
## Parameters
|
|
||||||
|
|
||||||
- `filters`: (optional) An object of type [FilterablePriceSetMoneyAmountRulesProps](../../interfaces/FilterablePriceSetMoneyAmountRulesProps.md) that is used to filter the retrieved price set money amount rules. It accepts the following properties:
|
|
||||||
- `$and`: (optional) An array of filters to apply on the entity, where each item in the array is joined with an "and" condition.
|
|
||||||
- `$or`: (optional) An array of filters to apply on the entity, where each item in the array is joined with an "or" condition.
|
|
||||||
- `id`: (optional) An array of strings, each string indicating an ID to filter the price set money amount rules.
|
|
||||||
- `price_set_money_amount_id`: (optional) an array of strings, each string indicating the ID of a price set money amount to filter the price set money amount rules.
|
|
||||||
- `rule_type_id`: (optional) An array of strings, each string indicating the ID of a rule type to filter the price set money amount rules.
|
|
||||||
- `value`: (optional) an array of strings, each string indicating a value to filter the price set money amount rules.
|
|
||||||
- `config`: (optional) An object of type [FindConfig](../../interfaces/FindConfig.md) used to configure how the price set money amount rules are retrieved. Its properties, such as `select` or `relations`, accept the attributes or relations associated with a price set money amount rule. It accepts the following properties:
|
|
||||||
- `order`: (optional) An object used to specify how to sort the returned records. Its keys are the names of attributes of the entity, and a key's value can either be `ASC` to sort retrieved records in an ascending order, or `DESC` to sort retrieved records in a descending order.
|
|
||||||
- `relations`: (optional) An array of strings, each being relation names of the entity to retrieve in the result.
|
|
||||||
- `select`: (optional) An array of strings, each being attribute names of the entity to retrieve in the result.
|
|
||||||
- `skip`: (optional) A number indicating the number of records to skip before retrieving the results.
|
|
||||||
- `take`: (optional) A number indicating the number of records to return in the result.
|
|
||||||
- `withDeleted`: (optional) A boolean indicating whether deleted records should also be retrieved as part of the result. This only works if the entity extends the `SoftDeletableEntity` class.
|
|
||||||
- `sharedContext`: (optional) An object of type [Context](../../interfaces/Context.md) used to share resources, such as transaction manager, between the application and the module. It accepts the following properties:
|
|
||||||
- `enableNestedTransactions`: (optional) a boolean value indicating whether nested transactions are enabled.
|
|
||||||
- `isolationLevel`: (optional) A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.
|
|
||||||
- `manager`: (optional) An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.
|
|
||||||
- `transactionId`: (optional) a string indicating the ID of the current transaction.
|
|
||||||
- `transactionManager`: (optional) An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.
|
|
||||||
|
|
||||||
## Returns
|
|
||||||
|
|
||||||
A promise that resolves to an array having two items, the first item is an array of objects of type [PriceSetMoneyAmountRulesDTO](../../interfaces/PriceSetMoneyAmountRulesDTO.md),
|
|
||||||
and the second item is a number indicating the total count.
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary>
|
|
||||||
PriceSetMoneyAmountRulesDTO
|
|
||||||
</summary>
|
|
||||||
|
|
||||||
- `id`: A string indicating the ID of the price set money amount.
|
|
||||||
- `price_set_money_amount`: an object of type [PriceSetMoneyAmountDTO](../../interfaces/PriceSetMoneyAmountDTO.md) holding the data of the associated price set money amount. It accepts the following properties:
|
|
||||||
- `id`: a string indicating the ID of a price set money amount.
|
|
||||||
- `money_amount`: (optional) an object of type [MoneyAmountDTO](../../interfaces/MoneyAmountDTO.md) holding the data of the associated money amount. It accepts the following properties:
|
|
||||||
- `amount`: (optional) A number indicating the amount of this price.
|
|
||||||
- `currency`: (optional) An object of type [CurrencyDTO](../../interfaces/CurrencyDTO.md) that holds the details of the price's currency. Since this is a relation, it will only be retrieved if it's passed to the `relations` array of the find-configuration options.
|
|
||||||
- `currency_code`: (optional) A string that indicates the currency code of this price.
|
|
||||||
- `id`: A string that indicates the ID of the money amount. A money amount represents a price.
|
|
||||||
- `max_quantity`: (optional) A number that indicates the maximum quantity required to be purchased for this price to be applied.
|
|
||||||
- `min_quantity`: (optional) A number that indicates the minimum quantity required to be purchased for this price to be applied.
|
|
||||||
- `price_set`: (optional) an object of type [PriceSetDTO](../../interfaces/PriceSetDTO.md) holding the data of the associated price set. It accepts the following properties:
|
|
||||||
- `id`: A string indicating the ID of the price set.
|
|
||||||
- `money_amounts`: (optional) An array of objects of type [MoneyAmountDTO](../../interfaces/MoneyAmountDTO.md), which holds the prices that belong to this price set.
|
|
||||||
- `rule_types`: (optional) An array of objects of type [RuleTypeDTO](../../interfaces/RuleTypeDTO.md), which holds the rule types applied on this price set.
|
|
||||||
- `title`: (optional) a string indicating the title of the price set money amount.
|
|
||||||
- `rule_type`: an object of type [RuleTypeDTO](../../interfaces/RuleTypeDTO.md) holding the data of the associated rule type. It accepts the following properties:
|
|
||||||
- `default_priority`: A number indicating the priority of the rule type. This is useful when calculating the price of a price set, and multiple rules satisfy the provided context. The higher the value, the higher the priority of the rule type.
|
|
||||||
- `id`: A string indicating the ID of the rule type.
|
|
||||||
- `name`: A string indicating the display name of the rule type.
|
|
||||||
- `rule_attribute`: A string indicating a unique name used to later identify the rule_attribute. For example, it can be used in the `context` parameter of the `calculatePrices` method to specify a rule for calculating the price.
|
|
||||||
- `value`: a string indicating the value of the price set money amount rule.
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
## Example
|
|
||||||
|
|
||||||
To retrieve a list of price set money amounts using their IDs:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function retrievePriceSetMoneyAmountRules (id: string) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const [priceSetMoneyAmountRules, count] = await pricingService.listAndCountPriceSetMoneyAmountRules({
|
|
||||||
id: [id]
|
|
||||||
})
|
|
||||||
|
|
||||||
// do something with the price set money amount rules or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
To specify relations that should be retrieved within the price set money amount rules:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function retrievePriceSetMoneyAmountRules (id: string) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const [priceSetMoneyAmountRules, count] = await pricingService.listAndCountPriceSetMoneyAmountRules({
|
|
||||||
id: [id]
|
|
||||||
}, {
|
|
||||||
relations: ["price_set_money_amount"],
|
|
||||||
})
|
|
||||||
|
|
||||||
// do something with the price set money amount rules or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
By default, only the first `15` records are retrieved. You can control pagination by specifying the `skip` and `take` properties of the `config` parameter:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function retrievePriceSetMoneyAmountRules (id: string, skip: number, take: number) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const [priceSetMoneyAmountRules, count] = await pricingService.listAndCountPriceSetMoneyAmountRules({
|
|
||||||
id: [id]
|
|
||||||
}, {
|
|
||||||
relations: ["price_set_money_amount"],
|
|
||||||
skip,
|
|
||||||
take
|
|
||||||
})
|
|
||||||
|
|
||||||
// do something with the price set money amount rules or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
You can also use the `$and` or `$or` properties of the `filter` parameter to use and/or conditions in your filters. For example:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function retrievePriceSetMoneyAmountRules (ids: string[], ruleTypeId: string[], skip: number, take: number) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const [priceSetMoneyAmountRules, count] = await pricingService.listAndCountPriceSetMoneyAmountRules({
|
|
||||||
$and: [
|
|
||||||
{
|
|
||||||
id: ids
|
|
||||||
},
|
|
||||||
{
|
|
||||||
rule_type_id: ruleTypeId
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}, {
|
|
||||||
relations: ["price_set_money_amount"],
|
|
||||||
skip,
|
|
||||||
take
|
|
||||||
})
|
|
||||||
|
|
||||||
// do something with the price set money amount rules or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
+116
@@ -0,0 +1,116 @@
|
|||||||
|
---
|
||||||
|
displayed_sidebar: pricingReference
|
||||||
|
badge:
|
||||||
|
variant: orange
|
||||||
|
text: Beta
|
||||||
|
slug: /references/pricing/listAndCountPriceSetMoneyAmountRules
|
||||||
|
sidebar_label: listAndCountPriceSetMoneyAmountRules
|
||||||
|
---
|
||||||
|
|
||||||
|
import ParameterTypes from "@site/src/components/ParameterTypes"
|
||||||
|
|
||||||
|
# listAndCountPriceSetMoneyAmountRules - Pricing Module Reference
|
||||||
|
|
||||||
|
This documentation provides a reference to the `listAndCountPriceSetMoneyAmountRules` method. This belongs to the Pricing Module.
|
||||||
|
|
||||||
|
This method is used to retrieve a paginated list of price set money amount rules along with the total count of
|
||||||
|
available price set money amount rules satisfying the provided filters.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
To retrieve a list of price set money amounts using their IDs:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function retrievePriceSetMoneyAmountRules (id: string) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const [priceSetMoneyAmountRules, count] = await pricingService.listAndCountPriceSetMoneyAmountRules({
|
||||||
|
id: [id]
|
||||||
|
})
|
||||||
|
|
||||||
|
// do something with the price set money amount rules or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
To specify relations that should be retrieved within the price set money amount rules:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function retrievePriceSetMoneyAmountRules (id: string) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const [priceSetMoneyAmountRules, count] = await pricingService.listAndCountPriceSetMoneyAmountRules({
|
||||||
|
id: [id]
|
||||||
|
}, {
|
||||||
|
relations: ["price_set_money_amount"],
|
||||||
|
})
|
||||||
|
|
||||||
|
// do something with the price set money amount rules or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
By default, only the first `15` records are retrieved. You can control pagination by specifying the `skip` and `take` properties of the `config` parameter:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function retrievePriceSetMoneyAmountRules (id: string, skip: number, take: number) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const [priceSetMoneyAmountRules, count] = await pricingService.listAndCountPriceSetMoneyAmountRules({
|
||||||
|
id: [id]
|
||||||
|
}, {
|
||||||
|
relations: ["price_set_money_amount"],
|
||||||
|
skip,
|
||||||
|
take
|
||||||
|
})
|
||||||
|
|
||||||
|
// do something with the price set money amount rules or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
You can also use the `$and` or `$or` properties of the `filter` parameter to use and/or conditions in your filters. For example:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function retrievePriceSetMoneyAmountRules (ids: string[], ruleTypeId: string[], skip: number, take: number) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const [priceSetMoneyAmountRules, count] = await pricingService.listAndCountPriceSetMoneyAmountRules({
|
||||||
|
$and: [
|
||||||
|
{
|
||||||
|
id: ids
|
||||||
|
},
|
||||||
|
{
|
||||||
|
rule_type_id: ruleTypeId
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}, {
|
||||||
|
relations: ["price_set_money_amount"],
|
||||||
|
skip,
|
||||||
|
take
|
||||||
|
})
|
||||||
|
|
||||||
|
// do something with the price set money amount rules or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"filters","type":"[`FilterablePriceSetMoneyAmountRulesProps`](../../interfaces/FilterablePriceSetMoneyAmountRulesProps.mdx)","description":"The filters to apply on the retrieved price set money amount rules.","optional":true,"defaultValue":"","children":[{"name":"$and","type":"([`FilterablePriceSetMoneyAmountRulesProps`](../../interfaces/FilterablePriceSetMoneyAmountRulesProps.mdx) \\| [`BaseFilterable`](../../interfaces/BaseFilterable.mdx)<[`FilterablePriceSetMoneyAmountRulesProps`](../../interfaces/FilterablePriceSetMoneyAmountRulesProps.mdx)\\>)[]","description":"An array of filters to apply on the entity, where each item in the array is joined with an \"and\" condition.","optional":true,"defaultValue":"","children":[]},{"name":"$or","type":"([`FilterablePriceSetMoneyAmountRulesProps`](../../interfaces/FilterablePriceSetMoneyAmountRulesProps.mdx) \\| [`BaseFilterable`](../../interfaces/BaseFilterable.mdx)<[`FilterablePriceSetMoneyAmountRulesProps`](../../interfaces/FilterablePriceSetMoneyAmountRulesProps.mdx)\\>)[]","description":"An array of filters to apply on the entity, where each item in the array is joined with an \"or\" condition.","optional":true,"defaultValue":"","children":[]},{"name":"id","type":"`string`[]","description":"The ID to filter price set money amount rules by.","optional":true,"defaultValue":"","children":[]},{"name":"price_set_money_amount_id","type":"`string`[]","description":"The IDs to filter the price set money amount rule's associated price set money amount.","optional":true,"defaultValue":"","children":[]},{"name":"rule_type_id","type":"`string`[]","description":"The IDs to filter the price set money amount rule's associated rule type.","optional":true,"defaultValue":"","children":[]},{"name":"value","type":"`string`[]","description":"The value to filter price set money amount rules by.","optional":true,"defaultValue":"","children":[]}]},{"name":"config","type":"[`FindConfig`](../../interfaces/FindConfig.mdx)<[`PriceSetMoneyAmountRulesDTO`](../../interfaces/PriceSetMoneyAmountRulesDTO.mdx)\\>","description":"The configurations determining how the price set money amount rules are retrieved. Its properties, such as `select` or `relations`, accept the attributes or relations associated with a price set money amount rule.","optional":true,"defaultValue":"","children":[{"name":"order","type":"`object`","description":"An object used to specify how to sort the returned records. Its keys are the names of attributes of the entity, and a key's value can either be `ASC` to sort retrieved records in an ascending order, or `DESC` to sort retrieved records in a descending order.","optional":true,"defaultValue":"","children":[]},{"name":"relations","type":"`string`[]","description":"An array of strings, each being relation names of the entity to retrieve in the result.","optional":true,"defaultValue":"","children":[]},{"name":"select","type":"(`string` \\| keyof `Entity`)[]","description":"An array of strings, each being attribute names of the entity to retrieve in the result.","optional":true,"defaultValue":"","children":[]},{"name":"skip","type":"`number`","description":"A number indicating the number of records to skip before retrieving the results.","optional":true,"defaultValue":"","children":[]},{"name":"take","type":"`number`","description":"A number indicating the number of records to return in the result.","optional":true,"defaultValue":"","children":[]},{"name":"withDeleted","type":"`boolean`","description":"A boolean indicating whether deleted records should also be retrieved as part of the result. This only works if the entity extends the `SoftDeletableEntity` class.","optional":true,"defaultValue":"","children":[]}]},{"name":"sharedContext","type":"[`Context`](../../interfaces/Context.mdx)","description":"A context used to share resources, such as transaction manager, between the application and the module.","optional":true,"defaultValue":"","children":[{"name":"enableNestedTransactions","type":"`boolean`","description":"a boolean value indicating whether nested transactions are enabled.","optional":true,"defaultValue":"","children":[]},{"name":"isolationLevel","type":"`string`","description":"A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.","optional":true,"defaultValue":"","children":[]},{"name":"manager","type":"`TManager`","description":"An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.","optional":true,"defaultValue":"","children":[]},{"name":"transactionId","type":"`string`","description":"a string indicating the ID of the current transaction.","optional":true,"defaultValue":"","children":[]},{"name":"transactionManager","type":"`TManager`","description":"An instance of a transaction manager of type `TManager`, which is aLine truncated
|
||||||
|
|
||||||
|
## Returns
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"Promise","type":"`Promise`<[[`PriceSetMoneyAmountRulesDTO`](../../interfaces/PriceSetMoneyAmountRulesDTO.mdx)[], `number`]\\>","optional":false,"defaultValue":"","description":"The list of price set money amount rules and their total count.","children":[{"name":"PriceSetMoneyAmountRulesDTO[]","type":"[`PriceSetMoneyAmountRulesDTO`](../../interfaces/PriceSetMoneyAmountRulesDTO.mdx)[]","optional":false,"defaultValue":"","description":"","children":[]},{"name":"number","type":"`number`","optional":true,"defaultValue":"","description":"","children":[]}]}]} />
|
||||||
-150
@@ -1,150 +0,0 @@
|
|||||||
---
|
|
||||||
displayed_sidebar: pricingReference
|
|
||||||
badge:
|
|
||||||
variant: orange
|
|
||||||
text: Beta
|
|
||||||
slug: /references/pricing/listAndCountRuleTypes
|
|
||||||
sidebar_label: listAndCountRuleTypes
|
|
||||||
---
|
|
||||||
|
|
||||||
# listAndCountRuleTypes - Pricing Module Reference
|
|
||||||
|
|
||||||
This documentation provides a reference to the listAndCountRuleTypes method. This belongs to the Pricing Module.
|
|
||||||
|
|
||||||
This method is used to retrieve a paginated list of rule types along with the total count of available rule types satisfying the provided filters.
|
|
||||||
|
|
||||||
## Parameters
|
|
||||||
|
|
||||||
- `filters`: (optional) An object of type [FilterableRuleTypeProps](../../interfaces/FilterableRuleTypeProps.md) that is used to filter the retrieved rule types. It accepts the following properties:
|
|
||||||
- `$and`: (optional) An array of filters to apply on the entity, where each item in the array is joined with an "and" condition.
|
|
||||||
- `$or`: (optional) An array of filters to apply on the entity, where each item in the array is joined with an "or" condition.
|
|
||||||
- `id`: (optional) an array of strings, each being an ID to filter rule types.
|
|
||||||
- `name`: (optional) an array of strings, each being a name to filter rule types.
|
|
||||||
- `rule_attribute`: (optional) an array of strings, each being a rule attribute to filter rule types.
|
|
||||||
- `config`: (optional) An object of type [FindConfig](../../interfaces/FindConfig.md) used to configure how the rule types are retrieved. Its properties, such as `select` or `relations`, accept the attributes or relations associated with a rule type. It accepts the following properties:
|
|
||||||
- `order`: (optional) An object used to specify how to sort the returned records. Its keys are the names of attributes of the entity, and a key's value can either be `ASC` to sort retrieved records in an ascending order, or `DESC` to sort retrieved records in a descending order.
|
|
||||||
- `relations`: (optional) An array of strings, each being relation names of the entity to retrieve in the result.
|
|
||||||
- `select`: (optional) An array of strings, each being attribute names of the entity to retrieve in the result.
|
|
||||||
- `skip`: (optional) A number indicating the number of records to skip before retrieving the results.
|
|
||||||
- `take`: (optional) A number indicating the number of records to return in the result.
|
|
||||||
- `withDeleted`: (optional) A boolean indicating whether deleted records should also be retrieved as part of the result. This only works if the entity extends the `SoftDeletableEntity` class.
|
|
||||||
- `sharedContext`: (optional) An object of type [Context](../../interfaces/Context.md) used to share resources, such as transaction manager, between the application and the module. It accepts the following properties:
|
|
||||||
- `enableNestedTransactions`: (optional) a boolean value indicating whether nested transactions are enabled.
|
|
||||||
- `isolationLevel`: (optional) A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.
|
|
||||||
- `manager`: (optional) An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.
|
|
||||||
- `transactionId`: (optional) a string indicating the ID of the current transaction.
|
|
||||||
- `transactionManager`: (optional) An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.
|
|
||||||
|
|
||||||
## Returns
|
|
||||||
|
|
||||||
A promise that resolves to an array having two items, the first item is an array of objects of type [RuleTypeDTO](../../interfaces/RuleTypeDTO.md),
|
|
||||||
and the second item is a number indicating the total count.
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary>
|
|
||||||
RuleTypeDTO
|
|
||||||
</summary>
|
|
||||||
|
|
||||||
- `default_priority`: A number indicating the priority of the rule type. This is useful when calculating the price of a price set, and multiple rules satisfy the provided context. The higher the value, the higher the priority of the rule type.
|
|
||||||
- `id`: A string indicating the ID of the rule type.
|
|
||||||
- `name`: A string indicating the display name of the rule type.
|
|
||||||
- `rule_attribute`: A string indicating a unique name used to later identify the rule_attribute. For example, it can be used in the `context` parameter of the `calculatePrices` method to specify a rule for calculating the price.
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
## Example
|
|
||||||
|
|
||||||
To retrieve a list of rule types using their IDs:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function retrieveRuleTypes (ruleTypeId: string) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const [ruleTypes, count] = await pricingService.listAndCountRuleTypes({
|
|
||||||
id: [
|
|
||||||
ruleTypeId
|
|
||||||
]
|
|
||||||
})
|
|
||||||
|
|
||||||
// do something with the rule types or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
To specify attributes that should be retrieved within the rule types:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function retrieveRuleTypes (ruleTypeId: string) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const [ruleTypes, count] = await pricingService.listAndCountRuleTypes({
|
|
||||||
id: [
|
|
||||||
ruleTypeId
|
|
||||||
]
|
|
||||||
}, {
|
|
||||||
select: ["name"]
|
|
||||||
})
|
|
||||||
|
|
||||||
// do something with the rule types or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
By default, only the first `15` records are retrieved. You can control pagination by specifying the `skip` and `take` properties of the `config` parameter:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function retrieveRuleTypes (ruleTypeId: string, skip: number, take: number) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const [ruleTypes, count] = await pricingService.listAndCountRuleTypes({
|
|
||||||
id: [
|
|
||||||
ruleTypeId
|
|
||||||
]
|
|
||||||
}, {
|
|
||||||
select: ["name"],
|
|
||||||
skip,
|
|
||||||
take
|
|
||||||
})
|
|
||||||
|
|
||||||
// do something with the rule types or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
You can also use the `$and` or `$or` properties of the `filter` parameter to use and/or conditions in your filters. For example:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function retrieveRuleTypes (ruleTypeId: string[], name: string[], skip: number, take: number) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const [ruleTypes, count] = await pricingService.listAndCountRuleTypes({
|
|
||||||
$and: [
|
|
||||||
{
|
|
||||||
id: ruleTypeId
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}, {
|
|
||||||
select: ["name"],
|
|
||||||
skip,
|
|
||||||
take
|
|
||||||
})
|
|
||||||
|
|
||||||
// do something with the rule types or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
+121
@@ -0,0 +1,121 @@
|
|||||||
|
---
|
||||||
|
displayed_sidebar: pricingReference
|
||||||
|
badge:
|
||||||
|
variant: orange
|
||||||
|
text: Beta
|
||||||
|
slug: /references/pricing/listAndCountRuleTypes
|
||||||
|
sidebar_label: listAndCountRuleTypes
|
||||||
|
---
|
||||||
|
|
||||||
|
import ParameterTypes from "@site/src/components/ParameterTypes"
|
||||||
|
|
||||||
|
# listAndCountRuleTypes - Pricing Module Reference
|
||||||
|
|
||||||
|
This documentation provides a reference to the `listAndCountRuleTypes` method. This belongs to the Pricing Module.
|
||||||
|
|
||||||
|
This method is used to retrieve a paginated list of rule types along with the total count of available rule types satisfying the provided filters.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
To retrieve a list of rule types using their IDs:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function retrieveRuleTypes (ruleTypeId: string) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const [ruleTypes, count] = await pricingService.listAndCountRuleTypes({
|
||||||
|
id: [
|
||||||
|
ruleTypeId
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
|
// do something with the rule types or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
To specify attributes that should be retrieved within the rule types:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function retrieveRuleTypes (ruleTypeId: string) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const [ruleTypes, count] = await pricingService.listAndCountRuleTypes({
|
||||||
|
id: [
|
||||||
|
ruleTypeId
|
||||||
|
]
|
||||||
|
}, {
|
||||||
|
select: ["name"]
|
||||||
|
})
|
||||||
|
|
||||||
|
// do something with the rule types or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
By default, only the first `15` records are retrieved. You can control pagination by specifying the `skip` and `take` properties of the `config` parameter:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function retrieveRuleTypes (ruleTypeId: string, skip: number, take: number) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const [ruleTypes, count] = await pricingService.listAndCountRuleTypes({
|
||||||
|
id: [
|
||||||
|
ruleTypeId
|
||||||
|
]
|
||||||
|
}, {
|
||||||
|
select: ["name"],
|
||||||
|
skip,
|
||||||
|
take
|
||||||
|
})
|
||||||
|
|
||||||
|
// do something with the rule types or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
You can also use the `$and` or `$or` properties of the `filter` parameter to use and/or conditions in your filters. For example:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function retrieveRuleTypes (ruleTypeId: string[], name: string[], skip: number, take: number) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const [ruleTypes, count] = await pricingService.listAndCountRuleTypes({
|
||||||
|
$and: [
|
||||||
|
{
|
||||||
|
id: ruleTypeId
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}, {
|
||||||
|
select: ["name"],
|
||||||
|
skip,
|
||||||
|
take
|
||||||
|
})
|
||||||
|
|
||||||
|
// do something with the rule types or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"filters","type":"[`FilterableRuleTypeProps`](../../interfaces/FilterableRuleTypeProps.mdx)","description":"The filters to apply on the retrieved rule types.","optional":true,"defaultValue":"","children":[{"name":"$and","type":"([`FilterableRuleTypeProps`](../../interfaces/FilterableRuleTypeProps.mdx) \\| [`BaseFilterable`](../../interfaces/BaseFilterable.mdx)<[`FilterableRuleTypeProps`](../../interfaces/FilterableRuleTypeProps.mdx)\\>)[]","description":"An array of filters to apply on the entity, where each item in the array is joined with an \"and\" condition.","optional":true,"defaultValue":"","children":[]},{"name":"$or","type":"([`FilterableRuleTypeProps`](../../interfaces/FilterableRuleTypeProps.mdx) \\| [`BaseFilterable`](../../interfaces/BaseFilterable.mdx)<[`FilterableRuleTypeProps`](../../interfaces/FilterableRuleTypeProps.mdx)\\>)[]","description":"An array of filters to apply on the entity, where each item in the array is joined with an \"or\" condition.","optional":true,"defaultValue":"","children":[]},{"name":"id","type":"`string`[]","description":"The IDs to filter rule types by.","optional":true,"defaultValue":"","children":[]},{"name":"name","type":"`string`[]","description":"The names to filter rule types by.","optional":true,"defaultValue":"","children":[]},{"name":"rule_attribute","type":"`string`[]","description":"The rule attributes to filter rule types by.","optional":true,"defaultValue":"","children":[]}]},{"name":"config","type":"[`FindConfig`](../../interfaces/FindConfig.mdx)<[`RuleTypeDTO`](../../interfaces/RuleTypeDTO.mdx)\\>","description":"The configurations determining how the rule types are retrieved. Its properties, such as `select` or `relations`, accept the attributes or relations associated with a rule type.","optional":true,"defaultValue":"","children":[{"name":"order","type":"`object`","description":"An object used to specify how to sort the returned records. Its keys are the names of attributes of the entity, and a key's value can either be `ASC` to sort retrieved records in an ascending order, or `DESC` to sort retrieved records in a descending order.","optional":true,"defaultValue":"","children":[]},{"name":"relations","type":"`string`[]","description":"An array of strings, each being relation names of the entity to retrieve in the result.","optional":true,"defaultValue":"","children":[]},{"name":"select","type":"(`string` \\| keyof `Entity`)[]","description":"An array of strings, each being attribute names of the entity to retrieve in the result.","optional":true,"defaultValue":"","children":[]},{"name":"skip","type":"`number`","description":"A number indicating the number of records to skip before retrieving the results.","optional":true,"defaultValue":"","children":[]},{"name":"take","type":"`number`","description":"A number indicating the number of records to return in the result.","optional":true,"defaultValue":"","children":[]},{"name":"withDeleted","type":"`boolean`","description":"A boolean indicating whether deleted records should also be retrieved as part of the result. This only works if the entity extends the `SoftDeletableEntity` class.","optional":true,"defaultValue":"","children":[]}]},{"name":"sharedContext","type":"[`Context`](../../interfaces/Context.mdx)","description":"A context used to share resources, such as transaction manager, between the application and the module.","optional":true,"defaultValue":"","children":[{"name":"enableNestedTransactions","type":"`boolean`","description":"a boolean value indicating whether nested transactions are enabled.","optional":true,"defaultValue":"","children":[]},{"name":"isolationLevel","type":"`string`","description":"A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.","optional":true,"defaultValue":"","children":[]},{"name":"manager","type":"`TManager`","description":"An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.","optional":true,"defaultValue":"","children":[]},{"name":"transactionId","type":"`string`","description":"a string indicating the ID of the current transaction.","optional":true,"defaultValue":"","children":[]},{"name":"transactionManager","type":"`TManager`","description":"An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.","optional":true,"defaultValue":"","children":[]}]}]} />
|
||||||
|
|
||||||
|
## Returns
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"Promise","type":"`Promise`<[[`RuleTypeDTO`](../../interfaces/RuleTypeDTO.mdx)[], `number`]\\>","optional":false,"defaultValue":"","description":"The list of rule types along with their total count.","children":[{"name":"RuleTypeDTO[]","type":"[`RuleTypeDTO`](../../interfaces/RuleTypeDTO.mdx)[]","optional":false,"defaultValue":"","description":"","children":[]},{"name":"number","type":"`number`","optional":true,"defaultValue":"","description":"","children":[]}]}]} />
|
||||||
-120
@@ -1,120 +0,0 @@
|
|||||||
---
|
|
||||||
displayed_sidebar: pricingReference
|
|
||||||
badge:
|
|
||||||
variant: orange
|
|
||||||
text: Beta
|
|
||||||
slug: /references/pricing/listCurrencies
|
|
||||||
sidebar_label: listCurrencies
|
|
||||||
---
|
|
||||||
|
|
||||||
# listCurrencies - Pricing Module Reference
|
|
||||||
|
|
||||||
This documentation provides a reference to the listCurrencies method. This belongs to the Pricing Module.
|
|
||||||
|
|
||||||
This method is used to retrieve a paginated list of currencies based on optional filters and configuration.
|
|
||||||
|
|
||||||
## Parameters
|
|
||||||
|
|
||||||
- `filters`: (optional) An object of type [FilterableCurrencyProps](../../interfaces/FilterableCurrencyProps.md) that is used to filter the retrieved currencies. It accepts the following properties:
|
|
||||||
- `$and`: (optional) An array of filters to apply on the entity, where each item in the array is joined with an "and" condition.
|
|
||||||
- `$or`: (optional) An array of filters to apply on the entity, where each item in the array is joined with an "or" condition.
|
|
||||||
- `code`: (optional) an array of strings, each being a currency code to filter the currencies.
|
|
||||||
- `config`: (optional) An object of type [FindConfig](../../interfaces/FindConfig.md) used to configure how the currencies are retrieved. Its properties, such as `select` or `relations`, accept the attributes or relations associated with a currency. It accepts the following properties:
|
|
||||||
- `order`: (optional) An object used to specify how to sort the returned records. Its keys are the names of attributes of the entity, and a key's value can either be `ASC` to sort retrieved records in an ascending order, or `DESC` to sort retrieved records in a descending order.
|
|
||||||
- `relations`: (optional) An array of strings, each being relation names of the entity to retrieve in the result.
|
|
||||||
- `select`: (optional) An array of strings, each being attribute names of the entity to retrieve in the result.
|
|
||||||
- `skip`: (optional) A number indicating the number of records to skip before retrieving the results.
|
|
||||||
- `take`: (optional) A number indicating the number of records to return in the result.
|
|
||||||
- `withDeleted`: (optional) A boolean indicating whether deleted records should also be retrieved as part of the result. This only works if the entity extends the `SoftDeletableEntity` class.
|
|
||||||
- `sharedContext`: (optional) An object of type [Context](../../interfaces/Context.md) used to share resources, such as transaction manager, between the application and the module. It accepts the following properties:
|
|
||||||
- `enableNestedTransactions`: (optional) a boolean value indicating whether nested transactions are enabled.
|
|
||||||
- `isolationLevel`: (optional) A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.
|
|
||||||
- `manager`: (optional) An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.
|
|
||||||
- `transactionId`: (optional) a string indicating the ID of the current transaction.
|
|
||||||
- `transactionManager`: (optional) An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.
|
|
||||||
|
|
||||||
## Returns
|
|
||||||
|
|
||||||
A promise that resolves to an array of objects of type [CurrencyDTO](../../interfaces/CurrencyDTO.md).
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary>
|
|
||||||
CurrencyDTO
|
|
||||||
</summary>
|
|
||||||
|
|
||||||
- `code`: a string indicating the code of the currency.
|
|
||||||
- `name`: (optional) a string indicating the name of the currency.
|
|
||||||
- `symbol`: (optional) a string indicating the symbol of the currency.
|
|
||||||
- `symbol_native`: (optional) a string indicating the symbol of the currecy in its native form. This is typically the symbol used when displaying a price.
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
## Example
|
|
||||||
|
|
||||||
To retrieve a list of currencies using their codes:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function retrieveCurrencies (codes: string[]) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const currencies = await pricingService.listCurrencies(
|
|
||||||
{
|
|
||||||
code: codes
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
// do something with the currencies or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
To specify attributes that should be retrieved within the money amounts:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function retrieveCurrencies (codes: string[]) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const currencies = await pricingService.listCurrencies(
|
|
||||||
{
|
|
||||||
code: codes
|
|
||||||
},
|
|
||||||
{
|
|
||||||
select: ["symbol_native"]
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
// do something with the currencies or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
By default, only the first `15` records are retrieved. You can control pagination by specifying the `skip` and `take` properties of the `config` parameter:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function retrieveCurrencies (codes: string[], skip: number, take: number) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const currencies = await pricingService.listCurrencies(
|
|
||||||
{
|
|
||||||
code: codes
|
|
||||||
},
|
|
||||||
{
|
|
||||||
select: ["symbol_native"],
|
|
||||||
skip,
|
|
||||||
take
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
// do something with the currencies or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
+94
@@ -0,0 +1,94 @@
|
|||||||
|
---
|
||||||
|
displayed_sidebar: pricingReference
|
||||||
|
badge:
|
||||||
|
variant: orange
|
||||||
|
text: Beta
|
||||||
|
slug: /references/pricing/listCurrencies
|
||||||
|
sidebar_label: listCurrencies
|
||||||
|
---
|
||||||
|
|
||||||
|
import ParameterTypes from "@site/src/components/ParameterTypes"
|
||||||
|
|
||||||
|
# listCurrencies - Pricing Module Reference
|
||||||
|
|
||||||
|
This documentation provides a reference to the `listCurrencies` method. This belongs to the Pricing Module.
|
||||||
|
|
||||||
|
This method is used to retrieve a paginated list of currencies based on optional filters and configuration.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
To retrieve a list of currencies using their codes:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function retrieveCurrencies (codes: string[]) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const currencies = await pricingService.listCurrencies(
|
||||||
|
{
|
||||||
|
code: codes
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
// do something with the currencies or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
To specify attributes that should be retrieved within the money amounts:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function retrieveCurrencies (codes: string[]) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const currencies = await pricingService.listCurrencies(
|
||||||
|
{
|
||||||
|
code: codes
|
||||||
|
},
|
||||||
|
{
|
||||||
|
select: ["symbol_native"]
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// do something with the currencies or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
By default, only the first `15` records are retrieved. You can control pagination by specifying the `skip` and `take` properties of the `config` parameter:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function retrieveCurrencies (codes: string[], skip: number, take: number) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const currencies = await pricingService.listCurrencies(
|
||||||
|
{
|
||||||
|
code: codes
|
||||||
|
},
|
||||||
|
{
|
||||||
|
select: ["symbol_native"],
|
||||||
|
skip,
|
||||||
|
take
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// do something with the currencies or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"filters","type":"[`FilterableCurrencyProps`](../../interfaces/FilterableCurrencyProps.mdx)","description":"The filters to apply on the retrieved currencies.","optional":true,"defaultValue":"","children":[{"name":"$and","type":"([`FilterableCurrencyProps`](../../interfaces/FilterableCurrencyProps.mdx) \\| [`BaseFilterable`](../../interfaces/BaseFilterable.mdx)<[`FilterableCurrencyProps`](../../interfaces/FilterableCurrencyProps.mdx)\\>)[]","description":"An array of filters to apply on the entity, where each item in the array is joined with an \"and\" condition.","optional":true,"defaultValue":"","children":[]},{"name":"$or","type":"([`FilterableCurrencyProps`](../../interfaces/FilterableCurrencyProps.mdx) \\| [`BaseFilterable`](../../interfaces/BaseFilterable.mdx)<[`FilterableCurrencyProps`](../../interfaces/FilterableCurrencyProps.mdx)\\>)[]","description":"An array of filters to apply on the entity, where each item in the array is joined with an \"or\" condition.","optional":true,"defaultValue":"","children":[]},{"name":"code","type":"`string`[]","description":"The codes to filter the currencies by.","optional":true,"defaultValue":"","children":[]}]},{"name":"config","type":"[`FindConfig`](../../interfaces/FindConfig.mdx)<[`CurrencyDTO`](../../interfaces/CurrencyDTO.mdx)\\>","description":"The configurations determining how the currencies are retrieved. Its properties, such as `select` or `relations`, accept the attributes or relations associated with a currency.","optional":true,"defaultValue":"","children":[{"name":"order","type":"`object`","description":"An object used to specify how to sort the returned records. Its keys are the names of attributes of the entity, and a key's value can either be `ASC` to sort retrieved records in an ascending order, or `DESC` to sort retrieved records in a descending order.","optional":true,"defaultValue":"","children":[]},{"name":"relations","type":"`string`[]","description":"An array of strings, each being relation names of the entity to retrieve in the result.","optional":true,"defaultValue":"","children":[]},{"name":"select","type":"(`string` \\| keyof `Entity`)[]","description":"An array of strings, each being attribute names of the entity to retrieve in the result.","optional":true,"defaultValue":"","children":[]},{"name":"skip","type":"`number`","description":"A number indicating the number of records to skip before retrieving the results.","optional":true,"defaultValue":"","children":[]},{"name":"take","type":"`number`","description":"A number indicating the number of records to return in the result.","optional":true,"defaultValue":"","children":[]},{"name":"withDeleted","type":"`boolean`","description":"A boolean indicating whether deleted records should also be retrieved as part of the result. This only works if the entity extends the `SoftDeletableEntity` class.","optional":true,"defaultValue":"","children":[]}]},{"name":"sharedContext","type":"[`Context`](../../interfaces/Context.mdx)","description":"A context used to share resources, such as transaction manager, between the application and the module.","optional":true,"defaultValue":"","children":[{"name":"enableNestedTransactions","type":"`boolean`","description":"a boolean value indicating whether nested transactions are enabled.","optional":true,"defaultValue":"","children":[]},{"name":"isolationLevel","type":"`string`","description":"A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.","optional":true,"defaultValue":"","children":[]},{"name":"manager","type":"`TManager`","description":"An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.","optional":true,"defaultValue":"","children":[]},{"name":"transactionId","type":"`string`","description":"a string indicating the ID of the current transaction.","optional":true,"defaultValue":"","children":[]},{"name":"transactionManager","type":"`TManager`","description":"An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.","optional":true,"defaultValue":"","children":[]}]}]} />
|
||||||
|
|
||||||
|
## Returns
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"Promise","type":"`Promise`<[`CurrencyDTO`](../../interfaces/CurrencyDTO.mdx)[]\\>","optional":false,"defaultValue":"","description":"The list of currencies.","children":[{"name":"CurrencyDTO[]","type":"[`CurrencyDTO`](../../interfaces/CurrencyDTO.mdx)[]","optional":false,"defaultValue":"","description":"","children":[{"name":"CurrencyDTO","type":"`object`","description":"A currency's data.","optional":false,"defaultValue":"","children":[]}]}]}]} />
|
||||||
-159
@@ -1,159 +0,0 @@
|
|||||||
---
|
|
||||||
displayed_sidebar: pricingReference
|
|
||||||
badge:
|
|
||||||
variant: orange
|
|
||||||
text: Beta
|
|
||||||
slug: /references/pricing/listMoneyAmounts
|
|
||||||
sidebar_label: listMoneyAmounts
|
|
||||||
---
|
|
||||||
|
|
||||||
# listMoneyAmounts - Pricing Module Reference
|
|
||||||
|
|
||||||
This documentation provides a reference to the listMoneyAmounts method. This belongs to the Pricing Module.
|
|
||||||
|
|
||||||
This method is used to retrieve a paginated list of money amounts based on optional filters and configuration.
|
|
||||||
|
|
||||||
## Parameters
|
|
||||||
|
|
||||||
- `filters`: (optional) An object of type [FilterableMoneyAmountProps](../../interfaces/FilterableMoneyAmountProps.md) that is used to filter the retrieved money amounts. It accepts the following properties:
|
|
||||||
- `$and`: (optional) An array of filters to apply on the entity, where each item in the array is joined with an "and" condition.
|
|
||||||
- `$or`: (optional) An array of filters to apply on the entity, where each item in the array is joined with an "or" condition.
|
|
||||||
- `currency_code`: (optional) A string or an array of strings, each being a currency code to filter money amounts.
|
|
||||||
- `id`: (optional) An array of strings, each being an ID to filter money amounts.
|
|
||||||
- `config`: (optional) An object of type [FindConfig](../../interfaces/FindConfig.md) used to configure how the money amounts are retrieved. Its properties, such as `select` or `relations`, accept the attributes or relations associated with a money amount. It accepts the following properties:
|
|
||||||
- `order`: (optional) An object used to specify how to sort the returned records. Its keys are the names of attributes of the entity, and a key's value can either be `ASC` to sort retrieved records in an ascending order, or `DESC` to sort retrieved records in a descending order.
|
|
||||||
- `relations`: (optional) An array of strings, each being relation names of the entity to retrieve in the result.
|
|
||||||
- `select`: (optional) An array of strings, each being attribute names of the entity to retrieve in the result.
|
|
||||||
- `skip`: (optional) A number indicating the number of records to skip before retrieving the results.
|
|
||||||
- `take`: (optional) A number indicating the number of records to return in the result.
|
|
||||||
- `withDeleted`: (optional) A boolean indicating whether deleted records should also be retrieved as part of the result. This only works if the entity extends the `SoftDeletableEntity` class.
|
|
||||||
- `sharedContext`: (optional) An object of type [Context](../../interfaces/Context.md) used to share resources, such as transaction manager, between the application and the module. It accepts the following properties:
|
|
||||||
- `enableNestedTransactions`: (optional) a boolean value indicating whether nested transactions are enabled.
|
|
||||||
- `isolationLevel`: (optional) A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.
|
|
||||||
- `manager`: (optional) An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.
|
|
||||||
- `transactionId`: (optional) a string indicating the ID of the current transaction.
|
|
||||||
- `transactionManager`: (optional) An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.
|
|
||||||
|
|
||||||
## Returns
|
|
||||||
|
|
||||||
A promise that resolves to an array of objects of type [MoneyAmountDTO](../../interfaces/MoneyAmountDTO.md).
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary>
|
|
||||||
MoneyAmountDTO
|
|
||||||
</summary>
|
|
||||||
|
|
||||||
- `amount`: (optional) A number indicating the amount of this price.
|
|
||||||
- `currency`: (optional) An object of type [CurrencyDTO](../../interfaces/CurrencyDTO.md) that holds the details of the price's currency. Since this is a relation, it will only be retrieved if it's passed to the `relations` array of the find-configuration options. It accepts the following properties:
|
|
||||||
- `code`: a string indicating the code of the currency.
|
|
||||||
- `name`: (optional) a string indicating the name of the currency.
|
|
||||||
- `symbol`: (optional) a string indicating the symbol of the currency.
|
|
||||||
- `symbol_native`: (optional) a string indicating the symbol of the currecy in its native form. This is typically the symbol used when displaying a price.
|
|
||||||
- `currency_code`: (optional) A string that indicates the currency code of this price.
|
|
||||||
- `id`: A string that indicates the ID of the money amount. A money amount represents a price.
|
|
||||||
- `max_quantity`: (optional) A number that indicates the maximum quantity required to be purchased for this price to be applied.
|
|
||||||
- `min_quantity`: (optional) A number that indicates the minimum quantity required to be purchased for this price to be applied.
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
## Example
|
|
||||||
|
|
||||||
To retrieve a list of money amounts using their IDs:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function retrieveMoneyAmounts (moneyAmountIds: string[]) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const moneyAmounts = await pricingService.listMoneyAmounts(
|
|
||||||
{
|
|
||||||
id: moneyAmountIds
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
// do something with the money amounts or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
To specify relations that should be retrieved within the money amounts:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function retrieveMoneyAmounts (moneyAmountIds: string[]) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const moneyAmounts = await pricingService.listMoneyAmounts(
|
|
||||||
{
|
|
||||||
id: moneyAmountIds
|
|
||||||
},
|
|
||||||
{
|
|
||||||
relations: ["currency"]
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
// do something with the money amounts or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
By default, only the first `15` records are retrieved. You can control pagination by specifying the `skip` and `take` properties of the `config` parameter:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function retrieveMoneyAmounts (moneyAmountIds: string[], skip: number, take: number) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const moneyAmounts = await pricingService.listMoneyAmounts(
|
|
||||||
{
|
|
||||||
id: moneyAmountIds
|
|
||||||
},
|
|
||||||
{
|
|
||||||
relations: ["currency"],
|
|
||||||
skip,
|
|
||||||
take
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
// do something with the money amounts or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
You can also use the `$and` or `$or` properties of the `filter` parameter to use and/or conditions in your filters. For example:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function retrieveMoneyAmounts (moneyAmountIds: string[], currencyCode: string[], skip: number, take: number) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const moneyAmounts = await pricingService.listMoneyAmounts(
|
|
||||||
{
|
|
||||||
$and: [
|
|
||||||
{
|
|
||||||
id: moneyAmountIds
|
|
||||||
},
|
|
||||||
{
|
|
||||||
currency_code: currencyCode
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
relations: ["currency"],
|
|
||||||
skip,
|
|
||||||
take
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
// do something with the money amounts or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
+126
@@ -0,0 +1,126 @@
|
|||||||
|
---
|
||||||
|
displayed_sidebar: pricingReference
|
||||||
|
badge:
|
||||||
|
variant: orange
|
||||||
|
text: Beta
|
||||||
|
slug: /references/pricing/listMoneyAmounts
|
||||||
|
sidebar_label: listMoneyAmounts
|
||||||
|
---
|
||||||
|
|
||||||
|
import ParameterTypes from "@site/src/components/ParameterTypes"
|
||||||
|
|
||||||
|
# listMoneyAmounts - Pricing Module Reference
|
||||||
|
|
||||||
|
This documentation provides a reference to the `listMoneyAmounts` method. This belongs to the Pricing Module.
|
||||||
|
|
||||||
|
This method is used to retrieve a paginated list of money amounts based on optional filters and configuration.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
To retrieve a list of money amounts using their IDs:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function retrieveMoneyAmounts (moneyAmountIds: string[]) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const moneyAmounts = await pricingService.listMoneyAmounts(
|
||||||
|
{
|
||||||
|
id: moneyAmountIds
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// do something with the money amounts or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
To specify relations that should be retrieved within the money amounts:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function retrieveMoneyAmounts (moneyAmountIds: string[]) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const moneyAmounts = await pricingService.listMoneyAmounts(
|
||||||
|
{
|
||||||
|
id: moneyAmountIds
|
||||||
|
},
|
||||||
|
{
|
||||||
|
relations: ["currency"]
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// do something with the money amounts or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
By default, only the first `15` records are retrieved. You can control pagination by specifying the `skip` and `take` properties of the `config` parameter:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function retrieveMoneyAmounts (moneyAmountIds: string[], skip: number, take: number) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const moneyAmounts = await pricingService.listMoneyAmounts(
|
||||||
|
{
|
||||||
|
id: moneyAmountIds
|
||||||
|
},
|
||||||
|
{
|
||||||
|
relations: ["currency"],
|
||||||
|
skip,
|
||||||
|
take
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// do something with the money amounts or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
You can also use the `$and` or `$or` properties of the `filter` parameter to use and/or conditions in your filters. For example:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function retrieveMoneyAmounts (moneyAmountIds: string[], currencyCode: string[], skip: number, take: number) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const moneyAmounts = await pricingService.listMoneyAmounts(
|
||||||
|
{
|
||||||
|
$and: [
|
||||||
|
{
|
||||||
|
id: moneyAmountIds
|
||||||
|
},
|
||||||
|
{
|
||||||
|
currency_code: currencyCode
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
relations: ["currency"],
|
||||||
|
skip,
|
||||||
|
take
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// do something with the money amounts or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"filters","type":"[`FilterableMoneyAmountProps`](../../interfaces/FilterableMoneyAmountProps.mdx)","description":"The filtes to apply on the retrieved money amounts.","optional":true,"defaultValue":"","children":[{"name":"$and","type":"([`FilterableMoneyAmountProps`](../../interfaces/FilterableMoneyAmountProps.mdx) \\| [`BaseFilterable`](../../interfaces/BaseFilterable.mdx)<[`FilterableMoneyAmountProps`](../../interfaces/FilterableMoneyAmountProps.mdx)\\>)[]","description":"An array of filters to apply on the entity, where each item in the array is joined with an \"and\" condition.","optional":true,"defaultValue":"","children":[]},{"name":"$or","type":"([`FilterableMoneyAmountProps`](../../interfaces/FilterableMoneyAmountProps.mdx) \\| [`BaseFilterable`](../../interfaces/BaseFilterable.mdx)<[`FilterableMoneyAmountProps`](../../interfaces/FilterableMoneyAmountProps.mdx)\\>)[]","description":"An array of filters to apply on the entity, where each item in the array is joined with an \"or\" condition.","optional":true,"defaultValue":"","children":[]},{"name":"currency_code","type":"`string` \\| `string`[]","description":"Currency codes to filter money amounts by.","optional":true,"defaultValue":"","children":[]},{"name":"id","type":"`string`[]","description":"IDs to filter money amounts by.","optional":true,"defaultValue":"","children":[]}]},{"name":"config","type":"[`FindConfig`](../../interfaces/FindConfig.mdx)<[`MoneyAmountDTO`](../../interfaces/MoneyAmountDTO.mdx)\\>","description":"The configurations determining how the money amounts are retrieved. Its properties, such as `select` or `relations`, accept the attributes or relations associated with a money amount.","optional":true,"defaultValue":"","children":[{"name":"order","type":"`object`","description":"An object used to specify how to sort the returned records. Its keys are the names of attributes of the entity, and a key's value can either be `ASC` to sort retrieved records in an ascending order, or `DESC` to sort retrieved records in a descending order.","optional":true,"defaultValue":"","children":[]},{"name":"relations","type":"`string`[]","description":"An array of strings, each being relation names of the entity to retrieve in the result.","optional":true,"defaultValue":"","children":[]},{"name":"select","type":"(`string` \\| keyof `Entity`)[]","description":"An array of strings, each being attribute names of the entity to retrieve in the result.","optional":true,"defaultValue":"","children":[]},{"name":"skip","type":"`number`","description":"A number indicating the number of records to skip before retrieving the results.","optional":true,"defaultValue":"","children":[]},{"name":"take","type":"`number`","description":"A number indicating the number of records to return in the result.","optional":true,"defaultValue":"","children":[]},{"name":"withDeleted","type":"`boolean`","description":"A boolean indicating whether deleted records should also be retrieved as part of the result. This only works if the entity extends the `SoftDeletableEntity` class.","optional":true,"defaultValue":"","children":[]}]},{"name":"sharedContext","type":"[`Context`](../../interfaces/Context.mdx)","description":"A context used to share resources, such as transaction manager, between the application and the module.","optional":true,"defaultValue":"","children":[{"name":"enableNestedTransactions","type":"`boolean`","description":"a boolean value indicating whether nested transactions are enabled.","optional":true,"defaultValue":"","children":[]},{"name":"isolationLevel","type":"`string`","description":"A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.","optional":true,"defaultValue":"","children":[]},{"name":"manager","type":"`TManager`","description":"An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.","optional":true,"defaultValue":"","children":[]},{"name":"transactionId","type":"`string`","description":"a string indicating the ID of the current transaction.","optional":true,"defaultValue":"","children":[]},{"name":"transactionManager","type":"`TManager`","description":"An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.","optional":true,"defaultValue":"","children":[]}]}]} />
|
||||||
|
|
||||||
|
## Returns
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"Promise","type":"`Promise`<[`MoneyAmountDTO`](../../interfaces/MoneyAmountDTO.mdx)[]\\>","optional":false,"defaultValue":"","description":"The list of money amounts.","children":[{"name":"MoneyAmountDTO[]","type":"[`MoneyAmountDTO`](../../interfaces/MoneyAmountDTO.mdx)[]","optional":false,"defaultValue":"","description":"","children":[{"name":"MoneyAmountDTO","type":"`object`","description":"A money amount's data. A money amount represents a price.","optional":false,"defaultValue":"","children":[]}]}]}]} />
|
||||||
-167
@@ -1,167 +0,0 @@
|
|||||||
---
|
|
||||||
displayed_sidebar: pricingReference
|
|
||||||
badge:
|
|
||||||
variant: orange
|
|
||||||
text: Beta
|
|
||||||
slug: /references/pricing/listPriceRules
|
|
||||||
sidebar_label: listPriceRules
|
|
||||||
---
|
|
||||||
|
|
||||||
# listPriceRules - Pricing Module Reference
|
|
||||||
|
|
||||||
This documentation provides a reference to the listPriceRules method. This belongs to the Pricing Module.
|
|
||||||
|
|
||||||
This method is used to retrieve a paginated list of price rules based on optional filters and configuration.
|
|
||||||
|
|
||||||
## Parameters
|
|
||||||
|
|
||||||
- `filters`: (optional) An object of type [FilterablePriceRuleProps](../../interfaces/FilterablePriceRuleProps.md) that is used to filter the retrieved price rules. It accepts the following properties:
|
|
||||||
- `$and`: (optional) An array of filters to apply on the entity, where each item in the array is joined with an "and" condition.
|
|
||||||
- `$or`: (optional) An array of filters to apply on the entity, where each item in the array is joined with an "or" condition.
|
|
||||||
- `id`: (optional) An array of strings, each indicating an ID to filter price rules.
|
|
||||||
- `name`: (optional) An array of strings, each indicating a name to filter price rules.
|
|
||||||
- `price_set_id`: (optional) An array of strings, each indicating a price set ID to filter price rules.
|
|
||||||
- `rule_type_id`: (optional) An array of strings, each indicating a rule type ID to filter rule types.
|
|
||||||
- `config`: (optional) An object of type [FindConfig](../../interfaces/FindConfig.md) used to configure how the price rule is retrieved. Its properties, such as `select` or `relations`, accept the attributes or relations associated with a price rule. It accepts the following properties:
|
|
||||||
- `order`: (optional) An object used to specify how to sort the returned records. Its keys are the names of attributes of the entity, and a key's value can either be `ASC` to sort retrieved records in an ascending order, or `DESC` to sort retrieved records in a descending order.
|
|
||||||
- `relations`: (optional) An array of strings, each being relation names of the entity to retrieve in the result.
|
|
||||||
- `select`: (optional) An array of strings, each being attribute names of the entity to retrieve in the result.
|
|
||||||
- `skip`: (optional) A number indicating the number of records to skip before retrieving the results.
|
|
||||||
- `take`: (optional) A number indicating the number of records to return in the result.
|
|
||||||
- `withDeleted`: (optional) A boolean indicating whether deleted records should also be retrieved as part of the result. This only works if the entity extends the `SoftDeletableEntity` class.
|
|
||||||
- `sharedContext`: (optional) An object of type [Context](../../interfaces/Context.md) used to share resources, such as transaction manager, between the application and the module. It accepts the following properties:
|
|
||||||
- `enableNestedTransactions`: (optional) a boolean value indicating whether nested transactions are enabled.
|
|
||||||
- `isolationLevel`: (optional) A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.
|
|
||||||
- `manager`: (optional) An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.
|
|
||||||
- `transactionId`: (optional) a string indicating the ID of the current transaction.
|
|
||||||
- `transactionManager`: (optional) An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.
|
|
||||||
|
|
||||||
## Returns
|
|
||||||
|
|
||||||
A promise that resolves to an array of objects of type [PriceRuleDTO](../../interfaces/PriceRuleDTO.md).
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary>
|
|
||||||
PriceRuleDTO
|
|
||||||
</summary>
|
|
||||||
|
|
||||||
- `id`: A string indicating the ID of the price rule.
|
|
||||||
- `is_dynamic`: A boolean indicating whether the price rule is dynamic.
|
|
||||||
- `price_list_id`: A string indicating the ID of the associated price list.
|
|
||||||
- `price_set`: An object of type [PriceSetDTO](../../interfaces/PriceSetDTO.md) that holds the data of the associated price set. It may only be available if the relation `price_set` is expanded. It accepts the following properties:
|
|
||||||
- `id`: A string indicating the ID of the price set.
|
|
||||||
- `money_amounts`: (optional) An array of objects of type [MoneyAmountDTO](../../interfaces/MoneyAmountDTO.md), which holds the prices that belong to this price set. Its items accept the following properties:
|
|
||||||
- `amount`: (optional) A number indicating the amount of this price.
|
|
||||||
- `currency`: (optional) An object of type [CurrencyDTO](../../interfaces/CurrencyDTO.md) that holds the details of the price's currency. Since this is a relation, it will only be retrieved if it's passed to the `relations` array of the find-configuration options.
|
|
||||||
- `currency_code`: (optional) A string that indicates the currency code of this price.
|
|
||||||
- `id`: A string that indicates the ID of the money amount. A money amount represents a price.
|
|
||||||
- `max_quantity`: (optional) A number that indicates the maximum quantity required to be purchased for this price to be applied.
|
|
||||||
- `min_quantity`: (optional) A number that indicates the minimum quantity required to be purchased for this price to be applied.
|
|
||||||
- `rule_types`: (optional) An array of objects of type [RuleTypeDTO](../../interfaces/RuleTypeDTO.md), which holds the rule types applied on this price set. Its items accept the following properties:
|
|
||||||
- `default_priority`: A number indicating the priority of the rule type. This is useful when calculating the price of a price set, and multiple rules satisfy the provided context. The higher the value, the higher the priority of the rule type.
|
|
||||||
- `id`: A string indicating the ID of the rule type.
|
|
||||||
- `name`: A string indicating the display name of the rule type.
|
|
||||||
- `rule_attribute`: A string indicating a unique name used to later identify the rule_attribute. For example, it can be used in the `context` parameter of the `calculatePrices` method to specify a rule for calculating the price.
|
|
||||||
- `price_set_id`: A string indicating the ID of the associated price set.
|
|
||||||
- `price_set_money_amount_id`: A string indicating the ID of the associated price set money amount.
|
|
||||||
- `priority`: A number indicating the priority of the price rule in comparison to other applicable price rules.
|
|
||||||
- `rule_type`: An object of type [RuleTypeDTO](../../interfaces/RuleTypeDTO.md) that holds the data of the associated rule type. It may only be available if the relation `rule_type` is expanded. It accepts the following properties:
|
|
||||||
- `default_priority`: A number indicating the priority of the rule type. This is useful when calculating the price of a price set, and multiple rules satisfy the provided context. The higher the value, the higher the priority of the rule type.
|
|
||||||
- `id`: A string indicating the ID of the rule type.
|
|
||||||
- `name`: A string indicating the display name of the rule type.
|
|
||||||
- `rule_attribute`: A string indicating a unique name used to later identify the rule_attribute. For example, it can be used in the `context` parameter of the `calculatePrices` method to specify a rule for calculating the price.
|
|
||||||
- `rule_type_id`: A string indicating the ID of the associated rule type.
|
|
||||||
- `value`: A string indicating the value of the price rule.
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
## Example
|
|
||||||
|
|
||||||
To retrieve a list of price rules using their IDs:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function retrievePriceRules (id: string) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const priceRules = await pricingService.listPriceRules({
|
|
||||||
id: [id]
|
|
||||||
})
|
|
||||||
|
|
||||||
// do something with the price rules or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
To specify relations that should be retrieved within the price rules:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function retrievePriceRules (id: string) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const priceRules = await pricingService.listPriceRules({
|
|
||||||
id: [id],
|
|
||||||
}, {
|
|
||||||
relations: ["price_set"]
|
|
||||||
})
|
|
||||||
|
|
||||||
// do something with the price rules or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
By default, only the first `15` records are retrieved. You can control pagination by specifying the `skip` and `take` properties of the `config` parameter:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function retrievePriceRules (id: string, skip: number, take: number) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const priceRules = await pricingService.listPriceRules({
|
|
||||||
id: [id],
|
|
||||||
}, {
|
|
||||||
relations: ["price_set"],
|
|
||||||
skip,
|
|
||||||
take
|
|
||||||
})
|
|
||||||
|
|
||||||
// do something with the price rules or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
You can also use the `$and` or `$or` properties of the `filter` parameter to use and/or conditions in your filters. For example:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function retrievePriceRules (ids: string[], name: string[], skip: number, take: number) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const priceRules = await pricingService.listPriceRules({
|
|
||||||
$and: [
|
|
||||||
{
|
|
||||||
id: ids
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}, {
|
|
||||||
relations: ["price_set"],
|
|
||||||
skip,
|
|
||||||
take
|
|
||||||
})
|
|
||||||
|
|
||||||
// do something with the price rules or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
+115
@@ -0,0 +1,115 @@
|
|||||||
|
---
|
||||||
|
displayed_sidebar: pricingReference
|
||||||
|
badge:
|
||||||
|
variant: orange
|
||||||
|
text: Beta
|
||||||
|
slug: /references/pricing/listPriceRules
|
||||||
|
sidebar_label: listPriceRules
|
||||||
|
---
|
||||||
|
|
||||||
|
import ParameterTypes from "@site/src/components/ParameterTypes"
|
||||||
|
|
||||||
|
# listPriceRules - Pricing Module Reference
|
||||||
|
|
||||||
|
This documentation provides a reference to the `listPriceRules` method. This belongs to the Pricing Module.
|
||||||
|
|
||||||
|
This method is used to retrieve a paginated list of price rules based on optional filters and configuration.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
To retrieve a list of price rules using their IDs:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function retrievePriceRules (id: string) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const priceRules = await pricingService.listPriceRules({
|
||||||
|
id: [id]
|
||||||
|
})
|
||||||
|
|
||||||
|
// do something with the price rules or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
To specify relations that should be retrieved within the price rules:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function retrievePriceRules (id: string) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const priceRules = await pricingService.listPriceRules({
|
||||||
|
id: [id],
|
||||||
|
}, {
|
||||||
|
relations: ["price_set"]
|
||||||
|
})
|
||||||
|
|
||||||
|
// do something with the price rules or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
By default, only the first `15` records are retrieved. You can control pagination by specifying the `skip` and `take` properties of the `config` parameter:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function retrievePriceRules (id: string, skip: number, take: number) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const priceRules = await pricingService.listPriceRules({
|
||||||
|
id: [id],
|
||||||
|
}, {
|
||||||
|
relations: ["price_set"],
|
||||||
|
skip,
|
||||||
|
take
|
||||||
|
})
|
||||||
|
|
||||||
|
// do something with the price rules or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
You can also use the `$and` or `$or` properties of the `filter` parameter to use and/or conditions in your filters. For example:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function retrievePriceRules (ids: string[], name: string[], skip: number, take: number) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const priceRules = await pricingService.listPriceRules({
|
||||||
|
$and: [
|
||||||
|
{
|
||||||
|
id: ids
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}, {
|
||||||
|
relations: ["price_set"],
|
||||||
|
skip,
|
||||||
|
take
|
||||||
|
})
|
||||||
|
|
||||||
|
// do something with the price rules or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"filters","type":"[`FilterablePriceRuleProps`](../../interfaces/FilterablePriceRuleProps.mdx)","description":"The filters to apply on the retrieved price rules.","optional":true,"defaultValue":"","children":[{"name":"$and","type":"([`FilterablePriceRuleProps`](../../interfaces/FilterablePriceRuleProps.mdx) \\| [`BaseFilterable`](../../interfaces/BaseFilterable.mdx)<[`FilterablePriceRuleProps`](../../interfaces/FilterablePriceRuleProps.mdx)\\>)[]","description":"An array of filters to apply on the entity, where each item in the array is joined with an \"and\" condition.","optional":true,"defaultValue":"","children":[]},{"name":"$or","type":"([`FilterablePriceRuleProps`](../../interfaces/FilterablePriceRuleProps.mdx) \\| [`BaseFilterable`](../../interfaces/BaseFilterable.mdx)<[`FilterablePriceRuleProps`](../../interfaces/FilterablePriceRuleProps.mdx)\\>)[]","description":"An array of filters to apply on the entity, where each item in the array is joined with an \"or\" condition.","optional":true,"defaultValue":"","children":[]},{"name":"id","type":"`string`[]","description":"The IDs to filter price rules by.","optional":true,"defaultValue":"","children":[]},{"name":"name","type":"`string`[]","description":"The names to filter price rules by.","optional":true,"defaultValue":"","children":[]},{"name":"price_set_id","type":"`string`[]","description":"The IDs to filter the price rule's associated price set.","optional":true,"defaultValue":"","children":[]},{"name":"rule_type_id","type":"`string`[]","description":"The IDs to filter the price rule's associated rule type.","optional":true,"defaultValue":"","children":[]}]},{"name":"config","type":"[`FindConfig`](../../interfaces/FindConfig.mdx)<[`PriceRuleDTO`](../../interfaces/PriceRuleDTO.mdx)\\>","description":"The configurations determining how the price rule is retrieved. Its properties, such as `select` or `relations`, accept the attributes or relations associated with a price rule.","optional":true,"defaultValue":"","children":[{"name":"order","type":"`object`","description":"An object used to specify how to sort the returned records. Its keys are the names of attributes of the entity, and a key's value can either be `ASC` to sort retrieved records in an ascending order, or `DESC` to sort retrieved records in a descending order.","optional":true,"defaultValue":"","children":[]},{"name":"relations","type":"`string`[]","description":"An array of strings, each being relation names of the entity to retrieve in the result.","optional":true,"defaultValue":"","children":[]},{"name":"select","type":"(`string` \\| keyof `Entity`)[]","description":"An array of strings, each being attribute names of the entity to retrieve in the result.","optional":true,"defaultValue":"","children":[]},{"name":"skip","type":"`number`","description":"A number indicating the number of records to skip before retrieving the results.","optional":true,"defaultValue":"","children":[]},{"name":"take","type":"`number`","description":"A number indicating the number of records to return in the result.","optional":true,"defaultValue":"","children":[]},{"name":"withDeleted","type":"`boolean`","description":"A boolean indicating whether deleted records should also be retrieved as part of the result. This only works if the entity extends the `SoftDeletableEntity` class.","optional":true,"defaultValue":"","children":[]}]},{"name":"sharedContext","type":"[`Context`](../../interfaces/Context.mdx)","description":"A context used to share resources, such as transaction manager, between the application and the module.","optional":true,"defaultValue":"","children":[{"name":"enableNestedTransactions","type":"`boolean`","description":"a boolean value indicating whether nested transactions are enabled.","optional":true,"defaultValue":"","children":[]},{"name":"isolationLevel","type":"`string`","description":"A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.","optional":true,"defaultValue":"","children":[]},{"name":"manager","type":"`TManager`","description":"An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.","optional":true,"defaultValue":"","children":[]},{"name":"transactionId","type":"`string`","description":"a string indicating the ID of the current transaction.","optional":true,"defaultValue":"","children":[]},{"name":"transactionManager","type":"`TManager`","description":"An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.","optional":true,"defaultValue":"","children":[]}]}]} />
|
||||||
|
|
||||||
|
## Returns
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"Promise","type":"`Promise`<[`PriceRuleDTO`](../../interfaces/PriceRuleDTO.mdx)[]\\>","optional":false,"defaultValue":"","description":"The list of price rules.","children":[{"name":"PriceRuleDTO[]","type":"[`PriceRuleDTO`](../../interfaces/PriceRuleDTO.mdx)[]","optional":false,"defaultValue":"","description":"","children":[{"name":"PriceRuleDTO","type":"`object`","description":"A price rule's data.","optional":false,"defaultValue":"","children":[]}]}]}]} />
|
||||||
-161
@@ -1,161 +0,0 @@
|
|||||||
---
|
|
||||||
displayed_sidebar: pricingReference
|
|
||||||
badge:
|
|
||||||
variant: orange
|
|
||||||
text: Beta
|
|
||||||
slug: /references/pricing/listPriceSetMoneyAmountRules
|
|
||||||
sidebar_label: listPriceSetMoneyAmountRules
|
|
||||||
---
|
|
||||||
|
|
||||||
# listPriceSetMoneyAmountRules - Pricing Module Reference
|
|
||||||
|
|
||||||
This documentation provides a reference to the listPriceSetMoneyAmountRules method. This belongs to the Pricing Module.
|
|
||||||
|
|
||||||
This method is used to retrieve a paginated list of price set money amount rules based on optional filters and configuration.
|
|
||||||
|
|
||||||
## Parameters
|
|
||||||
|
|
||||||
- `filters`: (optional) An object of type [FilterablePriceSetMoneyAmountRulesProps](../../interfaces/FilterablePriceSetMoneyAmountRulesProps.md) that is used to filter the retrieved price set money amount rules. It accepts the following properties:
|
|
||||||
- `$and`: (optional) An array of filters to apply on the entity, where each item in the array is joined with an "and" condition.
|
|
||||||
- `$or`: (optional) An array of filters to apply on the entity, where each item in the array is joined with an "or" condition.
|
|
||||||
- `id`: (optional) An array of strings, each string indicating an ID to filter the price set money amount rules.
|
|
||||||
- `price_set_money_amount_id`: (optional) an array of strings, each string indicating the ID of a price set money amount to filter the price set money amount rules.
|
|
||||||
- `rule_type_id`: (optional) An array of strings, each string indicating the ID of a rule type to filter the price set money amount rules.
|
|
||||||
- `value`: (optional) an array of strings, each string indicating a value to filter the price set money amount rules.
|
|
||||||
- `config`: (optional) An object of type [FindConfig](../../interfaces/FindConfig.md) used to configure how the price set money amount rules are retrieved. Its properties, such as `select` or `relations`, accept the attributes or relations associated with a price set money amount rule. It accepts the following properties:
|
|
||||||
- `order`: (optional) An object used to specify how to sort the returned records. Its keys are the names of attributes of the entity, and a key's value can either be `ASC` to sort retrieved records in an ascending order, or `DESC` to sort retrieved records in a descending order.
|
|
||||||
- `relations`: (optional) An array of strings, each being relation names of the entity to retrieve in the result.
|
|
||||||
- `select`: (optional) An array of strings, each being attribute names of the entity to retrieve in the result.
|
|
||||||
- `skip`: (optional) A number indicating the number of records to skip before retrieving the results.
|
|
||||||
- `take`: (optional) A number indicating the number of records to return in the result.
|
|
||||||
- `withDeleted`: (optional) A boolean indicating whether deleted records should also be retrieved as part of the result. This only works if the entity extends the `SoftDeletableEntity` class.
|
|
||||||
- `sharedContext`: (optional) An object of type [Context](../../interfaces/Context.md) used to share resources, such as transaction manager, between the application and the module. It accepts the following properties:
|
|
||||||
- `enableNestedTransactions`: (optional) a boolean value indicating whether nested transactions are enabled.
|
|
||||||
- `isolationLevel`: (optional) A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.
|
|
||||||
- `manager`: (optional) An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.
|
|
||||||
- `transactionId`: (optional) a string indicating the ID of the current transaction.
|
|
||||||
- `transactionManager`: (optional) An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.
|
|
||||||
|
|
||||||
## Returns
|
|
||||||
|
|
||||||
A promise that resolves to an array of objects of type [PriceSetMoneyAmountRulesDTO](../../interfaces/PriceSetMoneyAmountRulesDTO.md).
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary>
|
|
||||||
PriceSetMoneyAmountRulesDTO
|
|
||||||
</summary>
|
|
||||||
|
|
||||||
- `id`: A string indicating the ID of the price set money amount.
|
|
||||||
- `price_set_money_amount`: an object of type [PriceSetMoneyAmountDTO](../../interfaces/PriceSetMoneyAmountDTO.md) holding the data of the associated price set money amount. It accepts the following properties:
|
|
||||||
- `id`: a string indicating the ID of a price set money amount.
|
|
||||||
- `money_amount`: (optional) an object of type [MoneyAmountDTO](../../interfaces/MoneyAmountDTO.md) holding the data of the associated money amount. It accepts the following properties:
|
|
||||||
- `amount`: (optional) A number indicating the amount of this price.
|
|
||||||
- `currency`: (optional) An object of type [CurrencyDTO](../../interfaces/CurrencyDTO.md) that holds the details of the price's currency. Since this is a relation, it will only be retrieved if it's passed to the `relations` array of the find-configuration options.
|
|
||||||
- `currency_code`: (optional) A string that indicates the currency code of this price.
|
|
||||||
- `id`: A string that indicates the ID of the money amount. A money amount represents a price.
|
|
||||||
- `max_quantity`: (optional) A number that indicates the maximum quantity required to be purchased for this price to be applied.
|
|
||||||
- `min_quantity`: (optional) A number that indicates the minimum quantity required to be purchased for this price to be applied.
|
|
||||||
- `price_set`: (optional) an object of type [PriceSetDTO](../../interfaces/PriceSetDTO.md) holding the data of the associated price set. It accepts the following properties:
|
|
||||||
- `id`: A string indicating the ID of the price set.
|
|
||||||
- `money_amounts`: (optional) An array of objects of type [MoneyAmountDTO](../../interfaces/MoneyAmountDTO.md), which holds the prices that belong to this price set.
|
|
||||||
- `rule_types`: (optional) An array of objects of type [RuleTypeDTO](../../interfaces/RuleTypeDTO.md), which holds the rule types applied on this price set.
|
|
||||||
- `title`: (optional) a string indicating the title of the price set money amount.
|
|
||||||
- `rule_type`: an object of type [RuleTypeDTO](../../interfaces/RuleTypeDTO.md) holding the data of the associated rule type. It accepts the following properties:
|
|
||||||
- `default_priority`: A number indicating the priority of the rule type. This is useful when calculating the price of a price set, and multiple rules satisfy the provided context. The higher the value, the higher the priority of the rule type.
|
|
||||||
- `id`: A string indicating the ID of the rule type.
|
|
||||||
- `name`: A string indicating the display name of the rule type.
|
|
||||||
- `rule_attribute`: A string indicating a unique name used to later identify the rule_attribute. For example, it can be used in the `context` parameter of the `calculatePrices` method to specify a rule for calculating the price.
|
|
||||||
- `value`: a string indicating the value of the price set money amount rule.
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
## Example
|
|
||||||
|
|
||||||
To retrieve a list of price set money amount rules using their IDs:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function retrievePriceSetMoneyAmountRules (id: string) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const priceSetMoneyAmountRules = await pricingService.listPriceSetMoneyAmountRules({
|
|
||||||
id: [id]
|
|
||||||
})
|
|
||||||
|
|
||||||
// do something with the price set money amount rules or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
To specify relations that should be retrieved within the price set money amount rules:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function retrievePriceSetMoneyAmountRules (id: string) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const priceSetMoneyAmountRules = await pricingService.listPriceSetMoneyAmountRules({
|
|
||||||
id: [id]
|
|
||||||
}, {
|
|
||||||
relations: ["price_set_money_amount"]
|
|
||||||
})
|
|
||||||
|
|
||||||
// do something with the price set money amount rules or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
By default, only the first `15` records are retrieved. You can control pagination by specifying the `skip` and `take` properties of the `config` parameter:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function retrievePriceSetMoneyAmountRules (id: string, skip: number, take: number) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const priceSetMoneyAmountRules = await pricingService.listPriceSetMoneyAmountRules({
|
|
||||||
id: [id]
|
|
||||||
}, {
|
|
||||||
relations: ["price_set_money_amount"],
|
|
||||||
skip,
|
|
||||||
take
|
|
||||||
})
|
|
||||||
|
|
||||||
// do something with the price set money amount rules or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
You can also use the `$and` or `$or` properties of the `filter` parameter to use and/or conditions in your filters. For example:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function retrievePriceSetMoneyAmountRules (ids: string[], ruleTypeId: string[], skip: number, take: number) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const priceSetMoneyAmountRules = await pricingService.listPriceSetMoneyAmountRules({
|
|
||||||
$and: [
|
|
||||||
{
|
|
||||||
id: ids
|
|
||||||
},
|
|
||||||
{
|
|
||||||
rule_type_id: ruleTypeId
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}, {
|
|
||||||
relations: ["price_set_money_amount"],
|
|
||||||
skip,
|
|
||||||
take
|
|
||||||
})
|
|
||||||
|
|
||||||
// do something with the price set money amount rules or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
+115
@@ -0,0 +1,115 @@
|
|||||||
|
---
|
||||||
|
displayed_sidebar: pricingReference
|
||||||
|
badge:
|
||||||
|
variant: orange
|
||||||
|
text: Beta
|
||||||
|
slug: /references/pricing/listPriceSetMoneyAmountRules
|
||||||
|
sidebar_label: listPriceSetMoneyAmountRules
|
||||||
|
---
|
||||||
|
|
||||||
|
import ParameterTypes from "@site/src/components/ParameterTypes"
|
||||||
|
|
||||||
|
# listPriceSetMoneyAmountRules - Pricing Module Reference
|
||||||
|
|
||||||
|
This documentation provides a reference to the `listPriceSetMoneyAmountRules` method. This belongs to the Pricing Module.
|
||||||
|
|
||||||
|
This method is used to retrieve a paginated list of price set money amount rules based on optional filters and configuration.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
To retrieve a list of price set money amount rules using their IDs:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function retrievePriceSetMoneyAmountRules (id: string) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const priceSetMoneyAmountRules = await pricingService.listPriceSetMoneyAmountRules({
|
||||||
|
id: [id]
|
||||||
|
})
|
||||||
|
|
||||||
|
// do something with the price set money amount rules or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
To specify relations that should be retrieved within the price set money amount rules:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function retrievePriceSetMoneyAmountRules (id: string) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const priceSetMoneyAmountRules = await pricingService.listPriceSetMoneyAmountRules({
|
||||||
|
id: [id]
|
||||||
|
}, {
|
||||||
|
relations: ["price_set_money_amount"]
|
||||||
|
})
|
||||||
|
|
||||||
|
// do something with the price set money amount rules or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
By default, only the first `15` records are retrieved. You can control pagination by specifying the `skip` and `take` properties of the `config` parameter:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function retrievePriceSetMoneyAmountRules (id: string, skip: number, take: number) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const priceSetMoneyAmountRules = await pricingService.listPriceSetMoneyAmountRules({
|
||||||
|
id: [id]
|
||||||
|
}, {
|
||||||
|
relations: ["price_set_money_amount"],
|
||||||
|
skip,
|
||||||
|
take
|
||||||
|
})
|
||||||
|
|
||||||
|
// do something with the price set money amount rules or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
You can also use the `$and` or `$or` properties of the `filter` parameter to use and/or conditions in your filters. For example:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function retrievePriceSetMoneyAmountRules (ids: string[], ruleTypeId: string[], skip: number, take: number) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const priceSetMoneyAmountRules = await pricingService.listPriceSetMoneyAmountRules({
|
||||||
|
$and: [
|
||||||
|
{
|
||||||
|
id: ids
|
||||||
|
},
|
||||||
|
{
|
||||||
|
rule_type_id: ruleTypeId
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}, {
|
||||||
|
relations: ["price_set_money_amount"],
|
||||||
|
skip,
|
||||||
|
take
|
||||||
|
})
|
||||||
|
|
||||||
|
// do something with the price set money amount rules or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"filters","type":"[`FilterablePriceSetMoneyAmountRulesProps`](../../interfaces/FilterablePriceSetMoneyAmountRulesProps.mdx)","description":"The filters to apply on the retrieved price set money amount rules.","optional":true,"defaultValue":"","children":[{"name":"$and","type":"([`FilterablePriceSetMoneyAmountRulesProps`](../../interfaces/FilterablePriceSetMoneyAmountRulesProps.mdx) \\| [`BaseFilterable`](../../interfaces/BaseFilterable.mdx)<[`FilterablePriceSetMoneyAmountRulesProps`](../../interfaces/FilterablePriceSetMoneyAmountRulesProps.mdx)\\>)[]","description":"An array of filters to apply on the entity, where each item in the array is joined with an \"and\" condition.","optional":true,"defaultValue":"","children":[]},{"name":"$or","type":"([`FilterablePriceSetMoneyAmountRulesProps`](../../interfaces/FilterablePriceSetMoneyAmountRulesProps.mdx) \\| [`BaseFilterable`](../../interfaces/BaseFilterable.mdx)<[`FilterablePriceSetMoneyAmountRulesProps`](../../interfaces/FilterablePriceSetMoneyAmountRulesProps.mdx)\\>)[]","description":"An array of filters to apply on the entity, where each item in the array is joined with an \"or\" condition.","optional":true,"defaultValue":"","children":[]},{"name":"id","type":"`string`[]","description":"The ID to filter price set money amount rules by.","optional":true,"defaultValue":"","children":[]},{"name":"price_set_money_amount_id","type":"`string`[]","description":"The IDs to filter the price set money amount rule's associated price set money amount.","optional":true,"defaultValue":"","children":[]},{"name":"rule_type_id","type":"`string`[]","description":"The IDs to filter the price set money amount rule's associated rule type.","optional":true,"defaultValue":"","children":[]},{"name":"value","type":"`string`[]","description":"The value to filter price set money amount rules by.","optional":true,"defaultValue":"","children":[]}]},{"name":"config","type":"[`FindConfig`](../../interfaces/FindConfig.mdx)<[`PriceSetMoneyAmountRulesDTO`](../../interfaces/PriceSetMoneyAmountRulesDTO.mdx)\\>","description":"The configurations determining how the price set money amount rules are retrieved. Its properties, such as `select` or `relations`, accept the attributes or relations associated with a price set money amount rule.","optional":true,"defaultValue":"","children":[{"name":"order","type":"`object`","description":"An object used to specify how to sort the returned records. Its keys are the names of attributes of the entity, and a key's value can either be `ASC` to sort retrieved records in an ascending order, or `DESC` to sort retrieved records in a descending order.","optional":true,"defaultValue":"","children":[]},{"name":"relations","type":"`string`[]","description":"An array of strings, each being relation names of the entity to retrieve in the result.","optional":true,"defaultValue":"","children":[]},{"name":"select","type":"(`string` \\| keyof `Entity`)[]","description":"An array of strings, each being attribute names of the entity to retrieve in the result.","optional":true,"defaultValue":"","children":[]},{"name":"skip","type":"`number`","description":"A number indicating the number of records to skip before retrieving the results.","optional":true,"defaultValue":"","children":[]},{"name":"take","type":"`number`","description":"A number indicating the number of records to return in the result.","optional":true,"defaultValue":"","children":[]},{"name":"withDeleted","type":"`boolean`","description":"A boolean indicating whether deleted records should also be retrieved as part of the result. This only works if the entity extends the `SoftDeletableEntity` class.","optional":true,"defaultValue":"","children":[]}]},{"name":"sharedContext","type":"[`Context`](../../interfaces/Context.mdx)","description":"A context used to share resources, such as transaction manager, between the application and the module.","optional":true,"defaultValue":"","children":[{"name":"enableNestedTransactions","type":"`boolean`","description":"a boolean value indicating whether nested transactions are enabled.","optional":true,"defaultValue":"","children":[]},{"name":"isolationLevel","type":"`string`","description":"A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.","optional":true,"defaultValue":"","children":[]},{"name":"manager","type":"`TManager`","description":"An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.","optional":true,"defaultValue":"","children":[]},{"name":"transactionId","type":"`string`","description":"a string indicating the ID of the current transaction.","optional":true,"defaultValue":"","children":[]},{"name":"transactionManager","type":"`TManager`","description":"An instance of a transaction manager of type `TManager`, which is aLine truncated
|
||||||
|
|
||||||
|
## Returns
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"Promise","type":"`Promise`<[`PriceSetMoneyAmountRulesDTO`](../../interfaces/PriceSetMoneyAmountRulesDTO.mdx)[]\\>","optional":false,"defaultValue":"","description":"The list of price set money amount rules.","children":[{"name":"PriceSetMoneyAmountRulesDTO[]","type":"[`PriceSetMoneyAmountRulesDTO`](../../interfaces/PriceSetMoneyAmountRulesDTO.mdx)[]","optional":false,"defaultValue":"","description":"","children":[{"name":"PriceSetMoneyAmountRulesDTO","type":"`object`","description":"A price set money amount rule's data.","optional":false,"defaultValue":"","children":[]}]}]}]} />
|
||||||
-149
@@ -1,149 +0,0 @@
|
|||||||
---
|
|
||||||
displayed_sidebar: pricingReference
|
|
||||||
badge:
|
|
||||||
variant: orange
|
|
||||||
text: Beta
|
|
||||||
slug: /references/pricing/listRuleTypes
|
|
||||||
sidebar_label: listRuleTypes
|
|
||||||
---
|
|
||||||
|
|
||||||
# listRuleTypes - Pricing Module Reference
|
|
||||||
|
|
||||||
This documentation provides a reference to the listRuleTypes method. This belongs to the Pricing Module.
|
|
||||||
|
|
||||||
This method is used to retrieve a paginated list of rule types based on optional filters and configuration.
|
|
||||||
|
|
||||||
## Parameters
|
|
||||||
|
|
||||||
- `filters`: (optional) An object of type [FilterableRuleTypeProps](../../interfaces/FilterableRuleTypeProps.md) that is used to filter the retrieved rule types. It accepts the following properties:
|
|
||||||
- `$and`: (optional) An array of filters to apply on the entity, where each item in the array is joined with an "and" condition.
|
|
||||||
- `$or`: (optional) An array of filters to apply on the entity, where each item in the array is joined with an "or" condition.
|
|
||||||
- `id`: (optional) an array of strings, each being an ID to filter rule types.
|
|
||||||
- `name`: (optional) an array of strings, each being a name to filter rule types.
|
|
||||||
- `rule_attribute`: (optional) an array of strings, each being a rule attribute to filter rule types.
|
|
||||||
- `config`: (optional) An object of type [FindConfig](../../interfaces/FindConfig.md) used to configure how the rule types are retrieved. Its properties, such as `select` or `relations`, accept the attributes or relations associated with a rule type. It accepts the following properties:
|
|
||||||
- `order`: (optional) An object used to specify how to sort the returned records. Its keys are the names of attributes of the entity, and a key's value can either be `ASC` to sort retrieved records in an ascending order, or `DESC` to sort retrieved records in a descending order.
|
|
||||||
- `relations`: (optional) An array of strings, each being relation names of the entity to retrieve in the result.
|
|
||||||
- `select`: (optional) An array of strings, each being attribute names of the entity to retrieve in the result.
|
|
||||||
- `skip`: (optional) A number indicating the number of records to skip before retrieving the results.
|
|
||||||
- `take`: (optional) A number indicating the number of records to return in the result.
|
|
||||||
- `withDeleted`: (optional) A boolean indicating whether deleted records should also be retrieved as part of the result. This only works if the entity extends the `SoftDeletableEntity` class.
|
|
||||||
- `sharedContext`: (optional) An object of type [Context](../../interfaces/Context.md) used to share resources, such as transaction manager, between the application and the module. It accepts the following properties:
|
|
||||||
- `enableNestedTransactions`: (optional) a boolean value indicating whether nested transactions are enabled.
|
|
||||||
- `isolationLevel`: (optional) A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.
|
|
||||||
- `manager`: (optional) An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.
|
|
||||||
- `transactionId`: (optional) a string indicating the ID of the current transaction.
|
|
||||||
- `transactionManager`: (optional) An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.
|
|
||||||
|
|
||||||
## Returns
|
|
||||||
|
|
||||||
A promise that resolves to an array of objects of type [RuleTypeDTO](../../interfaces/RuleTypeDTO.md).
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary>
|
|
||||||
RuleTypeDTO
|
|
||||||
</summary>
|
|
||||||
|
|
||||||
- `default_priority`: A number indicating the priority of the rule type. This is useful when calculating the price of a price set, and multiple rules satisfy the provided context. The higher the value, the higher the priority of the rule type.
|
|
||||||
- `id`: A string indicating the ID of the rule type.
|
|
||||||
- `name`: A string indicating the display name of the rule type.
|
|
||||||
- `rule_attribute`: A string indicating a unique name used to later identify the rule_attribute. For example, it can be used in the `context` parameter of the `calculatePrices` method to specify a rule for calculating the price.
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
## Example
|
|
||||||
|
|
||||||
To retrieve a list of rule types using their IDs:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function retrieveRuleTypes (ruleTypeId: string) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const ruleTypes = await pricingService.listRuleTypes({
|
|
||||||
id: [
|
|
||||||
ruleTypeId
|
|
||||||
]
|
|
||||||
})
|
|
||||||
|
|
||||||
// do something with the rule types or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
To specify attributes that should be retrieved within the rule types:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function retrieveRuleTypes (ruleTypeId: string) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const ruleTypes = await pricingService.listRuleTypes({
|
|
||||||
id: [
|
|
||||||
ruleTypeId
|
|
||||||
]
|
|
||||||
}, {
|
|
||||||
select: ["name"]
|
|
||||||
})
|
|
||||||
|
|
||||||
// do something with the rule types or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
By default, only the first `15` records are retrieved. You can control pagination by specifying the `skip` and `take` properties of the `config` parameter:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function retrieveRuleTypes (ruleTypeId: string, skip: number, take: number) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const ruleTypes = await pricingService.listRuleTypes({
|
|
||||||
id: [
|
|
||||||
ruleTypeId
|
|
||||||
]
|
|
||||||
}, {
|
|
||||||
select: ["name"],
|
|
||||||
skip,
|
|
||||||
take
|
|
||||||
})
|
|
||||||
|
|
||||||
// do something with the rule types or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
You can also use the `$and` or `$or` properties of the `filter` parameter to use and/or conditions in your filters. For example:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function retrieveRuleTypes (ruleTypeId: string[], name: string[], skip: number, take: number) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const ruleTypes = await pricingService.listRuleTypes({
|
|
||||||
$and: [
|
|
||||||
{
|
|
||||||
id: ruleTypeId
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}, {
|
|
||||||
select: ["name"],
|
|
||||||
skip,
|
|
||||||
take
|
|
||||||
})
|
|
||||||
|
|
||||||
// do something with the rule types or return them
|
|
||||||
}
|
|
||||||
```
|
|
||||||
+121
@@ -0,0 +1,121 @@
|
|||||||
|
---
|
||||||
|
displayed_sidebar: pricingReference
|
||||||
|
badge:
|
||||||
|
variant: orange
|
||||||
|
text: Beta
|
||||||
|
slug: /references/pricing/listRuleTypes
|
||||||
|
sidebar_label: listRuleTypes
|
||||||
|
---
|
||||||
|
|
||||||
|
import ParameterTypes from "@site/src/components/ParameterTypes"
|
||||||
|
|
||||||
|
# listRuleTypes - Pricing Module Reference
|
||||||
|
|
||||||
|
This documentation provides a reference to the `listRuleTypes` method. This belongs to the Pricing Module.
|
||||||
|
|
||||||
|
This method is used to retrieve a paginated list of rule types based on optional filters and configuration.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
To retrieve a list of rule types using their IDs:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function retrieveRuleTypes (ruleTypeId: string) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const ruleTypes = await pricingService.listRuleTypes({
|
||||||
|
id: [
|
||||||
|
ruleTypeId
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
|
// do something with the rule types or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
To specify attributes that should be retrieved within the rule types:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function retrieveRuleTypes (ruleTypeId: string) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const ruleTypes = await pricingService.listRuleTypes({
|
||||||
|
id: [
|
||||||
|
ruleTypeId
|
||||||
|
]
|
||||||
|
}, {
|
||||||
|
select: ["name"]
|
||||||
|
})
|
||||||
|
|
||||||
|
// do something with the rule types or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
By default, only the first `15` records are retrieved. You can control pagination by specifying the `skip` and `take` properties of the `config` parameter:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function retrieveRuleTypes (ruleTypeId: string, skip: number, take: number) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const ruleTypes = await pricingService.listRuleTypes({
|
||||||
|
id: [
|
||||||
|
ruleTypeId
|
||||||
|
]
|
||||||
|
}, {
|
||||||
|
select: ["name"],
|
||||||
|
skip,
|
||||||
|
take
|
||||||
|
})
|
||||||
|
|
||||||
|
// do something with the rule types or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
You can also use the `$and` or `$or` properties of the `filter` parameter to use and/or conditions in your filters. For example:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function retrieveRuleTypes (ruleTypeId: string[], name: string[], skip: number, take: number) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
const ruleTypes = await pricingService.listRuleTypes({
|
||||||
|
$and: [
|
||||||
|
{
|
||||||
|
id: ruleTypeId
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}, {
|
||||||
|
select: ["name"],
|
||||||
|
skip,
|
||||||
|
take
|
||||||
|
})
|
||||||
|
|
||||||
|
// do something with the rule types or return them
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"filters","type":"[`FilterableRuleTypeProps`](../../interfaces/FilterableRuleTypeProps.mdx)","description":"The filters to apply on the retrieved rule types.","optional":true,"defaultValue":"","children":[{"name":"$and","type":"([`FilterableRuleTypeProps`](../../interfaces/FilterableRuleTypeProps.mdx) \\| [`BaseFilterable`](../../interfaces/BaseFilterable.mdx)<[`FilterableRuleTypeProps`](../../interfaces/FilterableRuleTypeProps.mdx)\\>)[]","description":"An array of filters to apply on the entity, where each item in the array is joined with an \"and\" condition.","optional":true,"defaultValue":"","children":[]},{"name":"$or","type":"([`FilterableRuleTypeProps`](../../interfaces/FilterableRuleTypeProps.mdx) \\| [`BaseFilterable`](../../interfaces/BaseFilterable.mdx)<[`FilterableRuleTypeProps`](../../interfaces/FilterableRuleTypeProps.mdx)\\>)[]","description":"An array of filters to apply on the entity, where each item in the array is joined with an \"or\" condition.","optional":true,"defaultValue":"","children":[]},{"name":"id","type":"`string`[]","description":"The IDs to filter rule types by.","optional":true,"defaultValue":"","children":[]},{"name":"name","type":"`string`[]","description":"The names to filter rule types by.","optional":true,"defaultValue":"","children":[]},{"name":"rule_attribute","type":"`string`[]","description":"The rule attributes to filter rule types by.","optional":true,"defaultValue":"","children":[]}]},{"name":"config","type":"[`FindConfig`](../../interfaces/FindConfig.mdx)<[`RuleTypeDTO`](../../interfaces/RuleTypeDTO.mdx)\\>","description":"The configurations determining how the rule types are retrieved. Its properties, such as `select` or `relations`, accept the attributes or relations associated with a rule type.","optional":true,"defaultValue":"","children":[{"name":"order","type":"`object`","description":"An object used to specify how to sort the returned records. Its keys are the names of attributes of the entity, and a key's value can either be `ASC` to sort retrieved records in an ascending order, or `DESC` to sort retrieved records in a descending order.","optional":true,"defaultValue":"","children":[]},{"name":"relations","type":"`string`[]","description":"An array of strings, each being relation names of the entity to retrieve in the result.","optional":true,"defaultValue":"","children":[]},{"name":"select","type":"(`string` \\| keyof `Entity`)[]","description":"An array of strings, each being attribute names of the entity to retrieve in the result.","optional":true,"defaultValue":"","children":[]},{"name":"skip","type":"`number`","description":"A number indicating the number of records to skip before retrieving the results.","optional":true,"defaultValue":"","children":[]},{"name":"take","type":"`number`","description":"A number indicating the number of records to return in the result.","optional":true,"defaultValue":"","children":[]},{"name":"withDeleted","type":"`boolean`","description":"A boolean indicating whether deleted records should also be retrieved as part of the result. This only works if the entity extends the `SoftDeletableEntity` class.","optional":true,"defaultValue":"","children":[]}]},{"name":"sharedContext","type":"[`Context`](../../interfaces/Context.mdx)","description":"A context used to share resources, such as transaction manager, between the application and the module.","optional":true,"defaultValue":"","children":[{"name":"enableNestedTransactions","type":"`boolean`","description":"a boolean value indicating whether nested transactions are enabled.","optional":true,"defaultValue":"","children":[]},{"name":"isolationLevel","type":"`string`","description":"A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.","optional":true,"defaultValue":"","children":[]},{"name":"manager","type":"`TManager`","description":"An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.","optional":true,"defaultValue":"","children":[]},{"name":"transactionId","type":"`string`","description":"a string indicating the ID of the current transaction.","optional":true,"defaultValue":"","children":[]},{"name":"transactionManager","type":"`TManager`","description":"An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.","optional":true,"defaultValue":"","children":[]}]}]} />
|
||||||
|
|
||||||
|
## Returns
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"Promise","type":"`Promise`<[`RuleTypeDTO`](../../interfaces/RuleTypeDTO.mdx)[]\\>","optional":false,"defaultValue":"","description":"The list of rule types.","children":[{"name":"RuleTypeDTO[]","type":"[`RuleTypeDTO`](../../interfaces/RuleTypeDTO.mdx)[]","optional":false,"defaultValue":"","description":"","children":[{"name":"RuleTypeDTO","type":"`object`","description":"A rule type's data.","optional":false,"defaultValue":"","children":[]}]}]}]} />
|
||||||
-49
@@ -1,49 +0,0 @@
|
|||||||
---
|
|
||||||
displayed_sidebar: pricingReference
|
|
||||||
badge:
|
|
||||||
variant: orange
|
|
||||||
text: Beta
|
|
||||||
slug: /references/pricing/removeRules
|
|
||||||
sidebar_label: removeRules
|
|
||||||
---
|
|
||||||
|
|
||||||
# removeRules - Pricing Module Reference
|
|
||||||
|
|
||||||
This documentation provides a reference to the removeRules method. This belongs to the Pricing Module.
|
|
||||||
|
|
||||||
This method remove rules from a price set.
|
|
||||||
|
|
||||||
## Parameters
|
|
||||||
|
|
||||||
- `data`: An array of objects of type [RemovePriceSetRulesDTO](../../interfaces/RemovePriceSetRulesDTO.md), each specfiying which rules to remove. Its items accept the following properties:
|
|
||||||
- `id`: A string indicating the ID of the price set.
|
|
||||||
- `rules`: An array of strings, each string is the `rule_attribute` of a rule you want to remove.
|
|
||||||
- `sharedContext`: (optional) An object of type [Context](../../interfaces/Context.md) used to share resources, such as transaction manager, between the application and the module. It accepts the following properties:
|
|
||||||
- `enableNestedTransactions`: (optional) a boolean value indicating whether nested transactions are enabled.
|
|
||||||
- `isolationLevel`: (optional) A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.
|
|
||||||
- `manager`: (optional) An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.
|
|
||||||
- `transactionId`: (optional) a string indicating the ID of the current transaction.
|
|
||||||
- `transactionManager`: (optional) An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.
|
|
||||||
|
|
||||||
## Returns
|
|
||||||
|
|
||||||
A promise that resolves when rules are successfully removed.
|
|
||||||
|
|
||||||
## Example
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function removePriceSetRule (priceSetId: string, ruleAttributes: []) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
await pricingService.removeRules([
|
|
||||||
{
|
|
||||||
id: priceSetId,
|
|
||||||
rules: ruleAttributes
|
|
||||||
},
|
|
||||||
])
|
|
||||||
}
|
|
||||||
```
|
|
||||||
+43
@@ -0,0 +1,43 @@
|
|||||||
|
---
|
||||||
|
displayed_sidebar: pricingReference
|
||||||
|
badge:
|
||||||
|
variant: orange
|
||||||
|
text: Beta
|
||||||
|
slug: /references/pricing/removeRules
|
||||||
|
sidebar_label: removeRules
|
||||||
|
---
|
||||||
|
|
||||||
|
import ParameterTypes from "@site/src/components/ParameterTypes"
|
||||||
|
|
||||||
|
# removeRules - Pricing Module Reference
|
||||||
|
|
||||||
|
This documentation provides a reference to the `removeRules` method. This belongs to the Pricing Module.
|
||||||
|
|
||||||
|
This method remove rules from a price set.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
initialize as initializePricingModule,
|
||||||
|
} from "@medusajs/pricing"
|
||||||
|
|
||||||
|
async function removePriceSetRule (priceSetId: string, ruleAttributes: []) {
|
||||||
|
const pricingService = await initializePricingModule()
|
||||||
|
|
||||||
|
await pricingService.removeRules([
|
||||||
|
{
|
||||||
|
id: priceSetId,
|
||||||
|
rules: ruleAttributes
|
||||||
|
},
|
||||||
|
])
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"data","type":"[`RemovePriceSetRulesDTO`](../../interfaces/RemovePriceSetRulesDTO.mdx)[]","description":"The rules to remove per price set.","optional":false,"defaultValue":"","children":[{"name":"id","type":"`string`","description":"The ID of the price set.","optional":false,"defaultValue":"","children":[]},{"name":"rules","type":"`string`[]","description":"The rules to remove. Each string is the `rule_attribute` of a rule to remove.","optional":false,"defaultValue":"","children":[]}]},{"name":"sharedContext","type":"[`Context`](../../interfaces/Context.mdx)","description":"A context used to share resources, such as transaction manager, between the application and the module.","optional":true,"defaultValue":"","children":[{"name":"enableNestedTransactions","type":"`boolean`","description":"a boolean value indicating whether nested transactions are enabled.","optional":true,"defaultValue":"","children":[]},{"name":"isolationLevel","type":"`string`","description":"A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.","optional":true,"defaultValue":"","children":[]},{"name":"manager","type":"`TManager`","description":"An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.","optional":true,"defaultValue":"","children":[]},{"name":"transactionId","type":"`string`","description":"a string indicating the ID of the current transaction.","optional":true,"defaultValue":"","children":[]},{"name":"transactionManager","type":"`TManager`","description":"An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.","optional":true,"defaultValue":"","children":[]}]}]} />
|
||||||
|
|
||||||
|
## Returns
|
||||||
|
|
||||||
|
<ParameterTypes parameters={[{"name":"Promise","type":"`Promise`<`void`\\>","optional":false,"defaultValue":"","description":"Resolves when rules are successfully removed.","children":[]}]} />
|
||||||
-101
@@ -1,101 +0,0 @@
|
|||||||
---
|
|
||||||
displayed_sidebar: pricingReference
|
|
||||||
badge:
|
|
||||||
variant: orange
|
|
||||||
text: Beta
|
|
||||||
slug: /references/pricing/retrieve
|
|
||||||
sidebar_label: retrieve
|
|
||||||
---
|
|
||||||
|
|
||||||
# retrieve - Pricing Module Reference
|
|
||||||
|
|
||||||
This documentation provides a reference to the retrieve method. This belongs to the Pricing Module.
|
|
||||||
|
|
||||||
This method is used to retrieves a price set by its ID.
|
|
||||||
|
|
||||||
## Parameters
|
|
||||||
|
|
||||||
- `id`: A string indicating the ID of the price set to retrieve.
|
|
||||||
- `config`: (optional) An object of type [FindConfig](../../interfaces/FindConfig.md) used to configure how the price set is retrieved. Its properties, such as `select` or `relations`, accept the attributes or relations associated with a price set. It accepts the following properties:
|
|
||||||
- `order`: (optional) An object used to specify how to sort the returned records. Its keys are the names of attributes of the entity, and a key's value can either be `ASC` to sort retrieved records in an ascending order, or `DESC` to sort retrieved records in a descending order.
|
|
||||||
- `relations`: (optional) An array of strings, each being relation names of the entity to retrieve in the result.
|
|
||||||
- `select`: (optional) An array of strings, each being attribute names of the entity to retrieve in the result.
|
|
||||||
- `skip`: (optional) A number indicating the number of records to skip before retrieving the results.
|
|
||||||
- `take`: (optional) A number indicating the number of records to return in the result.
|
|
||||||
- `withDeleted`: (optional) A boolean indicating whether deleted records should also be retrieved as part of the result. This only works if the entity extends the `SoftDeletableEntity` class.
|
|
||||||
- `sharedContext`: (optional) An object of type [Context](../../interfaces/Context.md) used to share resources, such as transaction manager, between the application and the module. It accepts the following properties:
|
|
||||||
- `enableNestedTransactions`: (optional) a boolean value indicating whether nested transactions are enabled.
|
|
||||||
- `isolationLevel`: (optional) A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.
|
|
||||||
- `manager`: (optional) An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.
|
|
||||||
- `transactionId`: (optional) a string indicating the ID of the current transaction.
|
|
||||||
- `transactionManager`: (optional) An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.
|
|
||||||
|
|
||||||
## Returns
|
|
||||||
|
|
||||||
A promise that resolves to an object of type [PriceSetDTO](../../interfaces/PriceSetDTO.md) which is the retrieved price set.
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary>
|
|
||||||
PriceSetDTO
|
|
||||||
</summary>
|
|
||||||
|
|
||||||
- `id`: A string indicating the ID of the price set.
|
|
||||||
- `money_amounts`: (optional) An array of objects of type [MoneyAmountDTO](../../interfaces/MoneyAmountDTO.md), which holds the prices that belong to this price set. Its items accept the following properties:
|
|
||||||
- `amount`: (optional) A number indicating the amount of this price.
|
|
||||||
- `currency`: (optional) An object of type [CurrencyDTO](../../interfaces/CurrencyDTO.md) that holds the details of the price's currency. Since this is a relation, it will only be retrieved if it's passed to the `relations` array of the find-configuration options. It accepts the following properties:
|
|
||||||
- `code`: a string indicating the code of the currency.
|
|
||||||
- `name`: (optional) a string indicating the name of the currency.
|
|
||||||
- `symbol`: (optional) a string indicating the symbol of the currency.
|
|
||||||
- `symbol_native`: (optional) a string indicating the symbol of the currecy in its native form. This is typically the symbol used when displaying a price.
|
|
||||||
- `currency_code`: (optional) A string that indicates the currency code of this price.
|
|
||||||
- `id`: A string that indicates the ID of the money amount. A money amount represents a price.
|
|
||||||
- `max_quantity`: (optional) A number that indicates the maximum quantity required to be purchased for this price to be applied.
|
|
||||||
- `min_quantity`: (optional) A number that indicates the minimum quantity required to be purchased for this price to be applied.
|
|
||||||
- `rule_types`: (optional) An array of objects of type [RuleTypeDTO](../../interfaces/RuleTypeDTO.md), which holds the rule types applied on this price set. Its items accept the following properties:
|
|
||||||
- `default_priority`: A number indicating the priority of the rule type. This is useful when calculating the price of a price set, and multiple rules satisfy the provided context. The higher the value, the higher the priority of the rule type.
|
|
||||||
- `id`: A string indicating the ID of the rule type.
|
|
||||||
- `name`: A string indicating the display name of the rule type.
|
|
||||||
- `rule_attribute`: A string indicating a unique name used to later identify the rule_attribute. For example, it can be used in the `context` parameter of the `calculatePrices` method to specify a rule for calculating the price.
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
## Example
|
|
||||||
|
|
||||||
A simple example that retrieves a price set by its ID:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function retrievePriceSet (priceSetId: string) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const priceSet = await pricingService.retrieve(
|
|
||||||
priceSetId
|
|
||||||
)
|
|
||||||
|
|
||||||
// do something with the price set or return it
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
To specify relations that should be retrieved:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {
|
|
||||||
initialize as initializePricingModule,
|
|
||||||
} from "@medusajs/pricing"
|
|
||||||
|
|
||||||
async function retrievePriceSet (priceSetId: string) {
|
|
||||||
const pricingService = await initializePricingModule()
|
|
||||||
|
|
||||||
const priceSet = await pricingService.retrieve(
|
|
||||||
priceSetId,
|
|
||||||
{
|
|
||||||
relations: ["money_amounts"]
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
// do something with the price set or return it
|
|
||||||
}
|
|
||||||
```
|
|
||||||
Loaded 100 of 218 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user