@pinelab/vendure-plugin-qls-fulfillment 1.0.0-beta.2 → 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
|
@@ -58,7 +58,12 @@ Make sure to monitor failed jobs: A job that failed after its retries were exhau
|
|
|
58
58
|
1. An order was not pushed to QLS
|
|
59
59
|
2. A product was not synced to QLS
|
|
60
60
|
|
|
61
|
-
Monitor your logs for the
|
|
61
|
+
Monitor your logs for the following text:
|
|
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.
|
|
65
|
+
|
|
66
|
+
Make sure to filter by logger context `QlsPlugin`, to prevent false positive alerts.
|
|
62
67
|
|
|
63
68
|
## Cancelling orders and manually pushing orders to QLS
|
|
64
69
|
|
package/dist/lib/qls-client.js
CHANGED
|
@@ -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
|
|
@@ -108,13 +111,19 @@ let QlsProductService = class QlsProductService {
|
|
|
108
111
|
let createdQlsProductsCount = 0;
|
|
109
112
|
let updatedQlsProductsCount = 0;
|
|
110
113
|
for (const variant of allVariants) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
114
|
+
try {
|
|
115
|
+
const existingQlsProduct = allQlsProducts.find((p) => p.sku == variant.sku);
|
|
116
|
+
const result = await this.createOrUpdateProductInQls(ctx, client, variant, existingQlsProduct ?? null);
|
|
117
|
+
if (result === 'created') {
|
|
118
|
+
createdQlsProductsCount += 1;
|
|
119
|
+
}
|
|
120
|
+
else if (result === 'updated') {
|
|
121
|
+
updatedQlsProductsCount += 1;
|
|
122
|
+
}
|
|
115
123
|
}
|
|
116
|
-
|
|
117
|
-
|
|
124
|
+
catch (e) {
|
|
125
|
+
const error = (0, catch_unknown_1.asError)(e);
|
|
126
|
+
core_1.Logger.error(`Error creating or updating variant '${variant.sku}' in QLS: ${error.message}`, constants_1.loggerCtx, error.stack);
|
|
118
127
|
}
|
|
119
128
|
}
|
|
120
129
|
core_1.Logger.info(`Created ${createdQlsProductsCount} products in QLS`, constants_1.loggerCtx);
|
|
@@ -264,16 +273,21 @@ let QlsProductService = class QlsProductService {
|
|
|
264
273
|
const take = 100;
|
|
265
274
|
let hasMore = true;
|
|
266
275
|
while (hasMore) {
|
|
267
|
-
const
|
|
268
|
-
|
|
276
|
+
const relations = ['featuredAsset', 'taxCategory', 'channels', 'product.featuredAsset'];
|
|
277
|
+
const [items, totalItems] = await this.listQueryBuilder.build(core_1.ProductVariant, {
|
|
269
278
|
skip,
|
|
270
279
|
take,
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
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) {
|
|
277
291
|
hasMore = false;
|
|
278
292
|
}
|
|
279
293
|
skip += take;
|
|
@@ -305,5 +319,7 @@ exports.QlsProductService = QlsProductService = __decorate([
|
|
|
305
319
|
core_1.StockLevelService,
|
|
306
320
|
core_1.ProductVariantService,
|
|
307
321
|
core_1.StockLocationService,
|
|
308
|
-
core_1.EventBus
|
|
322
|
+
core_1.EventBus,
|
|
323
|
+
core_1.ListQueryBuilder,
|
|
324
|
+
core_1.ProductPriceApplicator])
|
|
309
325
|
], QlsProductService);
|