Browse Source

docs: Improve docs on some new strategies

Michael Bromley 1 year ago
parent
commit
94aa0c7e86

+ 2 - 1
docs/docs/guides/core-concepts/taxes/index.mdx

@@ -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:
 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/).
 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.
 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).
 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.
 5. The final `priceWithTax` of the order line is calculated based on all the above.

+ 0 - 30
docs/docs/reference/typescript-api/products-stock/multi-channel-stock-location-strategy.md

@@ -23,11 +23,6 @@ does not take channels into account, update your VendureConfig to use to <a href
 
 
 ```ts title="Signature"
 ```ts title="Signature"
 class MultiChannelStockLocationStrategy extends BaseStockLocationStrategy {
 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>;
     getAvailableStock(ctx: RequestContext, productVariantId: ID, stockLevels: StockLevel[]) => Promise<AvailableStock>;
     forAllocation(ctx: RequestContext, stockLocations: StockLocation[], orderLine: OrderLine, quantity: number) => Promise<LocationWithQuantity[]>;
     forAllocation(ctx: RequestContext, stockLocations: StockLocation[], orderLine: OrderLine, quantity: number) => Promise<LocationWithQuantity[]>;
 }
 }
@@ -38,31 +33,6 @@ class MultiChannelStockLocationStrategy extends BaseStockLocationStrategy {
 
 
 <div className="members-wrapper">
 <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
 ### 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;`}   />
 <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;`}   />

+ 19 - 5
docs/docs/reference/typescript-api/tax/address-based-tax-zone-strategy.md

@@ -11,19 +11,33 @@ import MemberDescription from '@site/src/components/MemberDescription';
 
 
 ## AddressBasedTaxZoneStrategy
 ## 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
 :::info
 
 
 This is configured via `taxOptions.taxZoneStrategy = new AddressBasedTaxZoneStrategy()` in
 This is configured via `taxOptions.taxZoneStrategy = new AddressBasedTaxZoneStrategy()` in
 your VendureConfig.
 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"
 ```ts title="Signature"
 class AddressBasedTaxZoneStrategy implements TaxZoneStrategy {
 class AddressBasedTaxZoneStrategy implements TaxZoneStrategy {

+ 5 - 2
docs/docs/reference/typescript-api/tax/default-tax-zone-strategy.md

@@ -11,9 +11,12 @@ import MemberDescription from '@site/src/components/MemberDescription';
 
 
 ## DefaultTaxZoneStrategy
 ## 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"
 ```ts title="Signature"
 class DefaultTaxZoneStrategy implements TaxZoneStrategy {
 class DefaultTaxZoneStrategy implements TaxZoneStrategy {

+ 5 - 0
packages/core/src/config/catalog/multi-channel-stock-location-strategy.ts

@@ -30,10 +30,15 @@ import { AvailableStock, LocationWithQuantity, StockLocationStrategy } from './s
  * @since 3.1.0
  * @since 3.1.0
  */
  */
 export class MultiChannelStockLocationStrategy extends BaseStockLocationStrategy {
 export class MultiChannelStockLocationStrategy extends BaseStockLocationStrategy {
+    /** @internal */
     protected cacheService: CacheService;
     protected cacheService: CacheService;
+    /** @internal */
     protected channelIdCache: Cache;
     protected channelIdCache: Cache;
+    /** @internal */
     protected eventBus: EventBus;
     protected eventBus: EventBus;
+    /** @internal */
     protected globalSettingsService: GlobalSettingsService;
     protected globalSettingsService: GlobalSettingsService;
+    /** @internal */
     protected requestContextCache: RequestContextCacheService;
     protected requestContextCache: RequestContextCacheService;
 
 
     /** @internal */
     /** @internal */

+ 14 - 2
packages/core/src/config/tax/address-based-tax-zone-strategy.ts

@@ -13,8 +13,6 @@ const loggerCtx = 'AddressBasedTaxZoneStrategy';
  *
  *
  * Returns the default {@link Channel}'s default tax zone if no applicable zone is found.
  * Returns the default {@link Channel}'s default tax zone if no applicable zone is found.
  *
  *
- * @since 3.1.0
- *
  * :::info
  * :::info
  *
  *
  * This is configured via `taxOptions.taxZoneStrategy = new AddressBasedTaxZoneStrategy()` in
  * This is configured via `taxOptions.taxZoneStrategy = new AddressBasedTaxZoneStrategy()` in
@@ -22,6 +20,20 @@ const loggerCtx = 'AddressBasedTaxZoneStrategy';
  *
  *
  * :::
  * :::
  *
  *
+ * @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
  * @docsCategory tax
  */
  */
 export class AddressBasedTaxZoneStrategy implements TaxZoneStrategy {
 export class AddressBasedTaxZoneStrategy implements TaxZoneStrategy {

+ 4 - 1
packages/core/src/config/tax/default-tax-zone-strategy.ts

@@ -5,7 +5,10 @@ import { TaxZoneStrategy } from './tax-zone-strategy';
 
 
 /**
 /**
  * @description
  * @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
  * @docsCategory tax
  */
  */