* update dependencies * update onboarding mdx * fixes for mdx issues * fixes for mdx compatibility * resolve mdx errors * fixes in reference * fix check errors * revert change in vale action * fix node version in action * fix summary in markdown
1442 lines
30 KiB
Plaintext
1442 lines
30 KiB
Plaintext
---
|
|
displayed_sidebar: servicesSidebar
|
|
---
|
|
|
|
import ParameterTypes from "@site/src/components/ParameterTypes"
|
|
|
|
# TotalsService
|
|
|
|
A service that calculates total and subtotals for orders, carts etc..
|
|
|
|
#### Implements
|
|
|
|
## Constructors
|
|
|
|
### constructor
|
|
|
|
`**new TotalsService**(«destructured»)`
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "__namedParameters",
|
|
"type": "[TotalsServiceProps](../types/TotalsServiceProps.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": "newTotalsService_",
|
|
"type": "[NewTotalsService](NewTotalsService.mdx)",
|
|
"description": "",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "taxCalculationStrategy_",
|
|
"type": "[ITaxCalculationStrategy](../interfaces/ITaxCalculationStrategy.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 get**activeManager_**(): EntityManager`
|
|
|
|
#### Returns
|
|
|
|
EntityManager
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "EntityManager",
|
|
"type": "EntityManager",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"description": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
## Methods
|
|
|
|
### atomicPhase\_
|
|
|
|
`Protected **atomicPhase_**<TypeParameter TResult, TypeParameter 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": []
|
|
}
|
|
]} />
|
|
|
|
___
|
|
|
|
### calculateDiscount\_
|
|
|
|
`**calculateDiscount_**(lineItem, variant, variantPrice, value, discountType): [LineDiscount](../types/LineDiscount.mdx)`
|
|
|
|
Calculates either fixed or percentage discount of a variant
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "lineItem",
|
|
"type": "[LineItem](LineItem.mdx)",
|
|
"description": "id of line item",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "variant",
|
|
"type": "`string`",
|
|
"description": "id of variant in line item",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "variantPrice",
|
|
"type": "`number`",
|
|
"description": "price of the variant based on region",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "value",
|
|
"type": "`number`",
|
|
"description": "discount value",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "discountType",
|
|
"type": "[DiscountRuleType](../enums/DiscountRuleType.mdx)",
|
|
"description": "the type of discount (fixed or percentage)",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
[LineDiscount](../types/LineDiscount.mdx)
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "LineDiscount",
|
|
"type": "`object`",
|
|
"description": "Associates a line item and discount allocation.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Deprecated
|
|
|
|
- in favour of DiscountService.calculateDiscountForLineItem
|
|
|
|
___
|
|
|
|
### getAllocationItemDiscounts
|
|
|
|
`**getAllocationItemDiscounts**(discount, cart): [LineDiscount](../types/LineDiscount.mdx)[]`
|
|
|
|
If the rule of a discount has allocation="item", then we need
|
|
to calculate discount on each item in the cart. Furthermore, we need to
|
|
make sure to only apply the discount on valid variants. And finally we
|
|
return ether an array of percentages discounts or fixed discounts
|
|
alongside the variant on which the discount was applied.
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "discount",
|
|
"type": "[Discount](Discount.mdx)",
|
|
"description": "the discount to which we do the calculation",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "cart",
|
|
"type": "[Order](Order.mdx) \\| [Cart](Cart.mdx)",
|
|
"description": "the cart to calculate discounts for",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
[LineDiscount](../types/LineDiscount.mdx)[]
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "LineDiscount[]",
|
|
"type": "[LineDiscount](../types/LineDiscount.mdx)[]",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"description": "array of triples of lineitem, variant and applied discount",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
___
|
|
|
|
### getAllocationMap
|
|
|
|
`**getAllocationMap**(orderOrCart, options?): Promise<[LineAllocationsMap](../types/LineAllocationsMap.mdx)>`
|
|
|
|
Gets a map of discounts and gift cards that apply to line items in an
|
|
order. The function calculates the amount of a discount or gift card that
|
|
applies to a specific line item.
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "orderOrCart",
|
|
"type": "`object`",
|
|
"description": "the order or cart to get an allocation map for",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "orderOrCart.claims",
|
|
"type": "[ClaimOrder](ClaimOrder.mdx)[]",
|
|
"description": "",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "orderOrCart.discounts",
|
|
"type": "[Discount](Discount.mdx)[]",
|
|
"description": "",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "orderOrCart.items",
|
|
"type": "[LineItem](LineItem.mdx)[]",
|
|
"description": "",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "orderOrCart.swaps",
|
|
"type": "[Swap](Swap.mdx)[]",
|
|
"description": "",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "options",
|
|
"type": "[AllocationMapOptions](../types/AllocationMapOptions.mdx)",
|
|
"description": "controls what should be included in allocation map",
|
|
"optional": false,
|
|
"defaultValue": "{}",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
Promise<[LineAllocationsMap](../types/LineAllocationsMap.mdx)>
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "Promise",
|
|
"type": "Promise<[LineAllocationsMap](../types/LineAllocationsMap.mdx)>",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"description": "the allocation map for the line items in the cart or order.",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
___
|
|
|
|
### getCalculationContext
|
|
|
|
`**getCalculationContext**(calculationContextData, options?): Promise<[TaxCalculationContext](../types/TaxCalculationContext.mdx)>`
|
|
|
|
Prepares the calculation context for a tax total calculation.
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "calculationContextData",
|
|
"type": "[CalculationContextData](../types/CalculationContextData.mdx)",
|
|
"description": "the calculationContextData to get the calculation context for",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "options",
|
|
"type": "[CalculationContextOptions](../types/CalculationContextOptions.mdx)",
|
|
"description": "options to gather context by",
|
|
"optional": false,
|
|
"defaultValue": "{}",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
Promise<[TaxCalculationContext](../types/TaxCalculationContext.mdx)>
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "Promise",
|
|
"type": "Promise<[TaxCalculationContext](../types/TaxCalculationContext.mdx)>",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"description": "the tax calculation context",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
___
|
|
|
|
### getDiscountTotal
|
|
|
|
`**getDiscountTotal**(cartOrOrder): Promise<number>`
|
|
|
|
Calculates the total discount amount for each of the different supported
|
|
discount types. If discounts aren't present or invalid returns 0.
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "cartOrOrder",
|
|
"type": "[Order](Order.mdx) \\| [Cart](Cart.mdx)",
|
|
"description": "the cart or order to calculate discounts for",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
Promise<number>
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "Promise",
|
|
"type": "Promise<number>",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"description": "the total discounts amount",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
___
|
|
|
|
### getGiftCardTotal
|
|
|
|
`**getGiftCardTotal**(cartOrOrder, opts?): Promise<{ tax_total: number ; total: number }>`
|
|
|
|
Gets the gift card amount on a cart or order.
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "cartOrOrder",
|
|
"type": "[Order](Order.mdx) \\| [Cart](Cart.mdx)",
|
|
"description": "the cart or order to get gift card amount for",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "opts",
|
|
"type": "`object`",
|
|
"description": "",
|
|
"optional": false,
|
|
"defaultValue": "{}",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "opts.gift_cardable",
|
|
"type": "`number`",
|
|
"description": "",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
Promise<{ tax_total: number ; total: number }>
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "Promise",
|
|
"type": "Promise<{ tax_total: number ; total: number }>",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"description": "the gift card amount applied to the cart or order",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
___
|
|
|
|
### getGiftCardableAmount
|
|
|
|
`**getGiftCardableAmount**(cartOrOrder): Promise<number>`
|
|
|
|
Gets the amount that can be gift carded on a cart. In regions where gift
|
|
cards are taxable this amount should exclude taxes.
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "cartOrOrder",
|
|
"type": "[Order](Order.mdx) \\| [Cart](Cart.mdx)",
|
|
"description": "the cart or order to get gift card amount for",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
Promise<number>
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "Promise",
|
|
"type": "Promise<number>",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"description": "the gift card amount applied to the cart or order",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
___
|
|
|
|
### getLineDiscounts
|
|
|
|
`**getLineDiscounts**(cartOrOrder, discount?): [LineDiscountAmount](../types/LineDiscountAmount.mdx)[]`
|
|
|
|
Returns the discount amount allocated to the line items of an order.
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "cartOrOrder",
|
|
"type": "`object`",
|
|
"description": "the cart or order to get line discount allocations for",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "cartOrOrder.claims",
|
|
"type": "[ClaimOrder](ClaimOrder.mdx)[]",
|
|
"description": "",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "cartOrOrder.items",
|
|
"type": "[LineItem](LineItem.mdx)[]",
|
|
"description": "",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "cartOrOrder.swaps",
|
|
"type": "[Swap](Swap.mdx)[]",
|
|
"description": "",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "discount",
|
|
"type": "[Discount](Discount.mdx)",
|
|
"description": "the discount to use as context for the calculation",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
[LineDiscountAmount](../types/LineDiscountAmount.mdx)[]
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "LineDiscountAmount[]",
|
|
"type": "[LineDiscountAmount](../types/LineDiscountAmount.mdx)[]",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"description": "the allocations that the discount has on the items in the cart or\n order",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
___
|
|
|
|
### getLineItemAdjustmentsTotal
|
|
|
|
`**getLineItemAdjustmentsTotal**(cartOrOrder): number`
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "cartOrOrder",
|
|
"type": "[Order](Order.mdx) \\| [Cart](Cart.mdx)",
|
|
"description": "",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
`number`
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "number",
|
|
"type": "`number`",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"description": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
___
|
|
|
|
### getLineItemDiscountAdjustment
|
|
|
|
`**getLineItemDiscountAdjustment**(lineItem, discount): number`
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "lineItem",
|
|
"type": "[LineItem](LineItem.mdx)",
|
|
"description": "Line Items are created when a product is added to a Cart. When Line Items are purchased they will get copied to the resulting order, swap, or claim, and can eventually be referenced in Fulfillments and Returns. Line items may also be used for order edits.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "discount",
|
|
"type": "[Discount](Discount.mdx)",
|
|
"description": "A discount can be applied to a cart for promotional purposes.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
`number`
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "number",
|
|
"type": "`number`",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"description": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
___
|
|
|
|
### getLineItemRefund
|
|
|
|
`**getLineItemRefund**(order, lineItem): Promise<number>`
|
|
|
|
The amount that can be refunded for a given line item.
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "order",
|
|
"type": "[Order](Order.mdx)",
|
|
"description": "order to use as context for the calculation",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "lineItem",
|
|
"type": "[LineItem](LineItem.mdx)",
|
|
"description": "the line item to calculate the refund amount for.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
Promise<number>
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "Promise",
|
|
"type": "Promise<number>",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"description": "the line item refund amount.",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
___
|
|
|
|
### getLineItemTotal
|
|
|
|
`**getLineItemTotal**(lineItem, cartOrOrder, options?): Promise<number>`
|
|
|
|
Gets a total for a line item. The total can take gift cards, discounts and
|
|
taxes into account. This can be controlled through the options.
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "lineItem",
|
|
"type": "[LineItem](LineItem.mdx)",
|
|
"description": "the line item to calculate a total for",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "cartOrOrder",
|
|
"type": "[Order](Order.mdx) \\| [Cart](Cart.mdx)",
|
|
"description": "the cart or order to use as context for the calculation",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "options",
|
|
"type": "[GetLineItemTotalOptions](../types/GetLineItemTotalOptions.mdx)",
|
|
"description": "the options to use for the calculation",
|
|
"optional": false,
|
|
"defaultValue": "{}",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
Promise<number>
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "Promise",
|
|
"type": "Promise<number>",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"description": "the line item total",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
___
|
|
|
|
### getLineItemTotals
|
|
|
|
`**getLineItemTotals**(lineItem, cartOrOrder, options?): Promise<[LineItemTotals](../types/LineItemTotals-1.mdx)>`
|
|
|
|
Breaks down the totals related to a line item; these are the subtotal, the
|
|
amount of discount applied to the line item, the amount of a gift card
|
|
applied to a line item and the amount of tax applied to a line item.
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "lineItem",
|
|
"type": "[LineItem](LineItem.mdx)",
|
|
"description": "the line item to calculate totals for",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "cartOrOrder",
|
|
"type": "[Order](Order.mdx) \\| [Cart](Cart.mdx)",
|
|
"description": "the cart or order to use as context for the calculation",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "options",
|
|
"type": "[LineItemTotalsOptions](../types/LineItemTotalsOptions.mdx)",
|
|
"description": "the options to evaluate the line item totals for",
|
|
"optional": false,
|
|
"defaultValue": "{}",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
Promise<[LineItemTotals](../types/LineItemTotals-1.mdx)>
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "Promise",
|
|
"type": "Promise<[LineItemTotals](../types/LineItemTotals-1.mdx)>",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"description": "the breakdown of the line item totals",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
___
|
|
|
|
### getPaidTotal
|
|
|
|
`**getPaidTotal**(order): number`
|
|
|
|
Gets the total payments made on an order
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "order",
|
|
"type": "[Order](Order.mdx)",
|
|
"description": "the order to calculate paid amount for",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
`number`
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "number",
|
|
"type": "`number`",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"description": "the total paid amount",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
___
|
|
|
|
### getRefundTotal
|
|
|
|
`**getRefundTotal**(order, lineItems): Promise<number>`
|
|
|
|
Calculates refund total of line items.
|
|
If any of the items to return have been discounted, we need to
|
|
apply the discount again before refunding them.
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "order",
|
|
"type": "[Order](Order.mdx)",
|
|
"description": "cart or order to calculate subtotal for",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "lineItems",
|
|
"type": "[LineItem](LineItem.mdx)[]",
|
|
"description": "the line items to calculate refund total for",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
Promise<number>
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "Promise",
|
|
"type": "Promise<number>",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"description": "the calculated subtotal",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
___
|
|
|
|
### getRefundedTotal
|
|
|
|
`**getRefundedTotal**(order): number`
|
|
|
|
Gets the total refund amount for an order.
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "order",
|
|
"type": "[Order](Order.mdx)",
|
|
"description": "the order to get total refund amount for.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
`number`
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "number",
|
|
"type": "`number`",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"description": "the total refunded amount for an order.",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
___
|
|
|
|
### getShippingMethodTotals
|
|
|
|
`**getShippingMethodTotals**(shippingMethod, cartOrOrder, opts?): Promise<[ShippingMethodTotals](../types/ShippingMethodTotals-1.mdx)>`
|
|
|
|
Gets the totals breakdown for a shipping method. Fetches tax lines if not
|
|
already provided.
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "shippingMethod",
|
|
"type": "[ShippingMethod](ShippingMethod.mdx)",
|
|
"description": "the shipping method to get totals breakdown for.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "cartOrOrder",
|
|
"type": "[Order](Order.mdx) \\| [Cart](Cart.mdx)",
|
|
"description": "the cart or order to use as context for the breakdown",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "opts",
|
|
"type": "[GetShippingMethodTotalsOptions](../types/GetShippingMethodTotalsOptions.mdx)",
|
|
"description": "options for what should be included",
|
|
"optional": false,
|
|
"defaultValue": "{}",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
Promise<[ShippingMethodTotals](../types/ShippingMethodTotals-1.mdx)>
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "Promise",
|
|
"type": "Promise<[ShippingMethodTotals](../types/ShippingMethodTotals-1.mdx)>",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"description": "An object that breaks down the totals for the shipping method",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
___
|
|
|
|
### getShippingTotal
|
|
|
|
`**getShippingTotal**(cartOrOrder): Promise<number>`
|
|
|
|
Calculates shipping total
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "cartOrOrder",
|
|
"type": "[Order](Order.mdx) \\| [Cart](Cart.mdx)",
|
|
"description": "cart or order to calculate subtotal for",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
Promise<number>
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "Promise",
|
|
"type": "Promise<number>",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"description": "shipping total",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
___
|
|
|
|
### getSubtotal
|
|
|
|
`**getSubtotal**(cartOrOrder, opts?): Promise<number>`
|
|
|
|
Calculates subtotal of a given cart or order.
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "cartOrOrder",
|
|
"type": "[Order](Order.mdx) \\| [Cart](Cart.mdx)",
|
|
"description": "cart or order to calculate subtotal for",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "opts",
|
|
"type": "[SubtotalOptions](../types/SubtotalOptions.mdx)",
|
|
"description": "options",
|
|
"optional": false,
|
|
"defaultValue": "{}",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
Promise<number>
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "Promise",
|
|
"type": "Promise<number>",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"description": "the calculated subtotal",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
___
|
|
|
|
### getSwapTotal
|
|
|
|
`**getSwapTotal**(order): number`
|
|
|
|
The total paid for swaps. May be negative in case of negative swap
|
|
difference.
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "order",
|
|
"type": "[Order](Order.mdx)",
|
|
"description": "the order to calculate swap total for",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
`number`
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "number",
|
|
"type": "`number`",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"description": "the swap total",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
___
|
|
|
|
### getTaxTotal
|
|
|
|
`**getTaxTotal**(cartOrOrder, forceTaxes?): Promise<`null` \| number>`
|
|
|
|
Calculates tax total
|
|
Currently based on the Danish tax system
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "cartOrOrder",
|
|
"type": "[Order](Order.mdx) \\| [Cart](Cart.mdx)",
|
|
"description": "cart or order to calculate tax total for",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "forceTaxes",
|
|
"type": "`boolean`",
|
|
"description": "whether taxes should be calculated regardless of region settings",
|
|
"optional": false,
|
|
"defaultValue": "false",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
Promise<`null` \| number>
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "Promise",
|
|
"type": "Promise<`null` \\| number>",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"description": "tax total",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
___
|
|
|
|
### getTotal
|
|
|
|
`**getTotal**(cartOrOrder, options?): Promise<number>`
|
|
|
|
Calculates total of a given cart or order.
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "cartOrOrder",
|
|
"type": "[Order](Order.mdx) \\| [Cart](Cart.mdx)",
|
|
"description": "object to calculate total for",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "options",
|
|
"type": "[GetTotalsOptions](../types/GetTotalsOptions.mdx)",
|
|
"description": "options to calculate by",
|
|
"optional": false,
|
|
"defaultValue": "{}",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
Promise<number>
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "Promise",
|
|
"type": "Promise<number>",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"description": "the calculated subtotal",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
___
|
|
|
|
### rounded
|
|
|
|
`**rounded**(value): number`
|
|
|
|
Rounds a number using Math.round.
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "value",
|
|
"type": "`number`",
|
|
"description": "the value to round",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
`number`
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "number",
|
|
"type": "`number`",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"description": "the rounded value",
|
|
"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?): [TotalsService](TotalsService.mdx)`
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "transactionManager",
|
|
"type": "EntityManager",
|
|
"description": "",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
[TotalsService](TotalsService.mdx)
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "TotalsService",
|
|
"type": "[TotalsService](TotalsService.mdx)",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"description": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|