---
title: "ShippingCalculator"
generated: true
---
<GenerationInfo sourceFile="packages/core/src/config/shipping-method/shipping-calculator.ts" sourceLine="48" packageName="@vendure/core" />

The ShippingCalculator is used by a <DocsLink href="/reference/typescript-api/entities/shipping-method#shippingmethod">ShippingMethod</DocsLink> to calculate the price of shipping on a given <DocsLink href="/reference/typescript-api/entities/order#order">Order</DocsLink>.

*Example*

```ts
const flatRateCalculator = new ShippingCalculator({
  code: 'flat-rate-calculator',
  description: [{ languageCode: LanguageCode.en, value: 'Default Flat-Rate Shipping Calculator' }],
  args: {
    rate: {
      type: 'int',
      ui: { component: 'currency-form-input' },
    },
    taxRate: {
      type: 'int',
      ui: { component: 'number-form-input', suffix: '%' },
    },
  },
  calculate: (ctx, order, args) => {
    return {
      price: args.rate,
      taxRate: args.taxRate,
      priceIncludesTax: ctx.channel.pricesIncludeTax,
    };
  },
});
```

```ts title="Signature"
class ShippingCalculator<T extends ConfigArgs = ConfigArgs> extends ConfigurableOperationDef<T> {
    constructor(config: ShippingCalculatorConfig<T>)
}
```
* Extends: <DocsLink href="/reference/typescript-api/configurable-operation-def/#configurableoperationdef">`ConfigurableOperationDef`</DocsLink><T>



<div className="members-wrapper">

### constructor

<MemberInfo kind="method" type={`(config: ShippingCalculatorConfig<T>) => ShippingCalculator`}   />




</div>
<GenerationInfo sourceFile="packages/core/src/config/shipping-method/shipping-calculator.ts" sourceLine="79" packageName="@vendure/core" />

The return value of the <DocsLink href="/reference/typescript-api/shipping/shipping-calculator#calculateshippingfn">CalculateShippingFn</DocsLink>.

```ts title="Signature"
interface ShippingCalculationResult {
    price: number;
    priceIncludesTax: boolean;
    taxRate: number;
    metadata?: Record<string, any>;
}
```

<div className="members-wrapper">

### price

<MemberInfo kind="property" type={`number`}   />

The shipping price without any taxes.
### priceIncludesTax

<MemberInfo kind="property" type={`boolean`}   />

Whether or not the given price already includes taxes.
### taxRate

<MemberInfo kind="property" type={`number`}   />

The tax rate applied to the shipping price.
### metadata

<MemberInfo kind="property" type={`Record<string, any>`}   />

Arbitrary metadata may be returned from the calculation function. This can be used
e.g. to return data on estimated delivery times or any other data which may be
needed in the storefront application when listing eligible shipping methods.


</div>
<GenerationInfo sourceFile="packages/core/src/config/shipping-method/shipping-calculator.ts" sourceLine="119" packageName="@vendure/core" />

A function which implements the specific shipping calculation logic. It takes an <DocsLink href="/reference/typescript-api/entities/order#order">Order</DocsLink> and
an arguments object and should return the shipping price as an integer in cents.

Should return a <DocsLink href="/reference/typescript-api/shipping/shipping-calculator#shippingcalculationresult">ShippingCalculationResult</DocsLink> object.

```ts title="Signature"
type CalculateShippingFn<T extends ConfigArgs> = (
    ctx: RequestContext,
    order: Order,
    args: ConfigArgValues<T>,
    method: ShippingMethod,
) => CalculateShippingFnResult
```
