--- displayed_sidebar: servicesSidebar --- import ParameterTypes from "@site/src/components/ParameterTypes" # ShippingOptionService Provides layer to manipulate profiles. ## Constructors ### constructor `**new ShippingOptionService**(«destructured»)` #### Parameters ## Properties `", "description": "", "optional": true, "defaultValue": "", "expandable": false, "children": [] }, { "name": "__container__", "type": "`any`", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "__moduleDeclaration__", "type": "`Record`", "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 ## 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 #### Returns Promise<[ShippingOption](ShippingOption.mdx)> ___ ### atomicPhase\_ `Protected **atomicPhase_**(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. #### Parameters 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> ___ ### 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 #### Returns Promise<[ShippingOption](ShippingOption.mdx)> ___ ### createShippingMethod `**createShippingMethod**(optionId, data, config): Promise<[ShippingMethod](ShippingMethod.mdx)>` Creates a shipping method for a given cart. #### Parameters `", "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)> ___ ### delete `**delete**(optionId): Promise<void \| [ShippingOption](ShippingOption.mdx)>` Deletes a profile with a given profile id. #### Parameters #### Returns Promise<void \| [ShippingOption](ShippingOption.mdx)> ___ ### deleteShippingMethods `**deleteShippingMethods**(shippingMethods): Promise<[ShippingMethod](ShippingMethod.mdx)[]>` Removes a given shipping method #### Parameters #### Returns Promise<[ShippingMethod](ShippingMethod.mdx)[]> ___ ### 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 `", "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> ___ ### list `**list**(selector, config?): Promise<[ShippingOption](ShippingOption.mdx)[]>` #### Parameters #### Returns Promise<[ShippingOption](ShippingOption.mdx)[]> ___ ### listAndCount `**listAndCount**(selector, config?): Promise<[[ShippingOption](ShippingOption.mdx)[], number]>` #### Parameters #### Returns Promise<[[ShippingOption](ShippingOption.mdx)[], number]> ___ ### removeRequirement `**removeRequirement**(requirementId): Promise<void \| [ShippingOptionRequirement](ShippingOptionRequirement.mdx)>` Removes a requirement from a shipping option #### Parameters #### Returns Promise<void \| [ShippingOptionRequirement](ShippingOptionRequirement.mdx)> ___ ### 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 #### Returns Promise<[ShippingOption](ShippingOption.mdx)> ___ ### shouldRetryTransaction\_ `Protected **shouldRetryTransaction_**(err): boolean` #### Parameters ` \\| `{ code: string }`", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] } ]} /> #### Returns `boolean` ___ ### 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 #### Returns Promise<[ShippingOption](ShippingOption.mdx)> ___ ### 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 #### Returns Promise<undefined \| [ShippingMethod](ShippingMethod.mdx)> ___ ### updateShippingProfile `**updateShippingProfile**(optionIds, profileId): Promise<[ShippingOption](ShippingOption.mdx)[]>` #### Parameters #### Returns Promise<[ShippingOption](ShippingOption.mdx)[]> ___ ### validateAndMutatePrice `Private **validateAndMutatePrice**(option, priceInput): Promise<[CreateShippingOptionInput](../types/CreateShippingOptionInput.mdx) \| [Omit](../types/Omit.mdx)<[ShippingOption](ShippingOption.mdx), `"beforeInsert"`>>` #### Parameters #### Returns Promise<[CreateShippingOptionInput](../types/CreateShippingOptionInput.mdx) \| [Omit](../types/Omit.mdx)<[ShippingOption](ShippingOption.mdx), `"beforeInsert"`>> ___ ### 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 #### Returns Promise<`null` \| [ShippingOption](ShippingOption.mdx)> ___ ### validatePriceType\_ `**validatePriceType_**(priceType, option): Promise<[ShippingOptionPriceType](../enums/ShippingOptionPriceType.mdx)>` Validates a shipping option price #### Parameters #### Returns Promise<[ShippingOptionPriceType](../enums/ShippingOptionPriceType.mdx)> ___ ### validateRequirement\_ `**validateRequirement_**(requirement, optionId?): Promise<[ShippingOptionRequirement](ShippingOptionRequirement.mdx)>` Validates a requirement #### Parameters #### Returns Promise<[ShippingOptionRequirement](ShippingOptionRequirement.mdx)> ___ ### withTransaction `**withTransaction**(transactionManager?): [ShippingOptionService](ShippingOptionService.mdx)` #### Parameters #### Returns [ShippingOptionService](ShippingOptionService.mdx)