Files
medusa-store/www/apps/docs/content/references/services/classes/ShippingOptionService.mdx
github-actions[bot] 39649b3552 chore(docs): Generated References (#5602)
Generated the following references:
- `pricing`
- `product`

Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
Co-authored-by: Shahed Nasser <27354907+shahednasser@users.noreply.github.com>
2023-11-10 17:31:02 +00:00

1091 lines
24 KiB
Plaintext

---
displayed_sidebar: servicesSidebar
---
import ParameterTypes from "@site/src/components/ParameterTypes"
# ShippingOptionService
Provides layer to manipulate profiles.
## Constructors
### constructor
**new ShippingOptionService**(`«destructured»`)
#### Parameters
<ParameterTypes parameters={[
{
"name": "__namedParameters",
"type": "[`InjectedDependencies`](../types/InjectedDependencies-37.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": "featureFlagRouter_",
"type": "[`FlagRouter`](FlagRouter.mdx)",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "manager_",
"type": "`EntityManager`",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "methodRepository_",
"type": "`Repository`<[`ShippingMethod`](ShippingMethod.mdx)\\>",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "optionRepository_",
"type": "`Repository`<[`ShippingOption`](ShippingOption.mdx)\\> & { `upsertShippingProfile`: Method upsertShippingProfile }",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "providerService_",
"type": "[`FulfillmentProviderService`](FulfillmentProviderService.mdx)",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "regionService_",
"type": "[`RegionService`](RegionService.mdx)",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "requirementRepository_",
"type": "`Repository`<[`ShippingOptionRequirement`](ShippingOptionRequirement.mdx)\\>",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "transactionManager_",
"type": "`undefined` \\| `EntityManager`",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
## Accessors
### activeManager\_
`Protected` `get` **activeManager_**(): `EntityManager`
#### Returns
`EntityManager`
<ParameterTypes parameters={[
{
"name": "EntityManager",
"type": "`EntityManager`",
"optional": false,
"defaultValue": "",
"description": "",
"expandable": false,
"children": []
}
]} />
## Methods
### addRequirement
**addRequirement**(`optionId`, `requirement`): `Promise`<[`ShippingOption`](ShippingOption.mdx)\>
Adds a requirement to a shipping option. Only 1 requirement of each type
is allowed.
#### Parameters
<ParameterTypes parameters={[
{
"name": "optionId",
"type": "`string`",
"description": "the option to add the requirement to.",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "requirement",
"type": "[`ShippingOptionRequirement`](ShippingOptionRequirement.mdx)",
"description": "the requirement for the option.",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
#### Returns
`Promise`<[`ShippingOption`](ShippingOption.mdx)\>
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "`Promise`<[`ShippingOption`](ShippingOption.mdx)\\>",
"optional": false,
"defaultValue": "",
"description": "the result of update",
"expandable": false,
"children": []
}
]} />
___
### atomicPhase\_
`Protected` **atomicPhase_**<`TResult`, `TError`\>(`work`, `isolationOrErrorHandler?`, `maybeErrorHandlerOrDontFail?`): `Promise`<`TResult`\>
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.
<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`<`TResult`\\>",
"description": "the transactional work to be done",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "isolationOrErrorHandler",
"type": "`IsolationLevel` \\| (`error`: `TError`) => `Promise`<`void` \\| `TResult`\\>",
"description": "the isolation level to be used for the work.",
"optional": true,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "maybeErrorHandlerOrDontFail",
"type": "(`error`: `TError`) => `Promise`<`void` \\| `TResult`\\>",
"description": "Potential error handler",
"optional": true,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
#### Returns
`Promise`<`TResult`\>
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "`Promise`<`TResult`\\>",
"optional": false,
"defaultValue": "",
"description": "the result of the transactional work",
"expandable": false,
"children": []
}
]} />
___
### create
**create**(`data`): `Promise`<[`ShippingOption`](ShippingOption.mdx)\>
Creates a new shipping option. Used both for outbound and inbound shipping
options. The difference is registered by the `is_return` field which
defaults to false.
#### Parameters
<ParameterTypes parameters={[
{
"name": "data",
"type": "[`CreateShippingOptionInput`](../types/CreateShippingOptionInput.mdx)",
"description": "the data to create shipping options",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
#### Returns
`Promise`<[`ShippingOption`](ShippingOption.mdx)\>
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "`Promise`<[`ShippingOption`](ShippingOption.mdx)\\>",
"optional": false,
"defaultValue": "",
"description": "the result of the create operation",
"expandable": false,
"children": []
}
]} />
___
### createShippingMethod
**createShippingMethod**(`optionId`, `data`, `config`): `Promise`<[`ShippingMethod`](ShippingMethod.mdx)\>
Creates a shipping method for a given cart.
#### Parameters
<ParameterTypes parameters={[
{
"name": "optionId",
"type": "`string`",
"description": "the id of the option to use for the method.",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "data",
"type": "Record<`string`, `unknown`\\>",
"description": "the optional provider data to use.",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "config",
"type": "[`CreateShippingMethodDto`](../types/CreateShippingMethodDto.mdx)",
"description": "the cart to create the shipping method for.",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
#### Returns
`Promise`<[`ShippingMethod`](ShippingMethod.mdx)\>
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "`Promise`<[`ShippingMethod`](ShippingMethod.mdx)\\>",
"optional": false,
"defaultValue": "",
"description": "the resulting shipping method.",
"expandable": false,
"children": []
}
]} />
___
### delete
**delete**(`optionId`): `Promise`<`void` \| [`ShippingOption`](ShippingOption.mdx)\>
Deletes a profile with a given profile id.
#### Parameters
<ParameterTypes parameters={[
{
"name": "optionId",
"type": "`string`",
"description": "the id of the profile to delete. Must be castable as an ObjectId",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
#### Returns
`Promise`<`void` \| [`ShippingOption`](ShippingOption.mdx)\>
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "`Promise`<`void` \\| [`ShippingOption`](ShippingOption.mdx)\\>",
"optional": false,
"defaultValue": "",
"description": "the result of the delete operation.",
"expandable": false,
"children": []
}
]} />
___
### deleteShippingMethods
**deleteShippingMethods**(`shippingMethods`): `Promise`<[`ShippingMethod`](ShippingMethod.mdx)[]\>
Removes a given shipping method
#### Parameters
<ParameterTypes parameters={[
{
"name": "shippingMethods",
"type": "[`ShippingMethod`](ShippingMethod.mdx) \\| [`ShippingMethod`](ShippingMethod.mdx)[]",
"description": "the shipping method to remove",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
#### Returns
`Promise`<[`ShippingMethod`](ShippingMethod.mdx)[]\>
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "`Promise`<[`ShippingMethod`](ShippingMethod.mdx)[]\\>",
"optional": false,
"defaultValue": "",
"description": "removed shipping methods",
"expandable": false,
"children": []
}
]} />
___
### getPrice\_
**getPrice_**(`option`, `data`, `cart`): `Promise`<`number`\>
Returns the amount to be paid for a shipping method. Will ask the
fulfillment provider to calculate the price if the shipping option has the
price type "calculated".
#### Parameters
<ParameterTypes parameters={[
{
"name": "option",
"type": "[`ShippingOption`](ShippingOption.mdx)",
"description": "the shipping option to retrieve the price for.",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "data",
"type": "Record<`string`, `unknown`\\>",
"description": "the shipping data to retrieve the price.",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "cart",
"type": "`undefined` \\| [`Order`](Order.mdx) \\| [`Cart`](Cart.mdx)",
"description": "the context in which the price should be retrieved.",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
#### Returns
`Promise`<`number`\>
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "`Promise`<`number`\\>",
"optional": false,
"defaultValue": "",
"description": "the price of the shipping option.",
"expandable": false,
"children": []
}
]} />
___
### list
**list**(`selector`, `config?`): `Promise`<[`ShippingOption`](ShippingOption.mdx)[]\>
#### Parameters
<ParameterTypes parameters={[
{
"name": "selector",
"type": "[`Selector`](../types/Selector.mdx)<[`ShippingOption`](ShippingOption.mdx)\\>",
"description": "the query object for find",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "config",
"type": "[`FindConfig`](../interfaces/FindConfig.mdx)<[`ShippingOption`](ShippingOption.mdx)\\>",
"description": "config object",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
#### Returns
`Promise`<[`ShippingOption`](ShippingOption.mdx)[]\>
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "`Promise`<[`ShippingOption`](ShippingOption.mdx)[]\\>",
"optional": false,
"defaultValue": "",
"description": "the result of the find operation",
"expandable": false,
"children": []
}
]} />
___
### listAndCount
**listAndCount**(`selector`, `config?`): `Promise`<[[`ShippingOption`](ShippingOption.mdx)[], `number`]\>
#### Parameters
<ParameterTypes parameters={[
{
"name": "selector",
"type": "[`Selector`](../types/Selector.mdx)<[`ShippingOption`](ShippingOption.mdx)\\>",
"description": "the query object for find",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "config",
"type": "[`FindConfig`](../interfaces/FindConfig.mdx)<[`ShippingOption`](ShippingOption.mdx)\\>",
"description": "config object",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
#### Returns
`Promise`<[[`ShippingOption`](ShippingOption.mdx)[], `number`]\>
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "`Promise`<[[`ShippingOption`](ShippingOption.mdx)[], `number`]\\>",
"optional": false,
"defaultValue": "",
"description": "the result of the find operation",
"expandable": false,
"children": []
}
]} />
___
### removeRequirement
**removeRequirement**(`requirementId`): `Promise`<`void` \| [`ShippingOptionRequirement`](ShippingOptionRequirement.mdx)\>
Removes a requirement from a shipping option
#### Parameters
<ParameterTypes parameters={[
{
"name": "requirementId",
"type": "`any`",
"description": "the id of the requirement to remove",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
#### Returns
`Promise`<`void` \| [`ShippingOptionRequirement`](ShippingOptionRequirement.mdx)\>
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "`Promise`<`void` \\| [`ShippingOptionRequirement`](ShippingOptionRequirement.mdx)\\>",
"optional": false,
"defaultValue": "",
"description": "the result of update",
"expandable": false,
"children": []
}
]} />
___
### retrieve
**retrieve**(`optionId`, `options?`): `Promise`<[`ShippingOption`](ShippingOption.mdx)\>
Gets a profile by id.
Throws in case of DB Error and if profile was not found.
#### Parameters
<ParameterTypes parameters={[
{
"name": "optionId",
"type": "`any`",
"description": "the id of the profile to get.",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "options",
"type": "[`FindConfig`](../interfaces/FindConfig.mdx)<[`ShippingOption`](ShippingOption.mdx)\\>",
"description": "the options to get a profile",
"optional": false,
"defaultValue": "{}",
"expandable": false,
"children": []
}
]} />
#### Returns
`Promise`<[`ShippingOption`](ShippingOption.mdx)\>
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "`Promise`<[`ShippingOption`](ShippingOption.mdx)\\>",
"optional": false,
"defaultValue": "",
"description": "the profile document.",
"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": []
}
]} />
___
### update
**update**(`optionId`, `update`): `Promise`<[`ShippingOption`](ShippingOption.mdx)\>
Updates a profile. Metadata updates and product updates should use
dedicated methods, e.g. `setMetadata`, etc. The function
will throw errors if metadata or product updates are attempted.
#### Parameters
<ParameterTypes parameters={[
{
"name": "optionId",
"type": "`string`",
"description": "the id of the option. Must be a string that can be casted to an ObjectId",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "update",
"type": "[`UpdateShippingOptionInput`](../types/UpdateShippingOptionInput.mdx)",
"description": "an object with the update values.",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
#### Returns
`Promise`<[`ShippingOption`](ShippingOption.mdx)\>
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "`Promise`<[`ShippingOption`](ShippingOption.mdx)\\>",
"optional": false,
"defaultValue": "",
"description": "resolves to the update result.",
"expandable": false,
"children": []
}
]} />
___
### updateShippingMethod
**updateShippingMethod**(`id`, `update`): `Promise`<`undefined` \| [`ShippingMethod`](ShippingMethod.mdx)\>
Updates a shipping method's associations. Useful when a cart is completed
and its methods should be copied to an order/swap entity.
#### Parameters
<ParameterTypes parameters={[
{
"name": "id",
"type": "`string`",
"description": "the id of the shipping method to update",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "update",
"type": "[`ShippingMethodUpdate`](../types/ShippingMethodUpdate.mdx)",
"description": "the values to update the method with",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
#### Returns
`Promise`<`undefined` \| [`ShippingMethod`](ShippingMethod.mdx)\>
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "`Promise`<`undefined` \\| [`ShippingMethod`](ShippingMethod.mdx)\\>",
"optional": false,
"defaultValue": "",
"description": "the resulting shipping method",
"expandable": false,
"children": []
}
]} />
___
### updateShippingProfile
**updateShippingProfile**(`optionIds`, `profileId`): `Promise`<[`ShippingOption`](ShippingOption.mdx)[]\>
#### Parameters
<ParameterTypes parameters={[
{
"name": "optionIds",
"type": "`string` \\| `string`[]",
"description": "ID or IDs of the shipping options to update",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "profileId",
"type": "`string`",
"description": "Shipping profile ID to update the shipping options with",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
#### Returns
`Promise`<[`ShippingOption`](ShippingOption.mdx)[]\>
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "`Promise`<[`ShippingOption`](ShippingOption.mdx)[]\\>",
"optional": false,
"defaultValue": "",
"description": "updated shipping options",
"expandable": false,
"children": []
}
]} />
___
### validateAndMutatePrice
`Private` **validateAndMutatePrice**(`option`, `priceInput`): `Promise`<[`CreateShippingOptionInput`](../types/CreateShippingOptionInput.mdx) \| [`Omit`](../types/Omit.mdx)<[`ShippingOption`](ShippingOption.mdx), ``"beforeInsert"``\>\>
#### Parameters
<ParameterTypes parameters={[
{
"name": "option",
"type": "[`ShippingOption`](ShippingOption.mdx) \\| [`CreateShippingOptionInput`](../types/CreateShippingOptionInput.mdx)",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "priceInput",
"type": "[`ValidatePriceTypeAndAmountInput`](../types/ValidatePriceTypeAndAmountInput.mdx)",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
#### Returns
`Promise`<[`CreateShippingOptionInput`](../types/CreateShippingOptionInput.mdx) \| [`Omit`](../types/Omit.mdx)<[`ShippingOption`](ShippingOption.mdx), ``"beforeInsert"``\>\>
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "`Promise`<[`CreateShippingOptionInput`](../types/CreateShippingOptionInput.mdx) \\| [`Omit`](../types/Omit.mdx)<[`ShippingOption`](ShippingOption.mdx), ``\"beforeInsert\"``\\>\\>",
"optional": false,
"defaultValue": "",
"description": "",
"expandable": false,
"children": []
}
]} />
___
### validateCartOption
**validateCartOption**(`option`, `cart`): `Promise`<``null`` \| [`ShippingOption`](ShippingOption.mdx)\>
Checks if a given option id is a valid option for a cart. If it is the
option is returned with the correct price. Throws when region_ids do not
match, or when the shipping option requirements are not satisfied.
#### Parameters
<ParameterTypes parameters={[
{
"name": "option",
"type": "[`ShippingOption`](ShippingOption.mdx)",
"description": "the option object to check",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "cart",
"type": "[`Cart`](Cart.mdx)",
"description": "the cart object to check against",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
#### Returns
`Promise`<``null`` \| [`ShippingOption`](ShippingOption.mdx)\>
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "`Promise`<``null`` \\| [`ShippingOption`](ShippingOption.mdx)\\>",
"optional": false,
"defaultValue": "",
"description": "the validated shipping option",
"expandable": false,
"children": []
}
]} />
___
### validatePriceType\_
**validatePriceType_**(`priceType`, `option`): `Promise`<[`ShippingOptionPriceType`](../enums/ShippingOptionPriceType.mdx)\>
Validates a shipping option price
#### Parameters
<ParameterTypes parameters={[
{
"name": "priceType",
"type": "[`ShippingOptionPriceType`](../enums/ShippingOptionPriceType.mdx)",
"description": "the price to validate",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "option",
"type": "[`ShippingOption`](ShippingOption.mdx)",
"description": "the option to validate against",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
#### Returns
`Promise`<[`ShippingOptionPriceType`](../enums/ShippingOptionPriceType.mdx)\>
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "`Promise`<[`ShippingOptionPriceType`](../enums/ShippingOptionPriceType.mdx)\\>",
"optional": false,
"defaultValue": "",
"description": "the validated price",
"expandable": false,
"children": []
}
]} />
___
### validateRequirement\_
**validateRequirement_**(`requirement`, `optionId?`): `Promise`<[`ShippingOptionRequirement`](ShippingOptionRequirement.mdx)\>
Validates a requirement
#### Parameters
<ParameterTypes parameters={[
{
"name": "requirement",
"type": "[`ShippingOptionRequirement`](ShippingOptionRequirement.mdx)",
"description": "the requirement to validate",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "optionId",
"type": "`undefined` \\| `string`",
"description": "the id to validate the requirement",
"optional": false,
"defaultValue": "undefined",
"expandable": false,
"children": []
}
]} />
#### Returns
`Promise`<[`ShippingOptionRequirement`](ShippingOptionRequirement.mdx)\>
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "`Promise`<[`ShippingOptionRequirement`](ShippingOptionRequirement.mdx)\\>",
"optional": false,
"defaultValue": "",
"description": "a validated shipping requirement",
"expandable": false,
"children": []
}
]} />
___
### withTransaction
**withTransaction**(`transactionManager?`): [`ShippingOptionService`](ShippingOptionService.mdx)
#### Parameters
<ParameterTypes parameters={[
{
"name": "transactionManager",
"type": "`EntityManager`",
"description": "",
"optional": true,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
#### Returns
[`ShippingOptionService`](ShippingOptionService.mdx)
<ParameterTypes parameters={[
{
"name": "ShippingOptionService",
"type": "[`ShippingOptionService`](ShippingOptionService.mdx)",
"optional": false,
"defaultValue": "",
"description": "",
"expandable": false,
"children": []
}
]} />