@pinelab/vendure-plugin-qls-fulfillment 1.0.0-beta.21 → 1.0.0-beta.23

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.
@@ -89,25 +89,24 @@ let QlsOrderService = class QlsOrderService {
89
89
  throw new core_2.UserInputError(`Order '${order.code}' has already been synced to QLS`);
90
90
  }
91
91
  try {
92
- // Check if all products are available in QLS
93
- const qlsProducts = order.lines
94
- .filter((line) => {
95
- if (this.options.excludeVariantFromSync?.(ctx, line.productVariant)) {
92
+ // Map variants to QLS products
93
+ const qlsProducts = [];
94
+ await Promise.all(order.lines.map(async (line) => {
95
+ // Check if product variant should be excluded from sync
96
+ if (await this.options.excludeVariantFromSync?.(ctx, new core_2.Injector(this.moduleRef), line.productVariant)) {
96
97
  core_2.Logger.info(`Product variant '${line.productVariant.sku}' not sent to QLS in order '${order.code}' because it is excluded from sync.`, constants_1.loggerCtx);
97
- return false;
98
+ return;
98
99
  }
99
- return true;
100
- })
101
- .map((line) => {
100
+ // Check if product is available in QLS
102
101
  if (!line.productVariant.customFields.qlsProductId) {
103
102
  throw new Error(`Product variant '${line.productVariant.sku}' does not have a QLS product ID set. Unable to push order '${order.code}' to QLS.`);
104
103
  }
105
- return {
104
+ qlsProducts.push({
106
105
  amount_ordered: line.quantity,
107
106
  product_id: line.productVariant.customFields.qlsProductId,
108
107
  name: line.productVariant.name,
109
- };
110
- });
108
+ });
109
+ }));
111
110
  const additionalOrderFields = await this.options.getAdditionalOrderFields?.(ctx, new core_2.Injector(this.moduleRef), order);
112
111
  const customerName = [order.customer?.firstName, order.customer?.lastName]
113
112
  .filter(Boolean)
@@ -174,6 +173,7 @@ let QlsOrderService = class QlsOrderService {
174
173
  * Update the status of an order in QLS based on the given order code and status
175
174
  */
176
175
  async handleOrderStatusUpdate(ctx, body) {
176
+ core_2.Logger.info(`Handling QLS order status update for order '${body.customer_reference}' with status '${body.status} and amount_delivered '${body.amount_delivered}' and amount_total '${body.amount_total}'`, constants_1.loggerCtx);
177
177
  const orderCode = body.customer_reference;
178
178
  const order = await this.orderService.findOneByCode(ctx, orderCode, []);
179
179
  if (!order) {
@@ -3,6 +3,7 @@ import { EventBus, ID, Job, JobQueueService, ListQueryBuilder, ProductPriceAppli
3
3
  import { FulfillmentProduct } from '../lib/client-types';
4
4
  import { QlsClient } from '../lib/qls-client';
5
5
  import { QlsPluginOptions, QlsProductJobData } from '../types';
6
+ import { ModuleRef } from '@nestjs/core';
6
7
  type SyncProductsResult = {
7
8
  updatedInQls: Partial<ProductVariant>[];
8
9
  createdInQls: Partial<ProductVariant>[];
@@ -19,8 +20,9 @@ export declare class QlsProductService implements OnModuleInit, OnApplicationBoo
19
20
  private readonly eventBus;
20
21
  private readonly listQueryBuilder;
21
22
  private readonly productPriceApplicator;
23
+ private readonly moduleRef;
22
24
  private productJobQueue;
23
- constructor(connection: TransactionalConnection, options: QlsPluginOptions, jobQueueService: JobQueueService, stockLevelService: StockLevelService, variantService: ProductVariantService, stockLocationService: StockLocationService, eventBus: EventBus, listQueryBuilder: ListQueryBuilder, productPriceApplicator: ProductPriceApplicator);
25
+ constructor(connection: TransactionalConnection, options: QlsPluginOptions, jobQueueService: JobQueueService, stockLevelService: StockLevelService, variantService: ProductVariantService, stockLocationService: StockLocationService, eventBus: EventBus, listQueryBuilder: ListQueryBuilder, productPriceApplicator: ProductPriceApplicator, moduleRef: ModuleRef);
24
26
  onApplicationBootstrap(): void;
25
27
  onModuleInit(): Promise<void>;
26
28
  /**
@@ -24,10 +24,11 @@ const util_1 = __importDefault(require("util"));
24
24
  const constants_1 = require("../constants");
25
25
  const qls_client_1 = require("../lib/qls-client");
26
26
  const util_2 = require("./util");
27
+ const core_2 = require("@nestjs/core");
27
28
  // Wait for 700ms to avoid rate limit of 500/5 minutes
28
29
  const waitToPreventRateLimit = () => new Promise((resolve) => setTimeout(resolve, 700));
29
30
  let QlsProductService = class QlsProductService {
30
- constructor(connection, options, jobQueueService, stockLevelService, variantService, stockLocationService, eventBus, listQueryBuilder, productPriceApplicator) {
31
+ constructor(connection, options, jobQueueService, stockLevelService, variantService, stockLocationService, eventBus, listQueryBuilder, productPriceApplicator, moduleRef) {
31
32
  this.connection = connection;
32
33
  this.options = options;
33
34
  this.jobQueueService = jobQueueService;
@@ -37,6 +38,7 @@ let QlsProductService = class QlsProductService {
37
38
  this.eventBus = eventBus;
38
39
  this.listQueryBuilder = listQueryBuilder;
39
40
  this.productPriceApplicator = productPriceApplicator;
41
+ this.moduleRef = moduleRef;
40
42
  }
41
43
  onApplicationBootstrap() {
42
44
  // Listen for ProductVariantEvent and add a job to the queue
@@ -271,7 +273,7 @@ let QlsProductService = class QlsProductService {
271
273
  * Determines if a product needs to be created or updated in QLS based on the given variant and existing QLS product.
272
274
  */
273
275
  async createOrUpdateProductInQls(ctx, client, variant, existingProduct) {
274
- if (this.options.excludeVariantFromSync?.(ctx, variant)) {
276
+ if (await this.options.excludeVariantFromSync?.(ctx, new core_1.Injector(this.moduleRef), variant)) {
275
277
  core_1.Logger.info(`Variant '${variant.sku}' excluded from sync to QLS.`, constants_1.loggerCtx);
276
278
  return 'not-changed';
277
279
  }
@@ -429,5 +431,6 @@ exports.QlsProductService = QlsProductService = __decorate([
429
431
  core_1.StockLocationService,
430
432
  core_1.EventBus,
431
433
  core_1.ListQueryBuilder,
432
- core_1.ProductPriceApplicator])
434
+ core_1.ProductPriceApplicator,
435
+ core_2.ModuleRef])
433
436
  ], QlsProductService);
package/dist/types.d.ts CHANGED
@@ -40,7 +40,7 @@ export interface QlsPluginOptions {
40
40
  * Optional function to determine if a product variant should be excluded from syncing to QLS.
41
41
  * Return true to exclude the variant from sync, false or undefined to include it.
42
42
  */
43
- excludeVariantFromSync?: (ctx: RequestContext, variant: ProductVariant) => boolean | Promise<boolean>;
43
+ excludeVariantFromSync?: (ctx: RequestContext, injector: Injector, variant: ProductVariant) => boolean | Promise<boolean>;
44
44
  /**
45
45
  * Optional function to customize the receiver contact details when creating a QLS order.
46
46
  * Allows you to set different fields or override default mapping from the order's shipping address and customer.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pinelab/vendure-plugin-qls-fulfillment",
3
- "version": "1.0.0-beta.21",
3
+ "version": "1.0.0-beta.23",
4
4
  "description": "Vendure plugin to fulfill orders via QLS.",
5
5
  "keywords": [
6
6
  "fulfillment",