|
|
@@ -10,7 +10,7 @@ import {
|
|
|
ConfigurableOperationDefOptions,
|
|
|
} from '../../common/configurable-operation';
|
|
|
import { TtlCache } from '../../common/ttl-cache';
|
|
|
-import { Order } from '../../entity/order/order.entity';
|
|
|
+import { ShippingMethod, Order } from '../../entity';
|
|
|
|
|
|
/**
|
|
|
* @description
|
|
|
@@ -65,20 +65,20 @@ export class ShippingEligibilityChecker<T extends ConfigArgs = ConfigArgs> exten
|
|
|
*
|
|
|
* @internal
|
|
|
*/
|
|
|
- async check(ctx: RequestContext, order: Order, args: ConfigArg[]): Promise<boolean> {
|
|
|
- const shouldRunCheck = await this.shouldRunCheck(ctx, order, args);
|
|
|
- return shouldRunCheck ? this.checkFn(ctx, order, this.argsArrayToHash(args)) : true;
|
|
|
+ async check(ctx: RequestContext, order: Order, args: ConfigArg[], method: ShippingMethod): Promise<boolean> {
|
|
|
+ const shouldRunCheck = await this.shouldRunCheck(ctx, order, args, method);
|
|
|
+ return shouldRunCheck ? this.checkFn(ctx, order, this.argsArrayToHash(args), method) : true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Determines whether the check function needs to be run, based on the presence and
|
|
|
* result of any defined `shouldRunCheckFn`.
|
|
|
*/
|
|
|
- private async shouldRunCheck(ctx: RequestContext, order: Order, args: ConfigArg[]): Promise<boolean> {
|
|
|
+ private async shouldRunCheck(ctx: RequestContext, order: Order, args: ConfigArg[], method: ShippingMethod): Promise<boolean> {
|
|
|
if (typeof this.shouldRunCheckFn === 'function') {
|
|
|
const cacheKey = ctx.session?.id;
|
|
|
if (cacheKey) {
|
|
|
- const checkResult = await this.shouldRunCheckFn(ctx, order, this.argsArrayToHash(args));
|
|
|
+ const checkResult = await this.shouldRunCheckFn(ctx, order, this.argsArrayToHash(args), method);
|
|
|
const checkResultHash = createHash('sha1')
|
|
|
.update(JSON.stringify(checkResult))
|
|
|
.digest('base64');
|
|
|
@@ -109,6 +109,7 @@ export type CheckShippingEligibilityCheckerFn<T extends ConfigArgs> = (
|
|
|
ctx: RequestContext,
|
|
|
order: Order,
|
|
|
args: ConfigArgValues<T>,
|
|
|
+ method: ShippingMethod
|
|
|
) => boolean | Promise<boolean>;
|
|
|
|
|
|
/**
|
|
|
@@ -143,4 +144,5 @@ export type ShouldRunCheckFn<T extends ConfigArgs> = (
|
|
|
ctx: RequestContext,
|
|
|
order: Order,
|
|
|
args: ConfigArgValues<T>,
|
|
|
+ method: ShippingMethod
|
|
|
) => Json | Promise<Json>;
|