@vendure/core 3.7.4-master-202610050222 → 3.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config/catalog/default-stock-location-strategy.d.ts +57 -2
- package/dist/config/catalog/default-stock-location-strategy.js +101 -5
- package/dist/config/catalog/default-stock-location-strategy.js.map +1 -1
- package/dist/config/catalog/multi-channel-stock-location-strategy.d.ts +0 -5
- package/dist/config/catalog/multi-channel-stock-location-strategy.js +13 -27
- package/dist/config/catalog/multi-channel-stock-location-strategy.js.map +1 -1
- package/dist/config/order/default-order-process.js +13 -1
- package/dist/config/order/default-order-process.js.map +1 -1
- package/dist/config/order/stock-allocation-strategy.d.ts +4 -0
- package/dist/entity/order-line/order-line.entity.d.ts +3 -29
- package/dist/entity/order-line/order-line.entity.js +20 -66
- package/dist/entity/order-line/order-line.entity.js.map +1 -1
- package/dist/event-bus/events/stock-shortfall-event.d.ts +40 -0
- package/dist/event-bus/events/stock-shortfall-event.js +29 -0
- package/dist/event-bus/events/stock-shortfall-event.js.map +1 -0
- package/dist/event-bus/index.d.ts +1 -0
- package/dist/event-bus/index.js +1 -0
- package/dist/event-bus/index.js.map +1 -1
- package/dist/migration-utils/index.d.ts +0 -1
- package/dist/migration-utils/index.js +1 -3
- package/dist/migration-utils/index.js.map +1 -1
- package/dist/service/helpers/order-modifier/order-modifier.d.ts +15 -2
- package/dist/service/helpers/order-modifier/order-modifier.js +37 -12
- package/dist/service/helpers/order-modifier/order-modifier.js.map +1 -1
- package/dist/service/helpers/utils/stock-lock-order.d.ts +11 -0
- package/dist/service/helpers/utils/stock-lock-order.js +22 -0
- package/dist/service/helpers/utils/stock-lock-order.js.map +1 -0
- package/dist/service/services/product-variant.service.d.ts +9 -2
- package/dist/service/services/product-variant.service.js +18 -2
- package/dist/service/services/product-variant.service.js.map +1 -1
- package/dist/service/services/stock-level.service.d.ts +124 -2
- package/dist/service/services/stock-level.service.js +181 -12
- package/dist/service/services/stock-level.service.js.map +1 -1
- package/dist/service/services/stock-movement.service.d.ts +9 -0
- package/dist/service/services/stock-movement.service.js +143 -50
- package/dist/service/services/stock-movement.service.js.map +1 -1
- package/package.json +2 -2
- package/dist/migration-utils/v3_8_orderline_promotion_rescale.d.ts +0 -57
- package/dist/migration-utils/v3_8_orderline_promotion_rescale.js +0 -232
- package/dist/migration-utils/v3_8_orderline_promotion_rescale.js.map +0 -1
|
@@ -1,19 +1,56 @@
|
|
|
1
1
|
import { ID } from '@vendure/common/lib/shared-types';
|
|
2
|
+
import type { GlobalSettingsService, StockLevelService } from '../../service/index';
|
|
2
3
|
import { RequestContext } from '../../api/common/request-context';
|
|
3
4
|
import { Injector } from '../../common/injector';
|
|
4
5
|
import { TransactionalConnection } from '../../connection/transactional-connection';
|
|
5
6
|
import { OrderLine } from '../../entity/order-line/order-line.entity';
|
|
7
|
+
import { ProductVariant } from '../../entity/product-variant/product-variant.entity';
|
|
6
8
|
import { StockLevel } from '../../entity/stock-level/stock-level.entity';
|
|
7
9
|
import { StockLocation } from '../../entity/stock-location/stock-location.entity';
|
|
8
10
|
import { AvailableStock, LocationWithQuantity, StockLocationStrategy } from './stock-location-strategy';
|
|
9
11
|
export declare abstract class BaseStockLocationStrategy implements StockLocationStrategy {
|
|
10
12
|
protected connection: TransactionalConnection;
|
|
13
|
+
/** @internal */
|
|
14
|
+
protected injector: Injector;
|
|
15
|
+
/** @internal */
|
|
16
|
+
protected globalSettingsService: GlobalSettingsService;
|
|
17
|
+
/** @internal */
|
|
18
|
+
protected stockLevelService: StockLevelService;
|
|
11
19
|
init(injector: Injector): void | Promise<void>;
|
|
12
20
|
abstract getAvailableStock(ctx: RequestContext, productVariantId: ID, stockLevels: StockLevel[]): AvailableStock | Promise<AvailableStock>;
|
|
13
21
|
abstract forAllocation(ctx: RequestContext, stockLocations: StockLocation[], orderLine: OrderLine, quantity: number): LocationWithQuantity[] | Promise<LocationWithQuantity[]>;
|
|
14
22
|
forCancellation(ctx: RequestContext, stockLocations: StockLocation[], orderLine: OrderLine, quantity: number): Promise<LocationWithQuantity[]>;
|
|
15
23
|
forRelease(ctx: RequestContext, stockLocations: StockLocation[], orderLine: OrderLine, quantity: number): Promise<LocationWithQuantity[]>;
|
|
16
24
|
forSale(ctx: RequestContext, stockLocations: StockLocation[], orderLine: OrderLine, quantity: number): Promise<LocationWithQuantity[]>;
|
|
25
|
+
/**
|
|
26
|
+
* GlobalSettingsService and StockLevelService are resolved on first use rather than in
|
|
27
|
+
* `init()`. Both have to be imported dynamically to break a circular dependency, and that is
|
|
28
|
+
* asynchronous, while `init()` has to stay synchronous: it is a documented extension point,
|
|
29
|
+
* so a subclass may override it with a synchronous method, and may call `super.init()`
|
|
30
|
+
* without awaiting it. Resolving here means neither leaves a service unset.
|
|
31
|
+
*/
|
|
32
|
+
protected getGlobalSettingsService(): Promise<GlobalSettingsService>;
|
|
33
|
+
/**
|
|
34
|
+
* See {@link BaseStockLocationStrategy.getGlobalSettingsService} for why this is resolved
|
|
35
|
+
* lazily.
|
|
36
|
+
*/
|
|
37
|
+
protected getStockLevelService(): Promise<StockLevelService>;
|
|
38
|
+
/**
|
|
39
|
+
* A subclass which overrides `init()` must call `super.init(injector)`, as it already had to
|
|
40
|
+
* for `this.connection`. Saying so beats the TypeError that reaching into an unset Injector
|
|
41
|
+
* would otherwise raise.
|
|
42
|
+
*/
|
|
43
|
+
private getInjector;
|
|
44
|
+
/**
|
|
45
|
+
* Resolves the two ProductVariant settings which decide how much of it may be allocated:
|
|
46
|
+
* whether its inventory is tracked at all, and the threshold below which its stock may not
|
|
47
|
+
* fall. Both can defer to the global settings, so both are resolved here rather than read
|
|
48
|
+
* from the ProductVariant directly.
|
|
49
|
+
*/
|
|
50
|
+
protected getVariantStockSettings(ctx: RequestContext, variant: ProductVariant): Promise<{
|
|
51
|
+
inventoryNotTracked: boolean;
|
|
52
|
+
effectiveOutOfStockThreshold: number;
|
|
53
|
+
}>;
|
|
17
54
|
private getLocationsBasedOnAllocations;
|
|
18
55
|
}
|
|
19
56
|
/**
|
|
@@ -23,11 +60,29 @@ export declare abstract class BaseStockLocationStrategy implements StockLocation
|
|
|
23
60
|
* It assumes only a single StockLocation and that all stock is allocated from that location. When
|
|
24
61
|
* more than one StockLocation or Channel is used, it will not behave as expected.
|
|
25
62
|
*
|
|
63
|
+
* Since 3.7.4, `forAllocation()` caps each allocation at the stock the ProductVariant actually has
|
|
64
|
+
* available, read under a write lock. With the default {@link DefaultStockAllocationStrategy} the
|
|
65
|
+
* saleable stock check runs on the transition to `ArrangingPayment` and the allocation runs on the
|
|
66
|
+
* transition to `PaymentSettled`, in a later request, so another Order can take the stock in
|
|
67
|
+
* between. Before 3.7.4 the allocation went through at the full quantity and oversold the variant.
|
|
68
|
+
* Now the Order which loses that race is allocated less than it ordered, and
|
|
69
|
+
* {@link StockShortfallEvent} reports the shortfall. The customer has already paid at that point,
|
|
70
|
+
* and core neither refunds nor cancels the Order: subscribe to the event to decide what to do.
|
|
71
|
+
*
|
|
26
72
|
* @docsCategory products & stock
|
|
27
73
|
* @since 2.0.0
|
|
28
74
|
*/
|
|
29
75
|
export declare class DefaultStockLocationStrategy extends BaseStockLocationStrategy {
|
|
30
|
-
init(injector: Injector): void;
|
|
31
76
|
getAvailableStock(ctx: RequestContext, productVariantId: ID, stockLevels: StockLevel[]): AvailableStock;
|
|
32
|
-
|
|
77
|
+
/**
|
|
78
|
+
* @description
|
|
79
|
+
* Allocates from the first StockLocation, capped at the quantity the ProductVariant still has
|
|
80
|
+
* available: `stockOnHand - stockAllocated - outOfStockThreshold`, summed over every
|
|
81
|
+
* StockLevel of the variant, which is the same figure the saleable stock check uses. The
|
|
82
|
+
* StockLevels are read under a write lock, so a concurrent allocation of the same variant
|
|
83
|
+
* waits and then sees this one's result.
|
|
84
|
+
*
|
|
85
|
+
* @since 3.7.4 - The quantity is capped and the StockLevels are read under a lock
|
|
86
|
+
*/
|
|
87
|
+
forAllocation(ctx: RequestContext, stockLocations: StockLocation[], orderLine: OrderLine, quantity: number): Promise<LocationWithQuantity[]>;
|
|
33
88
|
}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DefaultStockLocationStrategy = exports.BaseStockLocationStrategy = void 0;
|
|
4
|
+
const generated_types_1 = require("@vendure/common/lib/generated-types");
|
|
5
|
+
const errors_1 = require("../../common/error/errors");
|
|
4
6
|
const utils_1 = require("../../common/utils");
|
|
5
7
|
const transactional_connection_1 = require("../../connection/transactional-connection");
|
|
8
|
+
const product_variant_entity_1 = require("../../entity/product-variant/product-variant.entity");
|
|
6
9
|
const allocation_entity_1 = require("../../entity/stock-movement/allocation.entity");
|
|
7
10
|
class BaseStockLocationStrategy {
|
|
8
11
|
init(injector) {
|
|
12
|
+
this.injector = injector;
|
|
9
13
|
this.connection = injector.get(transactional_connection_1.TransactionalConnection);
|
|
10
14
|
}
|
|
11
15
|
async forCancellation(ctx, stockLocations, orderLine, quantity) {
|
|
@@ -17,6 +21,64 @@ class BaseStockLocationStrategy {
|
|
|
17
21
|
async forSale(ctx, stockLocations, orderLine, quantity) {
|
|
18
22
|
return this.getLocationsBasedOnAllocations(ctx, stockLocations, orderLine, quantity);
|
|
19
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* GlobalSettingsService and StockLevelService are resolved on first use rather than in
|
|
26
|
+
* `init()`. Both have to be imported dynamically to break a circular dependency, and that is
|
|
27
|
+
* asynchronous, while `init()` has to stay synchronous: it is a documented extension point,
|
|
28
|
+
* so a subclass may override it with a synchronous method, and may call `super.init()`
|
|
29
|
+
* without awaiting it. Resolving here means neither leaves a service unset.
|
|
30
|
+
*/
|
|
31
|
+
async getGlobalSettingsService() {
|
|
32
|
+
if (!this.globalSettingsService) {
|
|
33
|
+
const GlobalSettingsService = (await import('../../service/services/global-settings.service.js'))
|
|
34
|
+
.GlobalSettingsService;
|
|
35
|
+
this.globalSettingsService = this.getInjector().get(GlobalSettingsService);
|
|
36
|
+
}
|
|
37
|
+
return this.globalSettingsService;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* See {@link BaseStockLocationStrategy.getGlobalSettingsService} for why this is resolved
|
|
41
|
+
* lazily.
|
|
42
|
+
*/
|
|
43
|
+
async getStockLevelService() {
|
|
44
|
+
if (!this.stockLevelService) {
|
|
45
|
+
const StockLevelService = (await import('../../service/services/stock-level.service.js'))
|
|
46
|
+
.StockLevelService;
|
|
47
|
+
this.stockLevelService = this.getInjector().get(StockLevelService);
|
|
48
|
+
}
|
|
49
|
+
return this.stockLevelService;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* A subclass which overrides `init()` must call `super.init(injector)`, as it already had to
|
|
53
|
+
* for `this.connection`. Saying so beats the TypeError that reaching into an unset Injector
|
|
54
|
+
* would otherwise raise.
|
|
55
|
+
*/
|
|
56
|
+
getInjector() {
|
|
57
|
+
if (!this.injector) {
|
|
58
|
+
throw new errors_1.InternalServerError(`${this.constructor.name} has no Injector: a StockLocationStrategy which overrides ` +
|
|
59
|
+
'init() must call super.init(injector).');
|
|
60
|
+
}
|
|
61
|
+
return this.injector;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Resolves the two ProductVariant settings which decide how much of it may be allocated:
|
|
65
|
+
* whether its inventory is tracked at all, and the threshold below which its stock may not
|
|
66
|
+
* fall. Both can defer to the global settings, so both are resolved here rather than read
|
|
67
|
+
* from the ProductVariant directly.
|
|
68
|
+
*/
|
|
69
|
+
async getVariantStockSettings(ctx, variant) {
|
|
70
|
+
const globalSettingsService = await this.getGlobalSettingsService();
|
|
71
|
+
const { outOfStockThreshold, trackInventory } = await globalSettingsService.getSettings(ctx);
|
|
72
|
+
const inventoryNotTracked = variant.trackInventory === generated_types_1.GlobalFlag.FALSE ||
|
|
73
|
+
(variant.trackInventory === generated_types_1.GlobalFlag.INHERIT && trackInventory === false);
|
|
74
|
+
const effectiveOutOfStockThreshold = variant.useGlobalOutOfStockThreshold
|
|
75
|
+
? outOfStockThreshold
|
|
76
|
+
: variant.outOfStockThreshold;
|
|
77
|
+
return {
|
|
78
|
+
inventoryNotTracked,
|
|
79
|
+
effectiveOutOfStockThreshold,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
20
82
|
async getLocationsBasedOnAllocations(ctx, stockLocations, orderLine, quantity) {
|
|
21
83
|
const allocations = await this.connection.getRepository(ctx, allocation_entity_1.Allocation).find({
|
|
22
84
|
where: {
|
|
@@ -54,13 +116,19 @@ exports.BaseStockLocationStrategy = BaseStockLocationStrategy;
|
|
|
54
116
|
* It assumes only a single StockLocation and that all stock is allocated from that location. When
|
|
55
117
|
* more than one StockLocation or Channel is used, it will not behave as expected.
|
|
56
118
|
*
|
|
119
|
+
* Since 3.7.4, `forAllocation()` caps each allocation at the stock the ProductVariant actually has
|
|
120
|
+
* available, read under a write lock. With the default {@link DefaultStockAllocationStrategy} the
|
|
121
|
+
* saleable stock check runs on the transition to `ArrangingPayment` and the allocation runs on the
|
|
122
|
+
* transition to `PaymentSettled`, in a later request, so another Order can take the stock in
|
|
123
|
+
* between. Before 3.7.4 the allocation went through at the full quantity and oversold the variant.
|
|
124
|
+
* Now the Order which loses that race is allocated less than it ordered, and
|
|
125
|
+
* {@link StockShortfallEvent} reports the shortfall. The customer has already paid at that point,
|
|
126
|
+
* and core neither refunds nor cancels the Order: subscribe to the event to decide what to do.
|
|
127
|
+
*
|
|
57
128
|
* @docsCategory products & stock
|
|
58
129
|
* @since 2.0.0
|
|
59
130
|
*/
|
|
60
131
|
class DefaultStockLocationStrategy extends BaseStockLocationStrategy {
|
|
61
|
-
init(injector) {
|
|
62
|
-
super.init(injector);
|
|
63
|
-
}
|
|
64
132
|
getAvailableStock(ctx, productVariantId, stockLevels) {
|
|
65
133
|
let stockOnHand = 0;
|
|
66
134
|
let stockAllocated = 0;
|
|
@@ -70,8 +138,36 @@ class DefaultStockLocationStrategy extends BaseStockLocationStrategy {
|
|
|
70
138
|
}
|
|
71
139
|
return { stockOnHand, stockAllocated };
|
|
72
140
|
}
|
|
73
|
-
|
|
74
|
-
|
|
141
|
+
/**
|
|
142
|
+
* @description
|
|
143
|
+
* Allocates from the first StockLocation, capped at the quantity the ProductVariant still has
|
|
144
|
+
* available: `stockOnHand - stockAllocated - outOfStockThreshold`, summed over every
|
|
145
|
+
* StockLevel of the variant, which is the same figure the saleable stock check uses. The
|
|
146
|
+
* StockLevels are read under a write lock, so a concurrent allocation of the same variant
|
|
147
|
+
* waits and then sees this one's result.
|
|
148
|
+
*
|
|
149
|
+
* @since 3.7.4 - The quantity is capped and the StockLevels are read under a lock
|
|
150
|
+
*/
|
|
151
|
+
async forAllocation(ctx, stockLocations, orderLine, quantity) {
|
|
152
|
+
const variant = await this.connection.getEntityOrThrow(ctx, product_variant_entity_1.ProductVariant, orderLine.productVariantId, { loadEagerRelations: false });
|
|
153
|
+
const { inventoryNotTracked, effectiveOutOfStockThreshold } = await this.getVariantStockSettings(ctx, variant);
|
|
154
|
+
if (inventoryNotTracked) {
|
|
155
|
+
// Nothing is counted for an untracked variant, so there is nothing to cap it against
|
|
156
|
+
// and no reason to make concurrent checkouts of it wait for each other.
|
|
157
|
+
return [{ location: stockLocations[0], quantity }];
|
|
158
|
+
}
|
|
159
|
+
const stockLevelService = await this.getStockLevelService();
|
|
160
|
+
const stockLevels = await stockLevelService.getLockedStockLevelsForVariant(ctx, orderLine.productVariantId);
|
|
161
|
+
const { stockOnHand, stockAllocated } = this.getAvailableStock(ctx, orderLine.productVariantId, stockLevels);
|
|
162
|
+
// A negative threshold is a permitted backorder depth, so this stays above
|
|
163
|
+
// `stockOnHand` by exactly that much. A variant with no StockLevel row counts as zero of
|
|
164
|
+
// both figures, which is what the saleable stock check makes of it too.
|
|
165
|
+
const quantityAvailable = stockOnHand - stockAllocated - effectiveOutOfStockThreshold;
|
|
166
|
+
const quantityToAllocate = Math.min(quantity, quantityAvailable);
|
|
167
|
+
if (quantityToAllocate <= 0) {
|
|
168
|
+
return [];
|
|
169
|
+
}
|
|
170
|
+
return [{ location: stockLocations[0], quantity: quantityToAllocate }];
|
|
75
171
|
}
|
|
76
172
|
}
|
|
77
173
|
exports.DefaultStockLocationStrategy = DefaultStockLocationStrategy;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default-stock-location-strategy.js","sourceRoot":"","sources":["../../../src/config/catalog/default-stock-location-strategy.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"default-stock-location-strategy.js","sourceRoot":"","sources":["../../../src/config/catalog/default-stock-location-strategy.ts"],"names":[],"mappings":";;;AAAA,yEAAiE;AAKjE,sDAAgE;AAEhE,8CAAiD;AACjD,wFAAoF;AAEpF,gGAAqF;AAGrF,qFAA2E;AAI3E,MAAsB,yBAAyB;IAS3C,IAAI,CAAC,QAAkB;QACnB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAC,GAAG,CAAC,kDAAuB,CAAC,CAAC;IAC5D,CAAC;IAeD,KAAK,CAAC,eAAe,CACjB,GAAmB,EACnB,cAA+B,EAC/B,SAAoB,EACpB,QAAgB;QAEhB,OAAO,IAAI,CAAC,8BAA8B,CAAC,GAAG,EAAE,cAAc,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;IACzF,CAAC;IAED,KAAK,CAAC,UAAU,CACZ,GAAmB,EACnB,cAA+B,EAC/B,SAAoB,EACpB,QAAgB;QAEhB,OAAO,IAAI,CAAC,8BAA8B,CAAC,GAAG,EAAE,cAAc,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;IACzF,CAAC;IAED,KAAK,CAAC,OAAO,CACT,GAAmB,EACnB,cAA+B,EAC/B,SAAoB,EACpB,QAAgB;QAEhB,OAAO,IAAI,CAAC,8BAA8B,CAAC,GAAG,EAAE,cAAc,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;IACzF,CAAC;IAED;;;;;;OAMG;IACO,KAA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,QAAQ,EAAE,CAAC,CAAC;QACvD,CAAC;QACD,MAAM,iBAAiB,GAAG,MAAM,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAC5D,MAAM,WAAW,GAAG,MAAM,iBAAiB,CAAC,8BAA8B,CACtE,GAAG,EACH,SAAS,CAAC,gBAAgB,CAC7B,CAAC;QACF,MAAM,EAAE,WAAW,EAAE,cAAc,EAAE,GAAG,IAAI,CAAC,iBAAiB,CAC1D,GAAG,EACH,SAAS,CAAC,gBAAgB,EAC1B,WAAW,CACd,CAAC;QACF,2EAA2E;QAC3E,yFAAyF;QACzF,wEAAwE;QACxE,MAAM,iBAAiB,GAAG,WAAW,GAAG,cAAc,GAAG,4BAA4B,CAAC;QACtF,MAAM,kBAAkB,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,iBAAiB,CAAC,CAAC;QACjE,IAAI,kBAAkB,IAAI,CAAC,EAAE,CAAC;YAC1B,OAAO,EAAE,CAAC;QACd,CAAC;QACD,OAAO,CAAC,EAAE,QAAQ,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,kBAAkB,EAAE,CAAC,CAAC;IAC3E,CAAC;CACJ;AA9DD,oEA8DC"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ID } from '@vendure/common/lib/shared-types';
|
|
2
|
-
import type { GlobalSettingsService } from '../../service/index';
|
|
3
2
|
import { RequestContext } from '../../api/common/request-context';
|
|
4
3
|
import { Cache, CacheService, RequestContextCacheService } from '../../cache/index';
|
|
5
4
|
import { Injector } from '../../common/injector';
|
|
@@ -30,8 +29,6 @@ export declare class MultiChannelStockLocationStrategy extends BaseStockLocation
|
|
|
30
29
|
/** @internal */
|
|
31
30
|
protected eventBus: EventBus;
|
|
32
31
|
/** @internal */
|
|
33
|
-
protected globalSettingsService: GlobalSettingsService;
|
|
34
|
-
/** @internal */
|
|
35
32
|
protected requestContextCache: RequestContextCacheService;
|
|
36
33
|
/** @internal */
|
|
37
34
|
init(injector: Injector): Promise<void>;
|
|
@@ -62,6 +59,4 @@ export declare class MultiChannelStockLocationStrategy extends BaseStockLocation
|
|
|
62
59
|
* to live out its full TTL.
|
|
63
60
|
*/
|
|
64
61
|
private invalidateChannelIdCache;
|
|
65
|
-
private getStockLevelsForVariant;
|
|
66
|
-
private getVariantStockSettings;
|
|
67
62
|
}
|
|
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.MultiChannelStockLocationStrategy = void 0;
|
|
7
|
-
const generated_types_1 = require("@vendure/common/lib/generated-types");
|
|
8
7
|
const ms_1 = __importDefault(require("ms"));
|
|
9
8
|
const operators_1 = require("rxjs/operators");
|
|
10
9
|
const index_1 = require("../../cache/index");
|
|
@@ -31,14 +30,10 @@ const loggerCtx = 'MultiChannelStockLocationStrategy';
|
|
|
31
30
|
class MultiChannelStockLocationStrategy extends default_stock_location_strategy_1.BaseStockLocationStrategy {
|
|
32
31
|
/** @internal */
|
|
33
32
|
async init(injector) {
|
|
34
|
-
super.init(injector);
|
|
33
|
+
await super.init(injector);
|
|
35
34
|
this.eventBus = injector.get(index_3.EventBus);
|
|
36
35
|
this.cacheService = injector.get(index_1.CacheService);
|
|
37
36
|
this.requestContextCache = injector.get(index_1.RequestContextCacheService);
|
|
38
|
-
// Dynamically import the GlobalSettingsService to avoid circular dependency
|
|
39
|
-
const GlobalSettingsService = (await import('../../service/services/global-settings.service.js'))
|
|
40
|
-
.GlobalSettingsService;
|
|
41
|
-
this.globalSettingsService = injector.get(GlobalSettingsService);
|
|
42
37
|
this.channelIdCache = this.cacheService.createCache({
|
|
43
38
|
options: {
|
|
44
39
|
ttl: (0, ms_1.default)('7 days'),
|
|
@@ -85,11 +80,22 @@ class MultiChannelStockLocationStrategy extends default_stock_location_strategy_
|
|
|
85
80
|
* have sufficient stock available.
|
|
86
81
|
*/
|
|
87
82
|
async forAllocation(ctx, stockLocations, orderLine, quantity) {
|
|
88
|
-
const stockLevels = await this.getStockLevelsForVariant(ctx, orderLine.productVariantId);
|
|
89
83
|
const variant = await this.connection.getEntityOrThrow(ctx, index_2.ProductVariant, orderLine.productVariantId, { loadEagerRelations: false });
|
|
90
84
|
let totalAllocated = 0;
|
|
91
85
|
const locations = [];
|
|
92
86
|
const { inventoryNotTracked, effectiveOutOfStockThreshold } = await this.getVariantStockSettings(ctx, variant);
|
|
87
|
+
// Only a tracked variant's figures decide how much is allocated, so only those need the lock.
|
|
88
|
+
let stockLevels;
|
|
89
|
+
if (inventoryNotTracked) {
|
|
90
|
+
stockLevels = await this.connection.getRepository(ctx, stock_level_entity_1.StockLevel).find({
|
|
91
|
+
where: { productVariantId: orderLine.productVariantId },
|
|
92
|
+
loadEagerRelations: false,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
const stockLevelService = await this.getStockLevelService();
|
|
97
|
+
stockLevels = await stockLevelService.getLockedStockLevelsForVariant(ctx, orderLine.productVariantId);
|
|
98
|
+
}
|
|
93
99
|
for (const stockLocation of stockLocations) {
|
|
94
100
|
const stockLevel = stockLevels.find(sl => sl.stockLocationId === stockLocation.id);
|
|
95
101
|
if (stockLevel && (await this.stockLevelAppliesToActiveChannel(ctx, stockLevel))) {
|
|
@@ -144,26 +150,6 @@ class MultiChannelStockLocationStrategy extends default_stock_location_strategy_
|
|
|
144
150
|
.delete(stockLocationId)
|
|
145
151
|
.catch(err => vendure_logger_1.Logger.error(`Failed to invalidate StockLocation channel id cache for id ${stockLocationId}: ${err instanceof Error ? err.message : String(err)}`, loggerCtx));
|
|
146
152
|
}
|
|
147
|
-
getStockLevelsForVariant(ctx, productVariantId) {
|
|
148
|
-
return this.requestContextCache.get(ctx, `MultiChannelStockLocationStrategy.stockLevels.${productVariantId}`, () => this.connection.getRepository(ctx, stock_level_entity_1.StockLevel).find({
|
|
149
|
-
where: {
|
|
150
|
-
productVariantId,
|
|
151
|
-
},
|
|
152
|
-
loadEagerRelations: false,
|
|
153
|
-
}));
|
|
154
|
-
}
|
|
155
|
-
async getVariantStockSettings(ctx, variant) {
|
|
156
|
-
const { outOfStockThreshold, trackInventory } = await this.globalSettingsService.getSettings(ctx);
|
|
157
|
-
const inventoryNotTracked = variant.trackInventory === generated_types_1.GlobalFlag.FALSE ||
|
|
158
|
-
(variant.trackInventory === generated_types_1.GlobalFlag.INHERIT && trackInventory === false);
|
|
159
|
-
const effectiveOutOfStockThreshold = variant.useGlobalOutOfStockThreshold
|
|
160
|
-
? outOfStockThreshold
|
|
161
|
-
: variant.outOfStockThreshold;
|
|
162
|
-
return {
|
|
163
|
-
inventoryNotTracked,
|
|
164
|
-
effectiveOutOfStockThreshold,
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
153
|
}
|
|
168
154
|
exports.MultiChannelStockLocationStrategy = MultiChannelStockLocationStrategy;
|
|
169
155
|
//# sourceMappingURL=multi-channel-stock-location-strategy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"multi-channel-stock-location-strategy.js","sourceRoot":"","sources":["../../../src/config/catalog/multi-channel-stock-location-strategy.ts"],"names":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"multi-channel-stock-location-strategy.js","sourceRoot":"","sources":["../../../src/config/catalog/multi-channel-stock-location-strategy.ts"],"names":[],"mappings":";;;;;;AACA,4CAAoB;AACpB,8CAAwC;AAGxC,6CAAoF;AAEpF,8CAAoD;AAEpD,oFAAyE;AACzE,6FAAkF;AAClF,iDAAyF;AACzF,6DAAkD;AAElD,uFAA8E;AAG9E,MAAM,SAAS,GAAG,mCAAmC,CAAC;AAEtD;;;;;;;;;;;;GAYG;AACH,MAAa,iCAAkC,SAAQ,2DAAyB;IAU5E,gBAAgB;IAChB,KAAK,CAAC,IAAI,CAAC,QAAkB;QACzB,MAAM,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC3B,IAAI,CAAC,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mB,EAAE,eAAmB;QAC1E,OAAO,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,WAAW,CAAC,eAAe,CAAC,EAAE,GAAG,EAAE,CAC7E,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,eAAe,EAAE,KAAK,IAAI,EAAE;YAChD,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,gBAAgB,CACxD,GAAG,EACH,qCAAa,EACb,eAAe,EACf;gBACI,SAAS,EAAE;oBACP,QAAQ,EAAE,IAAI;iBACjB;aACJ,CACJ,CAAC;YACF,OAAO,aAAa,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QACjD,CAAC,CAAC,CACL,CAAC;IACN,CAAC;IAED,0FAA0F;IAClF,WAAW,CAAC,eAAmB;QACnC,OAAO,6DAA6D,eAAe,EAAE,CAAC;IAC1F,CAAC;IAED;;;;OAIG;IACK,wBAAwB,CAAC,eAAmB;QAChD,KAAK,IAAI,CAAC,cAAc;aACnB,MAAM,CAAC,eAAe,CAAC;aACvB,KAAK,CAAC,GAAG,CAAC,EAAE,CACT,uBAAM,CAAC,KAAK,CACR,8DAA8D,eAAe,KACzE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CACnD,EAAE,EACF,SAAS,CACZ,CACJ,CAAC;IACV,CAAC;CACJ;AAhLD,8EAgLC"}
|
|
@@ -196,9 +196,21 @@ function configureDefaultOrderProcess(options) {
|
|
|
196
196
|
return 'message.cannot-transition-to-payment-without-shipping-method';
|
|
197
197
|
}
|
|
198
198
|
if (options.arrangingPaymentRequiresStock !== false) {
|
|
199
|
+
// A write lock on the StockLevel rows only closes the gap between this check
|
|
200
|
+
// and the allocation if the allocation happens in this same transition, and
|
|
201
|
+
// therefore in this same transaction. The default StockAllocationStrategy
|
|
202
|
+
// allocates later, on the transition to PaymentAuthorized or PaymentSettled,
|
|
203
|
+
// which is a separate request and a separate transaction, so a lock taken here
|
|
204
|
+
// would be released long before it could serialize anything. Ask the configured
|
|
205
|
+
// strategy and only lock when it is going to allocate now.
|
|
206
|
+
const { stockAllocationStrategy } = configService.orderOptions;
|
|
207
|
+
const lockStockLevels = await stockAllocationStrategy.shouldAllocateStock(ctx, fromState, toState, order);
|
|
208
|
+
if (lockStockLevels) {
|
|
209
|
+
await stockLevelService.lockStockLevelsForVariants(ctx, order.lines.map(line => line.productVariantId));
|
|
210
|
+
}
|
|
199
211
|
const variantsWithInsufficientSaleableStock = [];
|
|
200
212
|
for (const line of order.lines) {
|
|
201
|
-
const availableStock = await productVariantService.getSaleableStockLevel(ctx, line.productVariant);
|
|
213
|
+
const availableStock = await productVariantService.getSaleableStockLevel(ctx, line.productVariant, { lockStockLevels });
|
|
202
214
|
if (line.quantity > availableStock) {
|
|
203
215
|
variantsWithInsufficientSaleableStock.push(line.productVariant);
|
|
204
216
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default-order-process.js","sourceRoot":"","sources":["../../../src/config/order/default-order-process.ts"],"names":[],"mappings":";;;AAkKA,
|
|
1
|
+
{"version":3,"file":"default-order-process.js","sourceRoot":"","sources":["../../../src/config/order/default-order-process.ts"],"names":[],"mappings":";;;AAkKA,oEAiUC;AAneD,yEAAuE;AAEvE,uDAAoD;AAGpD,wFAAoF;AACpF,kEAAwD;AACxD,iFAAsE;AACtE,yGAA8F;AAC9F,wEAA8D;AAC9D,gGAAqF;AACrF,kFAA6E;AAE7E,yEAQiD;AAgHjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,SAAgB,4BAA4B,CAAC,OAAmC;IAC5E,IAAI,UAAmC,CAAC;IACxC,IAAI,qBAA0E,CAAC;IAC/E,IAAI,aAAwD,CAAC;IAC7D,IAAI,QAAkD,CAAC;IACvD,IAAI,oBAAwE,CAAC;IA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,CACzE,GAAG,EACH,SAAS,EACT,OAAO,EACP,KAAK,CACR,CAAC;YACF,IAAI,mBAAmB,EAAE,CAAC;gBACtB,MAAM,oBAAoB,CAAC,yBAAyB,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YACrE,CAAC;YACD,IAAI,OAAO,KAAK,WAAW,EAAE,CAAC;gBAC1B,KAAK,CAAC,MAAM,GAAG,KAAK,CAAC;YACzB,CAAC;YACD,IAAI,SAAS,KAAK,OAAO,IAAI,OAAO,KAAK,kBAAkB,EAAE,CAAC;gBAC1D,kEAAkE;gBAClE,2EAA2E;gBAC3E,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC;YACxB,CAAC;YACD,MAAM,cAAc,CAAC,0BAA0B,CAAC;gBAC5C,OAAO,EAAE,KAAK,CAAC,EAAE;gBACjB,IAAI,EAAE,kCAAgB,CAAC,sBAAsB;gBAC7C,GAAG;gBACH,IAAI,EAAE;oBACF,IAAI,EAAE,SAAS;oBACf,EAAE,EAAE,OAAO;iBACd;aACJ,CAAC,CAAC;QACP,CAAC;KACJ,CAAC;IAEF,KAAK,UAAU,yBAAyB,CAAC,GAAmB,EAAE,EAAM;QAChE,OAAO,MAAM,UAAU,CAAC,gBAAgB,CAAC,GAAG,EAAE,oBAAK,EAAE,EAAE,EAAE;YACrD,SAAS,EAAE,CAAC,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,gCAAgC,CAAC;SAC/F,CAAC,CAAC;IACP,CAAC;IAED,OAAO,YAAY,CAAC;AACxB,CAAC;AAED;;;;;;;;;GASG;AACU,QAAA,mBAAmB,GAAG,4BAA4B,CAAC,EAAE,CAAC,CAAC"}
|
|
@@ -21,6 +21,10 @@ export interface StockAllocationStrategy extends InjectableStrategy {
|
|
|
21
21
|
* @description
|
|
22
22
|
* This method is called whenever an Order transitions from one state to another.
|
|
23
23
|
* If it resolves to `true`, then stock will be allocated for this order.
|
|
24
|
+
*
|
|
25
|
+
* It may be called more than once for the same transition, because the transition guard
|
|
26
|
+
* also asks whether the allocation will happen now. Implementations must return the same
|
|
27
|
+
* result each time for the same arguments, and must be free of side effects.
|
|
24
28
|
*/
|
|
25
29
|
shouldAllocateStock(ctx: RequestContext, fromState: OrderState, toState: OrderState, order: Order): boolean | Promise<boolean>;
|
|
26
30
|
}
|
|
@@ -5,8 +5,8 @@ import { Asset } from '../asset/asset.entity';
|
|
|
5
5
|
import { VendureEntity } from '../base/base.entity';
|
|
6
6
|
import { Channel } from '../channel/channel.entity';
|
|
7
7
|
import { CustomOrderLineFields } from '../custom-entity-fields';
|
|
8
|
-
import { OrderLineReference } from '../order-line-reference/order-line-reference.entity';
|
|
9
8
|
import { Order } from '../order/order.entity';
|
|
9
|
+
import { OrderLineReference } from '../order-line-reference/order-line-reference.entity';
|
|
10
10
|
import { ProductVariant } from '../product-variant/product-variant.entity';
|
|
11
11
|
import { ShippingLine } from '../shipping-line/shipping-line.entity';
|
|
12
12
|
import { Allocation } from '../stock-movement/allocation.entity';
|
|
@@ -166,18 +166,6 @@ export declare class OrderLine extends VendureEntity implements HasCustomFields
|
|
|
166
166
|
get proratedLinePriceWithTax(): number;
|
|
167
167
|
get proratedLineTax(): number;
|
|
168
168
|
addAdjustment(adjustment: Adjustment): void;
|
|
169
|
-
/**
|
|
170
|
-
* @description
|
|
171
|
-
* Sets this line's quantity to `newQuantity`, rescaling its `PROMOTION`-type adjustments to
|
|
172
|
-
* match. Used where a quantity reduction bypasses `OrderCalculator` recalculation (see
|
|
173
|
-
* `OrderModifier.cancelOrderByOrderLines()`), to preserve the invariant that `PROMOTION`
|
|
174
|
-
* amounts are stored scaled to the current quantity.
|
|
175
|
-
*
|
|
176
|
-
* A `newQuantity` of 0 sets the quantity but leaves the adjustments untouched: the getters
|
|
177
|
-
* short-circuit on an empty line either way, so scaling them to zero would only erase the
|
|
178
|
-
* record of the discount that had applied, which plugins and accounting exports read back.
|
|
179
|
-
*/
|
|
180
|
-
setQuantityRescalingAdjustments(newQuantity: number): void;
|
|
181
169
|
/**
|
|
182
170
|
* Clears Adjustments from all OrderItems of the given type. If no type
|
|
183
171
|
* is specified, then all adjustments are removed.
|
|
@@ -203,26 +191,12 @@ export declare class OrderLine extends VendureEntity implements HasCustomFields
|
|
|
203
191
|
private _proratedUnitPriceWithTax;
|
|
204
192
|
/**
|
|
205
193
|
* @description
|
|
206
|
-
* The total of all price adjustments
|
|
207
|
-
* number due to discounts. See `quantityBasisFor()` for the quantity basis used per
|
|
208
|
-
* adjustment, which differs by `AdjustmentType`.
|
|
194
|
+
* The total of all price adjustments. Will typically be a negative number due to discounts.
|
|
209
195
|
*/
|
|
210
196
|
private getUnitAdjustmentsTotal;
|
|
211
197
|
/**
|
|
212
198
|
* @description
|
|
213
|
-
* The total of all price adjustments
|
|
214
|
-
* due to discounts. See `quantityBasisFor()` for the quantity basis used per adjustment.
|
|
199
|
+
* The total of all price adjustments. Will typically be a negative number due to discounts.
|
|
215
200
|
*/
|
|
216
201
|
private getLineAdjustmentsTotal;
|
|
217
|
-
/**
|
|
218
|
-
* @description
|
|
219
|
-
* The quantity that `adjustment.amount` (a line total) should be divided by to get a correct
|
|
220
|
-
* per-unit share. `PROMOTION` adjustments are always freshly recomputed against the current
|
|
221
|
-
* `this.quantity`, so that is their basis. Other types (`DISTRIBUTED_ORDER_PROMOTION`, `OTHER`)
|
|
222
|
-
* are a per-line share of an order-level amount that is redistributed by weight on every
|
|
223
|
-
* recalculation, so their basis is pinned to `orderPlacedQuantity` - otherwise a partially
|
|
224
|
-
* cancelled/refunded line's surviving units could absorb a bigger share than they're due. See
|
|
225
|
-
* #5127 for the full reasoning.
|
|
226
|
-
*/
|
|
227
|
-
private quantityBasisFor;
|
|
228
202
|
}
|