rerobe-js-orm 4.6.7 → 4.6.9
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/lib/models/Product.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export default class Product extends Base {
|
|
|
11
11
|
toObj(): CompleteProduct;
|
|
12
12
|
toProductInputObjForShopify(location?: string): any;
|
|
13
13
|
toProductInputObjForShopifyV2(locationId: string, weightUnit?: string): any[];
|
|
14
|
-
toProductInputObjForShopifyV3(locationId: string, weightUnit?: string): {
|
|
14
|
+
toProductInputObjForShopifyV3(locationId: string, weightUnit?: string, taxRate?: number): {
|
|
15
15
|
productOptions: {
|
|
16
16
|
name: string;
|
|
17
17
|
values: {
|
package/lib/models/Product.js
CHANGED
|
@@ -295,7 +295,7 @@ class Product extends Base_1.default {
|
|
|
295
295
|
}
|
|
296
296
|
return [productInputObj];
|
|
297
297
|
}
|
|
298
|
-
toProductInputObjForShopifyV3(locationId, weightUnit) {
|
|
298
|
+
toProductInputObjForShopifyV3(locationId, weightUnit, taxRate) {
|
|
299
299
|
var _a;
|
|
300
300
|
const title = this.attributes.title || `Ribbn Product ${this.attributes.handle || this.filterAttributes.documentId}`;
|
|
301
301
|
const inInventoryStatuses = [
|
|
@@ -324,6 +324,14 @@ class Product extends Base_1.default {
|
|
|
324
324
|
compareAtPrice: this.attributes.price || '0',
|
|
325
325
|
taxable: this.attributes.isTaxable === 'yes' ? true : false,
|
|
326
326
|
});
|
|
327
|
+
const applyTaxIfNeeded = (price, taxable) => {
|
|
328
|
+
const rate = typeof taxRate === 'number' && taxRate > 0 ? taxRate : 0;
|
|
329
|
+
const base = Number(price || 0);
|
|
330
|
+
if (!taxable || !rate)
|
|
331
|
+
return String(price !== null && price !== void 0 ? price : '0');
|
|
332
|
+
const adjusted = Number((base * (1 + rate)).toFixed(2));
|
|
333
|
+
return String(adjusted);
|
|
334
|
+
};
|
|
327
335
|
const passedTags = ((_a = this.filterAttributes.tags) === null || _a === void 0 ? void 0 : _a.length) ? this.filterAttributes.tags : [];
|
|
328
336
|
const tags = [
|
|
329
337
|
this.filterAttributes.documentId ? `ribbnId:${this.filterAttributes.documentId}` : null,
|
|
@@ -365,6 +373,9 @@ class Product extends Base_1.default {
|
|
|
365
373
|
variant.price = this.consignmentAttributes.salePrice;
|
|
366
374
|
variant.compareAtPrice = this.attributes.price || variant.compareAtPrice;
|
|
367
375
|
}
|
|
376
|
+
// Apply tax to price and compareAtPrice if taxable
|
|
377
|
+
variant.price = applyTaxIfNeeded(variant.price, Boolean(variant.taxable));
|
|
378
|
+
variant.compareAtPrice = applyTaxIfNeeded(variant.compareAtPrice, Boolean(variant.taxable));
|
|
368
379
|
return Object.assign(Object.assign({ title }, (statusToInclude ? { status: statusToInclude } : {})), { productOptions: [{ name: 'Variant', values: [{ name: title }] }], descriptionHtml: this.attributes.description, vendor: this.filterAttributes.brand, tags,
|
|
369
380
|
files, variants: [variant] });
|
|
370
381
|
}
|
|
@@ -440,6 +451,9 @@ class Product extends Base_1.default {
|
|
|
440
451
|
variant.price = salePrice;
|
|
441
452
|
variant.compareAtPrice = basePrice;
|
|
442
453
|
}
|
|
454
|
+
// Apply tax to price and compareAtPrice if taxable
|
|
455
|
+
variant.price = applyTaxIfNeeded(variant.price, Boolean(variant.taxable));
|
|
456
|
+
variant.compareAtPrice = applyTaxIfNeeded(variant.compareAtPrice, Boolean(variant.taxable));
|
|
443
457
|
return variant;
|
|
444
458
|
});
|
|
445
459
|
return Object.assign(Object.assign({ title }, (statusToInclude ? { status: statusToInclude } : {})), { productOptions, descriptionHtml: this.attributes.description, vendor: this.filterAttributes.brand, tags,
|
|
@@ -580,18 +594,8 @@ class Product extends Base_1.default {
|
|
|
580
594
|
stockTakeFirstTimestamp: null,
|
|
581
595
|
};
|
|
582
596
|
const stockDerivations = this.deriveStockTimestampsFromSystemTags();
|
|
583
|
-
stagedObj.
|
|
584
|
-
|
|
585
|
-
if (stagedObj.stockStatusTimestamp &&
|
|
586
|
-
stagedObj.stockStatusTimestamp === stockDerivations.stockTakeLatestTimestamp) {
|
|
587
|
-
stagedObj.stockStatus = 'In stock';
|
|
588
|
-
}
|
|
589
|
-
else if (stagedObj.stockStatusTimestamp) {
|
|
590
|
-
stagedObj.stockStatus = 'In transit';
|
|
591
|
-
}
|
|
592
|
-
else {
|
|
593
|
-
stagedObj.stockStatus = '';
|
|
594
|
-
}
|
|
597
|
+
stagedObj.stockStatus = this.utilities.sanitizeString(this.filterAttributes.stockStatus);
|
|
598
|
+
stagedObj.stockStatusTimestamp = this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.stockStatusTimestamp);
|
|
595
599
|
stagedObj.stockTakeFirstTimestamp = this.utilities.sanitizeMillisTimeStamp(stockDerivations.stockTakeFirstTimestamp);
|
|
596
600
|
stagedObj.stockTakeLatestTimestamp = this.utilities.sanitizeMillisTimeStamp(stockDerivations.stockTakeLatestTimestamp);
|
|
597
601
|
if (((_a = this.consignmentAttributes) === null || _a === void 0 ? void 0 : _a.inventoryLocations) &&
|
|
@@ -641,25 +645,15 @@ class Product extends Base_1.default {
|
|
|
641
645
|
const stockTakeLatest = parseLatestAndFirstTs(stockTakeTags).latest;
|
|
642
646
|
const inTransitLatest = parseLatestAndFirstTs(inTransitTags).latest;
|
|
643
647
|
const stockTakeLatestSan = stockTakeLatest ? this.utilities.sanitizeMillisTimeStamp(stockTakeLatest) : null;
|
|
648
|
+
const inTransitLatestSan = inTransitLatest ? this.utilities.sanitizeMillisTimeStamp(inTransitLatest) : null;
|
|
644
649
|
const stockTakeFirstRaw = stockTakeTags.length ? parseLatestAndFirstTs(stockTakeTags).first : 0;
|
|
645
650
|
const stockTakeFirstSan = stockTakeFirstRaw ? this.utilities.sanitizeMillisTimeStamp(stockTakeFirstRaw) : null;
|
|
646
|
-
let stockStatusTimestamp = null;
|
|
647
|
-
if (stockTakeLatest === 0 && inTransitLatest === 0) {
|
|
648
|
-
stockStatusTimestamp = null;
|
|
649
|
-
}
|
|
650
|
-
else if (stockTakeLatest >= inTransitLatest) {
|
|
651
|
-
stockStatusTimestamp = stockTakeLatestSan;
|
|
652
|
-
}
|
|
653
|
-
else {
|
|
654
|
-
stockStatusTimestamp = this.utilities.sanitizeMillisTimeStamp(inTransitLatest);
|
|
655
|
-
}
|
|
656
|
-
this.timestampAttributes.stockStatusTimestamp = stockStatusTimestamp;
|
|
657
651
|
this.timestampAttributes.stockTakeFirstTimestamp = stockTakeFirstSan;
|
|
658
652
|
this.timestampAttributes.stockTakeLatestTimestamp = stockTakeLatestSan;
|
|
659
653
|
return {
|
|
660
654
|
stockTakeFirstTimestamp: stockTakeFirstSan,
|
|
661
655
|
stockTakeLatestTimestamp: stockTakeLatestSan,
|
|
662
|
-
|
|
656
|
+
inTransitLatestTimestamp: inTransitLatestSan,
|
|
663
657
|
};
|
|
664
658
|
}
|
|
665
659
|
buildUpdatedFieldsForSalesChannel() {
|
|
@@ -371,7 +371,7 @@ type TypesenseProductObj = {
|
|
|
371
371
|
description: string;
|
|
372
372
|
discountType: string;
|
|
373
373
|
discountValue: number;
|
|
374
|
-
stockStatus:
|
|
374
|
+
stockStatus: string;
|
|
375
375
|
stockStatusTimestamp: number | null;
|
|
376
376
|
id: string;
|
|
377
377
|
documentId: string;
|