Skip to content

Commit

Permalink
docs: Improve docs on some new strategies
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbromley committed Dec 18, 2024
1 parent f297dc4 commit 94aa0c7
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 41 deletions.
3 changes: 2 additions & 1 deletion docs/docs/guides/core-concepts/taxes/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ In your storefront, you can therefore choose whether to display the prices with
When a customer adds an item to the Order, the following logic takes place:

1. The price of the item, and whether that price is inclusive of tax, is determined according to the configured [OrderItemPriceCalculationStrategy](/reference/typescript-api/orders/order-item-price-calculation-strategy/).
2. The active tax Zone is determined based on the configured [TaxZoneStrategy](/reference/typescript-api/tax/tax-zone-strategy/).
2. The active tax Zone is determined based on the configured [TaxZoneStrategy](/reference/typescript-api/tax/tax-zone-strategy/). By default, Vendure will use the default tax Zone from the Channel settings.
However, you often want to use the customer's address as the basis for determining the tax Zone. In this case, you should use the [AddressBasedTaxZoneStrategy](/reference/typescript-api/tax/address-based-tax-zone-strategy).
3. The applicable TaxRate is fetched based on the ProductVariant's TaxCategory and the active tax Zone determined in step 1.
4. The `TaxLineCalculationStrategy.calculate()` of the configured [TaxLineCalculationStrategy](/reference/typescript-api/tax/tax-line-calculation-strategy/) is called, which will return one or more [TaxLines](/reference/graphql-api/admin/object-types/#taxline).
5. The final `priceWithTax` of the order line is calculated based on all the above.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ does not take channels into account, update your VendureConfig to use to <a href

```ts title="Signature"
class MultiChannelStockLocationStrategy extends BaseStockLocationStrategy {
protected cacheService: CacheService;
protected channelIdCache: Cache;
protected eventBus: EventBus;
protected globalSettingsService: GlobalSettingsService;
protected requestContextCache: RequestContextCacheService;
getAvailableStock(ctx: RequestContext, productVariantId: ID, stockLevels: StockLevel[]) => Promise<AvailableStock>;
forAllocation(ctx: RequestContext, stockLocations: StockLocation[], orderLine: OrderLine, quantity: number) => Promise<LocationWithQuantity[]>;
}
Expand All @@ -38,31 +33,6 @@ class MultiChannelStockLocationStrategy extends BaseStockLocationStrategy {

<div className="members-wrapper">

### cacheService

<MemberInfo kind="property" type={`<a href='/reference/typescript-api/cache/cache-service#cacheservice'>CacheService</a>`} />


### channelIdCache

<MemberInfo kind="property" type={`<a href='/reference/typescript-api/cache/#cache'>Cache</a>`} />


### eventBus

<MemberInfo kind="property" type={`<a href='/reference/typescript-api/events/event-bus#eventbus'>EventBus</a>`} />


### globalSettingsService

<MemberInfo kind="property" type={`<a href='/reference/typescript-api/services/global-settings-service#globalsettingsservice'>GlobalSettingsService</a>`} />


### requestContextCache

<MemberInfo kind="property" type={`<a href='/reference/typescript-api/cache/request-context-cache-service#requestcontextcacheservice'>RequestContextCacheService</a>`} />


### getAvailableStock

<MemberInfo kind="method" type={`(ctx: <a href='/reference/typescript-api/request/request-context#requestcontext'>RequestContext</a>, productVariantId: <a href='/reference/typescript-api/common/id#id'>ID</a>, stockLevels: <a href='/reference/typescript-api/entities/stock-level#stocklevel'>StockLevel</a>[]) => Promise&#60;<a href='/reference/typescript-api/products-stock/stock-location-strategy#availablestock'>AvailableStock</a>&#62;`} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,33 @@ import MemberDescription from '@site/src/components/MemberDescription';

## AddressBasedTaxZoneStrategy

<GenerationInfo sourceFile="packages/core/src/config/tax/address-based-tax-zone-strategy.ts" sourceLine="27" packageName="@vendure/core" since="3.1.0
<GenerationInfo sourceFile="packages/core/src/config/tax/address-based-tax-zone-strategy.ts" sourceLine="39" packageName="@vendure/core" since="3.1.0" />

Address based <a href='/reference/typescript-api/tax/tax-zone-strategy#taxzonestrategy'>TaxZoneStrategy</a> which tries to find the applicable <a href='/reference/typescript-api/entities/zone#zone'>Zone</a> based on the
country of the billing address, or else the country of the shipping address of the Order.

Returns the default <a href='/reference/typescript-api/entities/channel#channel'>Channel</a>'s default tax zone if no applicable zone is found.

:::info

This is configured via `taxOptions.taxZoneStrategy = new AddressBasedTaxZoneStrategy()` in
your VendureConfig.

:::" />
:::

Address based <a href='/reference/typescript-api/tax/tax-zone-strategy#taxzonestrategy'>TaxZoneStrategy</a> which tries to find the applicable <a href='/reference/typescript-api/entities/zone#zone'>Zone</a> based on the
country of the billing address, or else the country of the shipping address of the Order.
*Example*

Returns the default <a href='/reference/typescript-api/entities/channel#channel'>Channel</a>'s default tax zone if no applicable zone is found.
```ts
import { VendureConfig, AddressBasedTaxZoneStrategy } from '@vendure/core';

export const config: VendureConfig = {
// other options...
taxOptions: {
// highlight-next-line
taxZoneStrategy: new AddressBasedTaxZoneStrategy(),
},
};
```

```ts title="Signature"
class AddressBasedTaxZoneStrategy implements TaxZoneStrategy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ import MemberDescription from '@site/src/components/MemberDescription';

## DefaultTaxZoneStrategy

<GenerationInfo sourceFile="packages/core/src/config/tax/default-tax-zone-strategy.ts" sourceLine="12" packageName="@vendure/core" />
<GenerationInfo sourceFile="packages/core/src/config/tax/default-tax-zone-strategy.ts" sourceLine="15" packageName="@vendure/core" />

A default method of determining Zone for tax calculations.
A default method of determining Zone for tax calculations. The strategy simply returns the default
tax zone of the Channel. In many cases you actually want to base the tax zone
on the shipping or billing address of the Order, in which case you would use the
<a href='/reference/typescript-api/tax/address-based-tax-zone-strategy#addressbasedtaxzonestrategy'>AddressBasedTaxZoneStrategy</a>.

```ts title="Signature"
class DefaultTaxZoneStrategy implements TaxZoneStrategy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,15 @@ import { AvailableStock, LocationWithQuantity, StockLocationStrategy } from './s
* @since 3.1.0
*/
export class MultiChannelStockLocationStrategy extends BaseStockLocationStrategy {
/** @internal */
protected cacheService: CacheService;
/** @internal */
protected channelIdCache: Cache;
/** @internal */
protected eventBus: EventBus;
/** @internal */
protected globalSettingsService: GlobalSettingsService;
/** @internal */
protected requestContextCache: RequestContextCacheService;

/** @internal */
Expand Down
16 changes: 14 additions & 2 deletions packages/core/src/config/tax/address-based-tax-zone-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,27 @@ const loggerCtx = 'AddressBasedTaxZoneStrategy';
*
* Returns the default {@link Channel}'s default tax zone if no applicable zone is found.
*
* @since 3.1.0
*
* :::info
*
* This is configured via `taxOptions.taxZoneStrategy = new AddressBasedTaxZoneStrategy()` in
* your VendureConfig.
*
* :::
*
* @example
* ```ts
* import { VendureConfig, AddressBasedTaxZoneStrategy } from '\@vendure/core';
*
* export const config: VendureConfig = {
* // other options...
* taxOptions: {
* // highlight-next-line
* taxZoneStrategy: new AddressBasedTaxZoneStrategy(),
* },
* };
* ```
*
* @since 3.1.0
* @docsCategory tax
*/
export class AddressBasedTaxZoneStrategy implements TaxZoneStrategy {
Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/config/tax/default-tax-zone-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import { TaxZoneStrategy } from './tax-zone-strategy';

/**
* @description
* A default method of determining Zone for tax calculations.
* A default method of determining Zone for tax calculations. The strategy simply returns the default
* tax zone of the Channel. In many cases you actually want to base the tax zone
* on the shipping or billing address of the Order, in which case you would use the
* {@link AddressBasedTaxZoneStrategy}.
*
* @docsCategory tax
*/
Expand Down

0 comments on commit 94aa0c7

Please sign in to comment.