@pinelab/vendure-plugin-qls-fulfillment 1.0.0-beta.3 → 1.0.0-beta.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/README.md CHANGED
@@ -59,8 +59,9 @@ Make sure to monitor failed jobs: A job that failed after its retries were exhau
59
59
  2. A product was not synced to QLS
60
60
 
61
61
  Monitor your logs for the following text:
62
- * `QLS webhook error` - This means an incoming stock update webhook was not processed correctly.
63
- * `Error creating or updating variant` - This means a product was not synced to QLS.
62
+
63
+ - `QLS webhook error` - This means an incoming stock update webhook was not processed correctly.
64
+ - `Error creating or updating variant` - This means a product was not synced to QLS.
64
65
 
65
66
  Make sure to filter by logger context `QlsPlugin`, to prevent false positive alerts.
66
67
 
@@ -86,7 +86,7 @@ class QlsClient {
86
86
  if (!response.ok) {
87
87
  const errorText = await response.text();
88
88
  // Log error including the request body
89
- core_1.Logger.error(`QLS request failed: ${response.status} ${response.statusText} - ${errorText}`, constants_1.loggerCtx, data ? JSON.stringify(data, null, 2) : undefined);
89
+ core_1.Logger.error(`QLS request to '${url}' failed: ${response.status} ${response.statusText} - ${errorText}`, constants_1.loggerCtx, data ? JSON.stringify(data, null, 2) : undefined);
90
90
  throw new Error(errorText);
91
91
  }
92
92
  const contentType = response.headers.get('content-type') ?? '';
@@ -1,8 +1,8 @@
1
1
  import { OnApplicationBootstrap, OnModuleInit } from '@nestjs/common';
2
- import { EventBus, ID, Job, JobQueueService, ProductVariant, ProductVariantService, RequestContext, StockLevelService, StockLocationService, TransactionalConnection } from '@vendure/core';
2
+ import { EventBus, ID, Job, JobQueueService, ListQueryBuilder, ProductPriceApplicator, ProductVariant, ProductVariantService, RequestContext, StockLevelService, StockLocationService, TransactionalConnection } from '@vendure/core';
3
+ import { FulfillmentProduct } from '../lib/client-types';
3
4
  import { QlsClient } from '../lib/qls-client';
4
5
  import { QlsPluginOptions, QlsProductJobData } from '../types';
5
- import { FulfillmentProduct } from '../lib/client-types';
6
6
  type SyncProductsJobResult = {
7
7
  updatedInQls: number;
8
8
  createdInQls: number;
@@ -16,8 +16,10 @@ export declare class QlsProductService implements OnModuleInit, OnApplicationBoo
16
16
  private readonly variantService;
17
17
  private readonly stockLocationService;
18
18
  private readonly eventBus;
19
+ private readonly listQueryBuilder;
20
+ private readonly productPriceApplicator;
19
21
  private productJobQueue;
20
- constructor(connection: TransactionalConnection, options: QlsPluginOptions, jobQueueService: JobQueueService, stockLevelService: StockLevelService, variantService: ProductVariantService, stockLocationService: StockLocationService, eventBus: EventBus);
22
+ constructor(connection: TransactionalConnection, options: QlsPluginOptions, jobQueueService: JobQueueService, stockLevelService: StockLevelService, variantService: ProductVariantService, stockLocationService: StockLocationService, eventBus: EventBus, listQueryBuilder: ListQueryBuilder, productPriceApplicator: ProductPriceApplicator);
21
23
  onApplicationBootstrap(): void;
22
24
  onModuleInit(): Promise<void>;
23
25
  /**
@@ -19,11 +19,12 @@ exports.QlsProductService = void 0;
19
19
  const common_1 = require("@nestjs/common");
20
20
  const core_1 = require("@vendure/core");
21
21
  const catch_unknown_1 = require("catch-unknown");
22
+ const typeorm_1 = require("typeorm");
22
23
  const util_1 = __importDefault(require("util"));
23
24
  const constants_1 = require("../constants");
24
25
  const qls_client_1 = require("../lib/qls-client");
25
26
  let QlsProductService = class QlsProductService {
26
- constructor(connection, options, jobQueueService, stockLevelService, variantService, stockLocationService, eventBus) {
27
+ constructor(connection, options, jobQueueService, stockLevelService, variantService, stockLocationService, eventBus, listQueryBuilder, productPriceApplicator) {
27
28
  this.connection = connection;
28
29
  this.options = options;
29
30
  this.jobQueueService = jobQueueService;
@@ -31,6 +32,8 @@ let QlsProductService = class QlsProductService {
31
32
  this.variantService = variantService;
32
33
  this.stockLocationService = stockLocationService;
33
34
  this.eventBus = eventBus;
35
+ this.listQueryBuilder = listQueryBuilder;
36
+ this.productPriceApplicator = productPriceApplicator;
34
37
  }
35
38
  onApplicationBootstrap() {
36
39
  // Listen for ProductVariantEvent and add a job to the queue
@@ -270,16 +273,21 @@ let QlsProductService = class QlsProductService {
270
273
  const take = 100;
271
274
  let hasMore = true;
272
275
  while (hasMore) {
273
- const result = await this.variantService.findAll(ctx, {
274
- filter: { deletedAt: { isNull: true } },
276
+ const relations = ['featuredAsset', 'taxCategory', 'channels', 'product.featuredAsset'];
277
+ const [items, totalItems] = await this.listQueryBuilder.build(core_1.ProductVariant, {
275
278
  skip,
276
279
  take,
277
- });
278
- if (!result.items.length) {
279
- break;
280
- }
281
- allVariants.push(...result.items);
282
- if (allVariants.length >= result.totalItems) {
280
+ }, {
281
+ relations,
282
+ channelId: ctx.channelId,
283
+ where: { deletedAt: (0, typeorm_1.IsNull)() },
284
+ ctx,
285
+ })
286
+ .getManyAndCount();
287
+ let variants = await Promise.all(items.map(async (item) => this.productPriceApplicator.applyChannelPriceAndTax(item, ctx, undefined, false)));
288
+ variants = variants.map((v) => (0, core_1.translateDeep)(v, ctx.languageCode));
289
+ allVariants.push(...variants);
290
+ if (allVariants.length >= totalItems) {
283
291
  hasMore = false;
284
292
  }
285
293
  skip += take;
@@ -311,5 +319,7 @@ exports.QlsProductService = QlsProductService = __decorate([
311
319
  core_1.StockLevelService,
312
320
  core_1.ProductVariantService,
313
321
  core_1.StockLocationService,
314
- core_1.EventBus])
322
+ core_1.EventBus,
323
+ core_1.ListQueryBuilder,
324
+ core_1.ProductPriceApplicator])
315
325
  ], QlsProductService);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pinelab/vendure-plugin-qls-fulfillment",
3
- "version": "1.0.0-beta.3",
3
+ "version": "1.0.0-beta.4",
4
4
  "description": "Vendure plugin to fulfill orders via QLS.",
5
5
  "keywords": [
6
6
  "fulfillment",