Files
medusa-store/www/apps/docs/content/references/services/classes/services.ShippingOptionService.mdx
github-actions[bot] 5a550e73b4 chore(docs): Generated References (#6222)
Generated the following references:
- `entities`
- `file`
- `fulfillment`
- `inventory`
- `js_client`
- `medusa`
- `medusa_config`
- `medusa_react`
- `modules`
- `notification`
- `payment`
- `price_selection`
- `pricing`
- `product`
- `search`
- `services`
- `stock_location`
- `tax`
- `tax_calculation`
- `types`
- `workflows`

Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
Co-authored-by: Shahed Nasser <27354907+shahednasser@users.noreply.github.com>
2024-01-25 18:12:27 +00:00

281 lines
20 KiB
Plaintext

---
displayed_sidebar: servicesSidebar
---
import ParameterTypes from "@site/src/components/ParameterTypes"
# ShippingOptionService
Provides layer to manipulate profiles.
## constructor
### Parameters
<ParameterTypes parameters={[{"name":"__namedParameters","type":"`InjectedDependencies`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="new ShippingOptionService"/>
___
## Properties
<ParameterTypes parameters={[{"name":"manager_","type":"`EntityManager`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"transactionManager_","type":"`undefined` \\| `EntityManager`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"__container__","type":"`any`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"providerService_","type":"[FulfillmentProviderService](services.FulfillmentProviderService.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"regionService_","type":"[RegionService](services.RegionService.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"requirementRepository_","type":"Repository&#60;[ShippingOptionRequirement](../../entities/classes/entities.ShippingOptionRequirement.mdx)&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"optionRepository_","type":"Repository&#60;[ShippingOption](../../entities/classes/entities.ShippingOption.mdx)&#62; & `object`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"methodRepository_","type":"Repository&#60;[ShippingMethod](../../entities/classes/entities.ShippingMethod.mdx)&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"featureFlagRouter_","type":"`FlagRouter`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"__configModule__","type":"`Record<string, unknown>`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"__moduleDeclaration__","type":"`Record<string, unknown>`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="ShippingOptionService"/>
___
## Accessors
### activeManager\_
#### Returns
<ParameterTypes parameters={[{"name":"EntityManager","type":"`EntityManager`","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]} sectionTitle="activeManager_"/>
___
## Methods
### withTransaction
#### Parameters
<ParameterTypes parameters={[{"name":"transactionManager","type":"`EntityManager`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="withTransaction"/>
#### Returns
<ParameterTypes parameters={[{"name":"this","type":"`this`","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]} sectionTitle="withTransaction"/>
### shouldRetryTransaction\_
#### Parameters
<ParameterTypes parameters={[{"name":"err","type":"`Record<string, unknown>` \\| `object`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="shouldRetryTransaction_"/>
#### Returns
<ParameterTypes parameters={[{"name":"boolean","type":"`boolean`","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]} sectionTitle="shouldRetryTransaction_"/>
### atomicPhase\_
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":[]}]} sectionTitle="atomicPhase_"/>
#### 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":[]}]} sectionTitle="atomicPhase_"/>
#### Returns
<ParameterTypes parameters={[{"name":"Promise","type":"Promise&#60;TResult&#62;","optional":false,"defaultValue":"","description":"the result of the transactional work","expandable":false,"children":[]}]} sectionTitle="atomicPhase_"/>
### validateRequirement\_
Validates a requirement
#### Parameters
<ParameterTypes parameters={[{"name":"requirement","type":"`ValidateRequirementTypeInput`","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":[]}]} sectionTitle="validateRequirement_"/>
#### Returns
<ParameterTypes parameters={[{"name":"Promise","type":"Promise&#60;[ShippingOptionRequirement](../../entities/classes/entities.ShippingOptionRequirement.mdx)&#62;","optional":false,"defaultValue":"","description":"a validated shipping requirement","expandable":false,"children":[]}]} sectionTitle="validateRequirement_"/>
### list
#### Parameters
<ParameterTypes parameters={[{"name":"selector","type":"[Selector](../../medusa/types/medusa.Selector.mdx)&#60;[ShippingOption](../../entities/classes/entities.ShippingOption.mdx)&#62; & `object`","description":"the query object for find","optional":false,"defaultValue":"{}","expandable":false,"children":[]},{"name":"config","type":"[FindConfig](../../medusa/interfaces/medusa.FindConfig.mdx)&#60;[ShippingOption](../../entities/classes/entities.ShippingOption.mdx)&#62;","description":"config object","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="list"/>
#### Returns
<ParameterTypes parameters={[{"name":"Promise","type":"Promise&#60;[ShippingOption](../../entities/classes/entities.ShippingOption.mdx)[]&#62;","optional":false,"defaultValue":"","description":"the result of the find operation","expandable":false,"children":[]}]} sectionTitle="list"/>
### listAndCount
#### Parameters
<ParameterTypes parameters={[{"name":"selector","type":"[Selector](../../medusa/types/medusa.Selector.mdx)&#60;[ShippingOption](../../entities/classes/entities.ShippingOption.mdx)&#62; & `object`","description":"the query object for find","optional":false,"defaultValue":"{}","expandable":false,"children":[]},{"name":"config","type":"[FindConfig](../../medusa/interfaces/medusa.FindConfig.mdx)&#60;[ShippingOption](../../entities/classes/entities.ShippingOption.mdx)&#62;","description":"config object","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="listAndCount"/>
#### Returns
<ParameterTypes parameters={[{"name":"Promise","type":"Promise&#60;[[ShippingOption](../../entities/classes/entities.ShippingOption.mdx)[], number]&#62;","optional":false,"defaultValue":"","description":"the result of the find operation","expandable":false,"children":[]}]} sectionTitle="listAndCount"/>
### retrieve
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](../../medusa/interfaces/medusa.FindConfig.mdx)&#60;[ShippingOption](../../entities/classes/entities.ShippingOption.mdx)&#62;","description":"the options to get a profile","optional":false,"defaultValue":"{}","expandable":false,"children":[]}]} sectionTitle="retrieve"/>
#### Returns
<ParameterTypes parameters={[{"name":"Promise","type":"Promise&#60;[ShippingOption](../../entities/classes/entities.ShippingOption.mdx)&#62;","optional":false,"defaultValue":"","description":"the profile document.","expandable":false,"children":[]}]} sectionTitle="retrieve"/>
### updateShippingMethod
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`","description":"the values to update the method with","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="updateShippingMethod"/>
#### Returns
<ParameterTypes parameters={[{"name":"Promise","type":"Promise&#60;undefined \\| [ShippingMethod](../../entities/classes/entities.ShippingMethod.mdx)&#62;","optional":false,"defaultValue":"","description":"the resulting shipping method","expandable":false,"children":[]}]} sectionTitle="updateShippingMethod"/>
### deleteShippingMethods
Removes a given shipping method
#### Parameters
<ParameterTypes parameters={[{"name":"shippingMethods","type":"[ShippingMethod](../../entities/classes/entities.ShippingMethod.mdx) \\| [ShippingMethod](../../entities/classes/entities.ShippingMethod.mdx)[]","description":"the shipping method to remove","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="deleteShippingMethods"/>
#### Returns
<ParameterTypes parameters={[{"name":"Promise","type":"Promise&#60;[ShippingMethod](../../entities/classes/entities.ShippingMethod.mdx)[]&#62;","optional":false,"defaultValue":"","description":"removed shipping methods","expandable":false,"children":[]}]} sectionTitle="deleteShippingMethods"/>
### createShippingMethod
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`","description":"the cart to create the shipping method for.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="createShippingMethod"/>
#### Returns
<ParameterTypes parameters={[{"name":"Promise","type":"Promise&#60;[ShippingMethod](../../entities/classes/entities.ShippingMethod.mdx)&#62;","optional":false,"defaultValue":"","description":"the resulting shipping method.","expandable":false,"children":[]}]} sectionTitle="createShippingMethod"/>
### validateCartOption
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](../../entities/classes/entities.ShippingOption.mdx)","description":"the option object to check","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"cart","type":"[Cart](../../entities/classes/entities.Cart.mdx)","description":"the cart object to check against","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="validateCartOption"/>
#### Returns
<ParameterTypes parameters={[{"name":"Promise","type":"Promise&#60;null \\| [ShippingOption](../../entities/classes/entities.ShippingOption.mdx)&#62;","optional":false,"defaultValue":"","description":"the validated shipping option","expandable":false,"children":[]}]} sectionTitle="validateCartOption"/>
### validateAndMutatePrice
#### Parameters
<ParameterTypes parameters={[{"name":"option","type":"[ShippingOption](../../entities/classes/entities.ShippingOption.mdx) \\| `CreateShippingOptionInput`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"priceInput","type":"`ValidatePriceTypeAndAmountInput`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="validateAndMutatePrice"/>
#### Returns
<ParameterTypes parameters={[{"name":"Promise","type":"Promise&#60;CreateShippingOptionInput \\| Omit&#60;[ShippingOption](../../entities/classes/entities.ShippingOption.mdx), \"beforeInsert\"&#62;&#62;","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]} sectionTitle="validateAndMutatePrice"/>
### create
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`","description":"the data to create shipping options","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="create"/>
#### Returns
<ParameterTypes parameters={[{"name":"Promise","type":"Promise&#60;[ShippingOption](../../entities/classes/entities.ShippingOption.mdx)&#62;","optional":false,"defaultValue":"","description":"the result of the create operation","expandable":false,"children":[]}]} sectionTitle="create"/>
### validatePriceType\_
Validates a shipping option price
#### Parameters
<ParameterTypes parameters={[{"name":"priceType","type":"[ShippingOptionPriceType](../../entities/enums/entities.ShippingOptionPriceType.mdx)","description":"the price to validate","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"option","type":"[ShippingOption](../../entities/classes/entities.ShippingOption.mdx)","description":"the option to validate against","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="validatePriceType_"/>
#### Returns
<ParameterTypes parameters={[{"name":"Promise","type":"Promise&#60;[ShippingOptionPriceType](../../entities/enums/entities.ShippingOptionPriceType.mdx)&#62;","optional":false,"defaultValue":"","description":"the validated price","expandable":false,"children":[]}]} sectionTitle="validatePriceType_"/>
### update
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\n can be casted to an ObjectId","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"update","type":"`UpdateShippingOptionInput`","description":"an object with the update values.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="update"/>
#### Returns
<ParameterTypes parameters={[{"name":"Promise","type":"Promise&#60;[ShippingOption](../../entities/classes/entities.ShippingOption.mdx)&#62;","optional":false,"defaultValue":"","description":"resolves to the update result.","expandable":false,"children":[]}]} sectionTitle="update"/>
### delete
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\n castable as an ObjectId","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="delete"/>
#### Returns
<ParameterTypes parameters={[{"name":"Promise","type":"Promise&#60;void \\| [ShippingOption](../../entities/classes/entities.ShippingOption.mdx)&#62;","optional":false,"defaultValue":"","description":"the result of the delete operation.","expandable":false,"children":[]}]} sectionTitle="delete"/>
### addRequirement
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](../../entities/classes/entities.ShippingOptionRequirement.mdx)","description":"the requirement for the option.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="addRequirement"/>
#### Returns
<ParameterTypes parameters={[{"name":"Promise","type":"Promise&#60;[ShippingOption](../../entities/classes/entities.ShippingOption.mdx)&#62;","optional":false,"defaultValue":"","description":"the result of update","expandable":false,"children":[]}]} sectionTitle="addRequirement"/>
### removeRequirement
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":[]}]} sectionTitle="removeRequirement"/>
#### Returns
<ParameterTypes parameters={[{"name":"Promise","type":"Promise&#60;void \\| [ShippingOptionRequirement](../../entities/classes/entities.ShippingOptionRequirement.mdx)&#62;","optional":false,"defaultValue":"","description":"the result of update","expandable":false,"children":[]}]} sectionTitle="removeRequirement"/>
### updateShippingProfile
#### 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":[]}]} sectionTitle="updateShippingProfile"/>
#### Returns
<ParameterTypes parameters={[{"name":"Promise","type":"Promise&#60;[ShippingOption](../../entities/classes/entities.ShippingOption.mdx)[]&#62;","optional":false,"defaultValue":"","description":"updated shipping options","expandable":false,"children":[]}]} sectionTitle="updateShippingProfile"/>
### getPrice\_
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](../../entities/classes/entities.ShippingOption.mdx)","description":"the shipping option to retrieve the price\n 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](../../entities/classes/entities.Order.mdx) \\| [Cart](../../entities/classes/entities.Cart.mdx)","description":"the context in which the price should be\n retrieved.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="getPrice_"/>
#### Returns
<ParameterTypes parameters={[{"name":"Promise","type":"Promise&#60;number&#62;","optional":false,"defaultValue":"","description":"the price of the shipping option.","expandable":false,"children":[]}]} sectionTitle="getPrice_"/>