Files
medusa-store/www/apps/docs/content/references/services/classes/PricingService.mdx
github-actions[bot] cdd42dbdcd chore(docs): Generated References (#5743)
Generated the following references:
- `entities`
- `inventory`
- `js-client`
- `pricing`
- `product`
- `services`
- `stock-location`
- `workflows`

Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
Co-authored-by: Shahed Nasser <27354907+shahednasser@users.noreply.github.com>
2023-11-27 18:58:52 +00:00

1071 lines
24 KiB
Plaintext

---
displayed_sidebar: servicesSidebar
---
import ParameterTypes from "@site/src/components/ParameterTypes"
# PricingService
Allows retrieval of prices.
## Constructors
#### constructor
`**new PricingService**(«destructured»)`
##### Parameters
<ParameterTypes parameters={[
{
"name": "__namedParameters",
"type": "[InjectedDependencies](../types/InjectedDependencies-25.mdx)",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
## Properties
<ParameterTypes parameters={[
{
"name": "__configModule__",
"type": "`Record<string, unknown>`",
"description": "",
"optional": true,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "__container__",
"type": "`any`",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "__moduleDeclaration__",
"type": "`Record<string, unknown>`",
"description": "",
"optional": true,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "customerService_",
"type": "[CustomerService](CustomerService.mdx)",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "featureFlagRouter",
"type": "[FlagRouter](FlagRouter.mdx)",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "manager_",
"type": "EntityManager",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "priceSelectionStrategy",
"type": "[IPriceSelectionStrategy](../interfaces/IPriceSelectionStrategy.mdx)",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "productVariantService",
"type": "[ProductVariantService](ProductVariantService.mdx)",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "regionService",
"type": "[RegionService](RegionService.mdx)",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "taxProviderService",
"type": "[TaxProviderService](TaxProviderService.mdx)",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "transactionManager_",
"type": "`undefined` \\| EntityManager",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
## Accessors
#### activeManager\_
`Protected` **activeManager\_**: [object Object]
___
#### pricingModuleService
`Protected` **pricingModuleService**: [object Object]
___
#### remoteQuery
`Protected` **remoteQuery**: [object Object]
## Methods
#### atomicPhase\_
`Protected **atomicPhase_**<TypeParameter TResult, TypeParameter TError>(work, isolationOrErrorHandler?, maybeErrorHandlerOrDontFail?): Promise&#60;TResult&#62;`
Wraps some work within a transactional block. If the service already has
a transaction manager attached this will be reused, otherwise a new
transaction manager is created.
##### Type Parameters
<ParameterTypes parameters={[
{
"name": "TResult",
"type": "`object`",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "TError",
"type": "`object`",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
##### Parameters
<ParameterTypes parameters={[
{
"name": "work",
"type": "(`transactionManager`: EntityManager) => Promise&#60;TResult&#62;",
"description": "the transactional work to be done",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "isolationOrErrorHandler",
"type": "`IsolationLevel` \\| (`error`: `TError`) => Promise&#60;void \\| TResult&#62;",
"description": "the isolation level to be used for the work.",
"optional": true,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "maybeErrorHandlerOrDontFail",
"type": "(`error`: `TError`) => Promise&#60;void \\| TResult&#62;",
"description": "Potential error handler",
"optional": true,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
##### Returns
Promise&#60;TResult&#62;
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "Promise&#60;TResult&#62;",
"optional": false,
"defaultValue": "",
"description": "the result of the transactional work",
"expandable": false,
"children": []
}
]} />
___
#### calculateTaxes
`**calculateTaxes**(variantPricing, productRates): [TaxedPricing](../types/TaxedPricing.mdx)`
Gets the prices for a product variant
##### Parameters
<ParameterTypes parameters={[
{
"name": "variantPricing",
"type": "[ProductVariantPricing](../types/ProductVariantPricing.mdx)",
"description": "the prices retrieved from a variant",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "productRates",
"type": "[TaxServiceRate](../types/TaxServiceRate.mdx)[]",
"description": "the tax rates that the product has applied",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
##### Returns
[TaxedPricing](../types/TaxedPricing.mdx)
<ParameterTypes parameters={[
{
"name": "TaxedPricing",
"type": "`object`",
"description": "Pricing fields related to taxes.",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
___
#### collectPricingContext
`**collectPricingContext**(context): Promise&#60;[PricingContext](../types/PricingContext-1.mdx)&#62;`
Collects additional information necessary for completing the price
selection.
##### Parameters
<ParameterTypes parameters={[
{
"name": "context",
"type": "[PriceSelectionContext](../types/PriceSelectionContext.mdx)",
"description": "the price selection context to use",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
##### Returns
Promise&#60;[PricingContext](../types/PricingContext-1.mdx)&#62;
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "Promise&#60;[PricingContext](../types/PricingContext-1.mdx)&#62;",
"optional": false,
"defaultValue": "",
"description": "The pricing context",
"expandable": false,
"children": []
}
]} />
___
#### getPricingModuleVariantMoneyAmounts
`Private **getPricingModuleVariantMoneyAmounts**(variantIds): Promise&#60;Map&#60;string, [MoneyAmount](MoneyAmount.mdx)[]&#62;&#62;`
##### Parameters
<ParameterTypes parameters={[
{
"name": "variantIds",
"type": "`string`[]",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
##### Returns
Promise&#60;Map&#60;string, [MoneyAmount](MoneyAmount.mdx)[]&#62;&#62;
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "Promise&#60;Map&#60;string, [MoneyAmount](MoneyAmount.mdx)[]&#62;&#62;",
"optional": false,
"defaultValue": "",
"description": "",
"expandable": false,
"children": []
}
]} />
___
#### getProductPricing
`**getProductPricing**(product, context): Promise&#60;Record&#60;string, [ProductVariantPricing](../types/ProductVariantPricing.mdx)&#62;&#62;`
Gets all the variant prices for a product. All the product's variants will
be fetched.
##### Parameters
<ParameterTypes parameters={[
{
"name": "product",
"type": "[Pick](../types/Pick.mdx)&#60;[Product](Product.mdx), \"id\" \\| \"variants\"&#62;",
"description": "the product to get pricing for.",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "context",
"type": "[PriceSelectionContext](../types/PriceSelectionContext.mdx)",
"description": "the price selection context to use",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
##### Returns
Promise&#60;Record&#60;string, [ProductVariantPricing](../types/ProductVariantPricing.mdx)&#62;&#62;
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "Promise&#60;Record&#60;string, [ProductVariantPricing](../types/ProductVariantPricing.mdx)&#62;&#62;",
"optional": false,
"defaultValue": "",
"description": "A map of variant ids to their corresponding prices",
"expandable": false,
"children": []
}
]} />
___
#### getProductPricingById
`**getProductPricingById**(productId, context): Promise&#60;Record&#60;string, [ProductVariantPricing](../types/ProductVariantPricing.mdx)&#62;&#62;`
Gets all the variant prices for a product by the product id
##### Parameters
<ParameterTypes parameters={[
{
"name": "productId",
"type": "`string`",
"description": "the id of the product to get prices for",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "context",
"type": "[PriceSelectionContext](../types/PriceSelectionContext.mdx)",
"description": "the price selection context to use",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
##### Returns
Promise&#60;Record&#60;string, [ProductVariantPricing](../types/ProductVariantPricing.mdx)&#62;&#62;
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "Promise&#60;Record&#60;string, [ProductVariantPricing](../types/ProductVariantPricing.mdx)&#62;&#62;",
"optional": false,
"defaultValue": "",
"description": "A map of variant ids to their corresponding prices",
"expandable": false,
"children": []
}
]} />
___
#### getProductPricing\_
`Private **getProductPricing_**(data, context): Promise&#60;Map&#60;string, Record&#60;string, [ProductVariantPricing](../types/ProductVariantPricing.mdx)&#62;&#62;&#62;`
##### Parameters
<ParameterTypes parameters={[
{
"name": "data",
"type": "``{ productId: string ; variants: [ProductVariant](ProductVariant.mdx)[] }``[]",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "context",
"type": "[PricingContext](../types/PricingContext-1.mdx)",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
##### Returns
Promise&#60;Map&#60;string, Record&#60;string, [ProductVariantPricing](../types/ProductVariantPricing.mdx)&#62;&#62;&#62;
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "Promise&#60;Map&#60;string, Record&#60;string, [ProductVariantPricing](../types/ProductVariantPricing.mdx)&#62;&#62;&#62;",
"optional": false,
"defaultValue": "",
"description": "",
"expandable": false,
"children": []
}
]} />
___
#### getProductVariantPricing
`**getProductVariantPricing**(variant, context): Promise&#60;[ProductVariantPricing](../types/ProductVariantPricing.mdx)&#62;`
Gets the prices for a product variant.
##### Parameters
<ParameterTypes parameters={[
{
"name": "variant",
"type": "[Pick](../types/Pick.mdx)&#60;[ProductVariant](ProductVariant.mdx), \"id\" \\| \"product_id\"&#62;",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "context",
"type": "[PriceSelectionContext](../types/PriceSelectionContext.mdx) \\| [PricingContext](../types/PricingContext-1.mdx)",
"description": "the price selection context to use",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
##### Returns
Promise&#60;[ProductVariantPricing](../types/ProductVariantPricing.mdx)&#62;
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "Promise&#60;[ProductVariantPricing](../types/ProductVariantPricing.mdx)&#62;",
"optional": false,
"defaultValue": "",
"description": "The product variant prices",
"expandable": false,
"children": []
}
]} />
___
#### getProductVariantPricingById
`**getProductVariantPricingById**(variantId, context): Promise&#60;[ProductVariantPricing](../types/ProductVariantPricing.mdx)&#62;`
Gets the prices for a product variant by a variant id.
##### Parameters
<ParameterTypes parameters={[
{
"name": "variantId",
"type": "`string`",
"description": "the id of the variant to get prices for",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "context",
"type": "[PriceSelectionContext](../types/PriceSelectionContext.mdx) \\| [PricingContext](../types/PricingContext-1.mdx)",
"description": "the price selection context to use",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
##### Returns
Promise&#60;[ProductVariantPricing](../types/ProductVariantPricing.mdx)&#62;
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "Promise&#60;[ProductVariantPricing](../types/ProductVariantPricing.mdx)&#62;",
"optional": false,
"defaultValue": "",
"description": "The product variant prices",
"expandable": false,
"children": []
}
]} />
#### Deprecated
Use [getProductVariantsPricing](PricingService.mdx#getproductvariantspricing) instead.
___
#### getProductVariantPricingModulePricing\_
`Private **getProductVariantPricingModulePricing_**(variantPriceData, context): Promise&#60;Map&#60;any, any&#62;&#62;`
##### Parameters
<ParameterTypes parameters={[
{
"name": "variantPriceData",
"type": "``{ quantity?: number ; variantId: string }``[]",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "context",
"type": "[PricingContext](../types/PricingContext-1.mdx)",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
##### Returns
Promise&#60;Map&#60;any, any&#62;&#62;
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "Promise&#60;Map&#60;any, any&#62;&#62;",
"optional": false,
"defaultValue": "",
"description": "",
"expandable": false,
"children": []
}
]} />
___
#### getProductVariantPricing\_
`Private **getProductVariantPricing_**(data, context): Promise&#60;Map&#60;string, [ProductVariantPricing](../types/ProductVariantPricing.mdx)&#62;&#62;`
##### Parameters
<ParameterTypes parameters={[
{
"name": "data",
"type": "``{ quantity?: number ; variantId: string }``[]",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "context",
"type": "[PricingContext](../types/PricingContext-1.mdx)",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
##### Returns
Promise&#60;Map&#60;string, [ProductVariantPricing](../types/ProductVariantPricing.mdx)&#62;&#62;
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "Promise&#60;Map&#60;string, [ProductVariantPricing](../types/ProductVariantPricing.mdx)&#62;&#62;",
"optional": false,
"defaultValue": "",
"description": "",
"expandable": false,
"children": []
}
]} />
___
#### getProductVariantsPricing
`**getProductVariantsPricing**(data, context): Promise&#60;&#123; [variant_id: string]: [ProductVariantPricing](../types/ProductVariantPricing.mdx); &#125;&#62;`
Gets the prices for a collection of variants.
##### Parameters
<ParameterTypes parameters={[
{
"name": "data",
"type": "``{ quantity?: number ; variantId: string }``[]",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "context",
"type": "[PriceSelectionContext](../types/PriceSelectionContext.mdx) \\| [PricingContext](../types/PricingContext-1.mdx)",
"description": "the price selection context to use",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
##### Returns
Promise&#60;&#123; [variant_id: string]: [ProductVariantPricing](../types/ProductVariantPricing.mdx); &#125;&#62;
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "Promise&#60;&#123; [variant_id: string]: [ProductVariantPricing](../types/ProductVariantPricing.mdx); &#125;&#62;",
"optional": false,
"defaultValue": "",
"description": "The product variant prices",
"expandable": false,
"children": []
}
]} />
___
#### getShippingOptionPricing
`**getShippingOptionPricing**(shippingOption, context): Promise&#60;[PricedShippingOption](../types/PricedShippingOption.mdx)&#62;`
Gets the prices for a shipping option.
##### Parameters
<ParameterTypes parameters={[
{
"name": "shippingOption",
"type": "[ShippingOption](ShippingOption.mdx)",
"description": "the shipping option to get prices for",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "context",
"type": "[PriceSelectionContext](../types/PriceSelectionContext.mdx) \\| [PricingContext](../types/PricingContext-1.mdx)",
"description": "the price selection context to use",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
##### Returns
Promise&#60;[PricedShippingOption](../types/PricedShippingOption.mdx)&#62;
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "Promise&#60;[PricedShippingOption](../types/PricedShippingOption.mdx)&#62;",
"optional": false,
"defaultValue": "",
"description": "The shipping option prices",
"expandable": false,
"children": []
}
]} />
___
#### setAdminProductPricing
`**setAdminProductPricing**(products): Promise&#60;([Product](Product.mdx) \| [PricedProduct](../types/PricedProduct.mdx))[]&#62;`
##### Parameters
<ParameterTypes parameters={[
{
"name": "products",
"type": "[Product](Product.mdx)[]",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
##### Returns
Promise&#60;([Product](Product.mdx) \| [PricedProduct](../types/PricedProduct.mdx))[]&#62;
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "Promise&#60;([Product](Product.mdx) \\| [PricedProduct](../types/PricedProduct.mdx))[]&#62;",
"optional": false,
"defaultValue": "",
"description": "",
"expandable": false,
"children": []
}
]} />
___
#### setAdminVariantPricing
`**setAdminVariantPricing**(variants, context?): Promise&#60;[PricedVariant](../types/PricedVariant.mdx)[]&#62;`
##### Parameters
<ParameterTypes parameters={[
{
"name": "variants",
"type": "[ProductVariant](ProductVariant.mdx)[]",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "context",
"type": "[PriceSelectionContext](../types/PriceSelectionContext.mdx)",
"description": "",
"optional": false,
"defaultValue": "{}",
"expandable": false,
"children": []
}
]} />
##### Returns
Promise&#60;[PricedVariant](../types/PricedVariant.mdx)[]&#62;
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "Promise&#60;[PricedVariant](../types/PricedVariant.mdx)[]&#62;",
"optional": false,
"defaultValue": "",
"description": "",
"expandable": false,
"children": []
}
]} />
___
#### setProductPrices
`**setProductPrices**(products, context?): Promise&#60;([Product](Product.mdx) \| [PricedProduct](../types/PricedProduct.mdx))[]&#62;`
Set additional prices on a list of products.
##### Parameters
<ParameterTypes parameters={[
{
"name": "products",
"type": "[Product](Product.mdx)[]",
"description": "list of products on which to set additional prices",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "context",
"type": "[PriceSelectionContext](../types/PriceSelectionContext.mdx)",
"description": "the price selection context to use",
"optional": false,
"defaultValue": "{}",
"expandable": false,
"children": []
}
]} />
##### Returns
Promise&#60;([Product](Product.mdx) \| [PricedProduct](../types/PricedProduct.mdx))[]&#62;
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "Promise&#60;([Product](Product.mdx) \\| [PricedProduct](../types/PricedProduct.mdx))[]&#62;",
"optional": false,
"defaultValue": "",
"description": "A list of products with variants decorated with prices",
"expandable": false,
"children": []
}
]} />
___
#### setShippingOptionPrices
`**setShippingOptionPrices**(shippingOptions, context?): Promise&#60;[PricedShippingOption](../types/PricedShippingOption.mdx)[]&#62;`
Set additional prices on a list of shipping options.
##### Parameters
<ParameterTypes parameters={[
{
"name": "shippingOptions",
"type": "[ShippingOption](ShippingOption.mdx)[]",
"description": "list of shipping options on which to set additional prices",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "context",
"type": "[Omit](../types/Omit.mdx)&#60;[PriceSelectionContext](../types/PriceSelectionContext.mdx), \"region_id\"&#62;",
"description": "the price selection context to use",
"optional": false,
"defaultValue": "{}",
"expandable": false,
"children": []
}
]} />
##### Returns
Promise&#60;[PricedShippingOption](../types/PricedShippingOption.mdx)[]&#62;
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "Promise&#60;[PricedShippingOption](../types/PricedShippingOption.mdx)[]&#62;",
"optional": false,
"defaultValue": "",
"description": "A list of shipping options with prices",
"expandable": false,
"children": []
}
]} />
___
#### setVariantPrices
`**setVariantPrices**(variants, context?): Promise&#60;[PricedVariant](../types/PricedVariant.mdx)[]&#62;`
Set additional prices on a list of product variants.
##### Parameters
<ParameterTypes parameters={[
{
"name": "variants",
"type": "[ProductVariant](ProductVariant.mdx)[]",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "context",
"type": "[PriceSelectionContext](../types/PriceSelectionContext.mdx)",
"description": "the price selection context to use",
"optional": false,
"defaultValue": "{}",
"expandable": false,
"children": []
}
]} />
##### Returns
Promise&#60;[PricedVariant](../types/PricedVariant.mdx)[]&#62;
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "Promise&#60;[PricedVariant](../types/PricedVariant.mdx)[]&#62;",
"optional": false,
"defaultValue": "",
"description": "A list of products with variants decorated with prices",
"expandable": false,
"children": []
}
]} />
___
#### shouldRetryTransaction\_
`Protected **shouldRetryTransaction_**(err): boolean`
##### Parameters
<ParameterTypes parameters={[
{
"name": "err",
"type": "`Record<string, unknown>` \\| ``{ code: string }``",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
##### Returns
`boolean`
<ParameterTypes parameters={[
{
"name": "boolean",
"type": "`boolean`",
"optional": true,
"defaultValue": "",
"description": "",
"expandable": false,
"children": []
}
]} />
___
#### withTransaction
`**withTransaction**(transactionManager?): [PricingService](PricingService.mdx)`
##### Parameters
<ParameterTypes parameters={[
{
"name": "transactionManager",
"type": "EntityManager",
"description": "",
"optional": true,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
##### Returns
[PricingService](PricingService.mdx)
<ParameterTypes parameters={[
{
"name": "PricingService",
"type": "[PricingService](PricingService.mdx)",
"optional": false,
"defaultValue": "",
"description": "",
"expandable": false,
"children": []
}
]} />