@pinelab/vendure-plugin-qls-fulfillment 1.6.0 → 1.8.0
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/CHANGELOG.md +8 -0
- package/dist/custom-fields.d.ts +1 -0
- package/dist/custom-fields.js +14 -0
- package/dist/lib/client-types.d.ts +1 -0
- package/dist/lib/qls-client.d.ts +1 -0
- package/dist/lib/qls-client.js +7 -0
- package/dist/qls-plugin.js +1 -0
- package/dist/services/qls-order.service.js +1 -1
- package/dist/services/qls-product.service.d.ts +4 -1
- package/dist/services/qls-product.service.js +19 -8
- package/dist/types.d.ts +6 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/custom-fields.d.ts
CHANGED
package/dist/custom-fields.js
CHANGED
|
@@ -15,6 +15,20 @@ function getVariantCustomFields(uiTab) {
|
|
|
15
15
|
readonly: true,
|
|
16
16
|
ui: { tab: uiTab },
|
|
17
17
|
},
|
|
18
|
+
{
|
|
19
|
+
name: 'qlsRawWarehouseStockData',
|
|
20
|
+
type: 'text',
|
|
21
|
+
label: [
|
|
22
|
+
{
|
|
23
|
+
value: 'QLS Raw Warehouse Stock Data',
|
|
24
|
+
languageCode: core_1.LanguageCode.en,
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
nullable: true,
|
|
28
|
+
public: false,
|
|
29
|
+
readonly: true,
|
|
30
|
+
ui: { tab: uiTab },
|
|
31
|
+
},
|
|
18
32
|
];
|
|
19
33
|
}
|
|
20
34
|
exports.orderCustomFields = [
|
package/dist/lib/qls-client.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export declare class QlsClient {
|
|
|
15
15
|
* Returns the first product found, or undefined if no product is found.
|
|
16
16
|
*/
|
|
17
17
|
getFulfillmentProductBySku(sku: string): Promise<FulfillmentProduct | undefined>;
|
|
18
|
+
getFulfillmentProductById(fulfillmentProductId: string): Promise<FulfillmentProduct | undefined>;
|
|
18
19
|
/**
|
|
19
20
|
* Get stock for all fulfillment products.
|
|
20
21
|
* Might require multiple requests if the result is paginated.
|
package/dist/lib/qls-client.js
CHANGED
|
@@ -34,6 +34,13 @@ class QlsClient {
|
|
|
34
34
|
}
|
|
35
35
|
return result.data[0];
|
|
36
36
|
}
|
|
37
|
+
async getFulfillmentProductById(fulfillmentProductId) {
|
|
38
|
+
const result = await this.rawRequest('GET', `fulfillment/products/${fulfillmentProductId}`);
|
|
39
|
+
if (!result.data) {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
return result.data;
|
|
43
|
+
}
|
|
37
44
|
/**
|
|
38
45
|
* Get stock for all fulfillment products.
|
|
39
46
|
* Might require multiple requests if the result is paginated.
|
package/dist/qls-plugin.js
CHANGED
|
@@ -177,7 +177,7 @@ let QlsOrderService = class QlsOrderService {
|
|
|
177
177
|
locality: order.shippingAddress.city,
|
|
178
178
|
country: order.shippingAddress.countryCode.toUpperCase(),
|
|
179
179
|
email: order.customer.emailAddress,
|
|
180
|
-
phone: order.customer.phoneNumber,
|
|
180
|
+
phone: order.shippingAddress.phoneNumber ?? order.customer.phoneNumber,
|
|
181
181
|
},
|
|
182
182
|
products: qlsProducts,
|
|
183
183
|
...(additionalOrderFields ?? {}),
|
|
@@ -62,7 +62,10 @@ export declare class QlsProductService implements OnModuleInit, OnApplicationBoo
|
|
|
62
62
|
/**
|
|
63
63
|
* Determines if a product needs to be created or updated in QLS based on the given variant and existing QLS product.
|
|
64
64
|
*/
|
|
65
|
-
createOrUpdateProductInQls(ctx: RequestContext, client: QlsClient, variant: ProductVariant, existingProduct: FulfillmentProduct | null): Promise<
|
|
65
|
+
createOrUpdateProductInQls(ctx: RequestContext, client: QlsClient, variant: ProductVariant, existingProduct: FulfillmentProduct | null): Promise<{
|
|
66
|
+
status: 'created' | 'updated' | 'not-changed';
|
|
67
|
+
qlsProductId?: string;
|
|
68
|
+
}>;
|
|
66
69
|
/**
|
|
67
70
|
* Update the additional EANs/barcodes for a product in QLS if needed
|
|
68
71
|
*/
|
|
@@ -127,13 +127,13 @@ let QlsProductService = class QlsProductService {
|
|
|
127
127
|
try {
|
|
128
128
|
const existingQlsProduct = allQlsProducts.find((p) => p.sku == variant.sku);
|
|
129
129
|
const result = await this.createOrUpdateProductInQls(ctx, client, variant, existingQlsProduct ?? null);
|
|
130
|
-
if (result === 'created') {
|
|
130
|
+
if (result.status === 'created') {
|
|
131
131
|
createdQlsProducts.push(variant);
|
|
132
132
|
}
|
|
133
|
-
else if (result === 'updated') {
|
|
133
|
+
else if (result.status === 'updated') {
|
|
134
134
|
updatedQlsProducts.push(variant);
|
|
135
135
|
}
|
|
136
|
-
if (result === 'created' || result === 'updated') {
|
|
136
|
+
if (result.status === 'created' || result.status === 'updated') {
|
|
137
137
|
// Wait only if we created or updated a product, otherwise no calls have been made yet.
|
|
138
138
|
await waitToPreventRateLimit();
|
|
139
139
|
}
|
|
@@ -212,12 +212,23 @@ let QlsProductService = class QlsProductService {
|
|
|
212
212
|
try {
|
|
213
213
|
const existingQlsProduct = await client.getFulfillmentProductBySku(variant.sku);
|
|
214
214
|
const result = await this.createOrUpdateProductInQls(ctx, client, variant, existingQlsProduct ?? null);
|
|
215
|
-
if (result === 'created') {
|
|
215
|
+
if (result.status === 'created') {
|
|
216
216
|
createdInQls.push(variant);
|
|
217
217
|
}
|
|
218
|
-
else if (result === 'updated') {
|
|
218
|
+
else if (result.status === 'updated') {
|
|
219
219
|
updatedInQls.push(variant);
|
|
220
220
|
}
|
|
221
|
+
if (result.qlsProductId && this.options.saveRawWarehouseStockData) {
|
|
222
|
+
const qlsProduct = await client.getFulfillmentProductById(result.qlsProductId);
|
|
223
|
+
// Update QLS warehouse stock data in Vendure, only on sync variants to prevent rate limit issues, and only if the option is enabled
|
|
224
|
+
if (qlsProduct && qlsProduct.warehouse_stocks) {
|
|
225
|
+
await this.connection.getRepository(ctx, core_1.ProductVariant).update({ id: variant.id }, {
|
|
226
|
+
customFields: {
|
|
227
|
+
qlsRawWarehouseStockData: JSON.stringify(qlsProduct.warehouse_stocks),
|
|
228
|
+
},
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
}
|
|
221
232
|
}
|
|
222
233
|
catch (e) {
|
|
223
234
|
const error = (0, catch_unknown_1.asError)(e);
|
|
@@ -280,7 +291,7 @@ let QlsProductService = class QlsProductService {
|
|
|
280
291
|
async createOrUpdateProductInQls(ctx, client, variant, existingProduct) {
|
|
281
292
|
if (await this.options.excludeVariantFromSync?.(ctx, new core_1.Injector(this.moduleRef), variant)) {
|
|
282
293
|
core_1.Logger.info(`Variant '${variant.sku}' excluded from sync to QLS.`, constants_1.loggerCtx);
|
|
283
|
-
return 'not-changed';
|
|
294
|
+
return { status: 'not-changed' };
|
|
284
295
|
}
|
|
285
296
|
if (!variant.enabled || !variant.product?.enabled) {
|
|
286
297
|
const disabledEntity = !variant.enabled ? 'Variant' : 'Product';
|
|
@@ -290,7 +301,7 @@ let QlsProductService = class QlsProductService {
|
|
|
290
301
|
else {
|
|
291
302
|
core_1.Logger.info(`${disabledEntity} '${variant.sku}' is disabled, skipping sync to QLS.`, constants_1.loggerCtx);
|
|
292
303
|
}
|
|
293
|
-
return 'not-changed';
|
|
304
|
+
return { status: 'not-changed', qlsProductId: existingProduct?.id };
|
|
294
305
|
}
|
|
295
306
|
let qlsProduct = existingProduct;
|
|
296
307
|
let createdOrUpdated = 'not-changed';
|
|
@@ -332,7 +343,7 @@ let QlsProductService = class QlsProductService {
|
|
|
332
343
|
if (createdOrUpdated === 'not-changed') {
|
|
333
344
|
core_1.Logger.info(`Variant '${variant.sku}' not updated in QLS, because no changes were found.`, constants_1.loggerCtx);
|
|
334
345
|
}
|
|
335
|
-
return createdOrUpdated;
|
|
346
|
+
return { status: createdOrUpdated, qlsProductId: qlsProduct?.id };
|
|
336
347
|
}
|
|
337
348
|
/**
|
|
338
349
|
* Update the additional EANs/barcodes for a product in QLS if needed
|
package/dist/types.d.ts
CHANGED
|
@@ -53,6 +53,12 @@ export interface QlsPluginOptions {
|
|
|
53
53
|
* Defaults to 'QLS'.
|
|
54
54
|
*/
|
|
55
55
|
qlsProductIdUiTab?: string | null;
|
|
56
|
+
/**
|
|
57
|
+
* After syncing a variant to QLS, fetch the full product from QLS and save
|
|
58
|
+
* the raw warehouse stock data in the `qlsRawWarehouseStockData` custom field.
|
|
59
|
+
* Defaults to false.
|
|
60
|
+
*/
|
|
61
|
+
saveRawWarehouseStockData?: boolean;
|
|
56
62
|
/**
|
|
57
63
|
* Additional order items to add to the QLS order.
|
|
58
64
|
*/
|