rerobe-js-orm 4.5.8 → 4.5.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.
|
@@ -5,6 +5,11 @@ const Order_1 = require("../../models/Order");
|
|
|
5
5
|
const OrderHelpers_1 = require("../../helpers/OrderHelpers");
|
|
6
6
|
const order_constants_1 = require("../../constants/order-constants");
|
|
7
7
|
const orderHelpers = new OrderHelpers_1.default();
|
|
8
|
+
// Helper: build MoneyBag with defaults; if presentment missing, copy from shop, and vice versa
|
|
9
|
+
const buildMoneyBagFromAmount = (amount, currency) => ({
|
|
10
|
+
shopMoney: { amount: amount !== undefined ? amount : 0, currencyCode: currency || '' },
|
|
11
|
+
presentmentMoney: { amount: amount !== undefined ? amount : 0, currencyCode: currency || '' },
|
|
12
|
+
});
|
|
8
13
|
const fulfillmentStatusRestMapping = {
|
|
9
14
|
fulfilled: 'FULFILLED',
|
|
10
15
|
null: '',
|
|
@@ -327,7 +332,7 @@ class OrderFromShopifyWebhook extends OrderFactory_1.default {
|
|
|
327
332
|
const taxLinesV2 = tax_lines.map((item) => ({
|
|
328
333
|
rate: item.rate,
|
|
329
334
|
title: item.title,
|
|
330
|
-
priceSet:
|
|
335
|
+
priceSet: buildMoneyBagFromAmount(item.price, currency || ''),
|
|
331
336
|
}));
|
|
332
337
|
const shippingLine = shipping_lines && shipping_lines.length
|
|
333
338
|
? {
|
|
@@ -438,10 +443,7 @@ class OrderFromShopifyWebhook extends OrderFactory_1.default {
|
|
|
438
443
|
const taxLinesV3 = (tax_lines || []).map((item) => ({
|
|
439
444
|
rate: item.rate,
|
|
440
445
|
title: item.title,
|
|
441
|
-
priceSet:
|
|
442
|
-
shopMoney: { amount: item.price, currencyCode: currency || '' },
|
|
443
|
-
presentmentMoney: { amount: item.price, currencyCode: currency || '' },
|
|
444
|
-
},
|
|
446
|
+
priceSet: buildMoneyBagFromAmount(item.price, currency || ''),
|
|
445
447
|
}));
|
|
446
448
|
const shippingLine = shipping_lines && shipping_lines.length
|
|
447
449
|
? {
|
package/lib/models/Order.js
CHANGED
|
@@ -99,33 +99,46 @@ class Order extends Base_1.default {
|
|
|
99
99
|
this.customerName = (props === null || props === void 0 ? void 0 : props.customerName) || '';
|
|
100
100
|
this.merchantId = (props === null || props === void 0 ? void 0 : props.merchantId) || '';
|
|
101
101
|
this.refunds = (props === null || props === void 0 ? void 0 : props.refunds) || [];
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
amount
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
102
|
+
const defaultPresentmentFrom = (present, base) => {
|
|
103
|
+
const coerceAmount = (val) => {
|
|
104
|
+
const num = Number(val);
|
|
105
|
+
if (!Number.isFinite(num))
|
|
106
|
+
return NaN;
|
|
107
|
+
const rounded = Math.round((num + Number.EPSILON) * 100) / 100;
|
|
108
|
+
return Number(rounded.toFixed(2));
|
|
109
|
+
};
|
|
110
|
+
// Try presentment first
|
|
111
|
+
if (present && typeof present === 'object' && 'amount' in present) {
|
|
112
|
+
const amt = coerceAmount(present.amount);
|
|
113
|
+
if (!Number.isNaN(amt)) {
|
|
114
|
+
return {
|
|
115
|
+
amount: amt,
|
|
116
|
+
currencyCode: present.currencyCode || (base === null || base === void 0 ? void 0 : base.currencyCode) || this.currencyCode || '',
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
// Fallback to base
|
|
121
|
+
if (base && typeof base === 'object' && 'amount' in base) {
|
|
122
|
+
const amt = coerceAmount(base.amount);
|
|
123
|
+
if (!Number.isNaN(amt)) {
|
|
124
|
+
return {
|
|
125
|
+
amount: amt,
|
|
126
|
+
currencyCode: base.currencyCode || this.currencyCode || '',
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
// Final default
|
|
131
|
+
return { amount: 0, currencyCode: this.currencyCode || '' };
|
|
128
132
|
};
|
|
133
|
+
this.subtotalPricePresentment = defaultPresentmentFrom(props === null || props === void 0 ? void 0 : props.subtotalPricePresentment, this.subtotalPrice);
|
|
134
|
+
this.totalDiscountPresentment = defaultPresentmentFrom(props === null || props === void 0 ? void 0 : props.totalDiscountPresentment, this.totalDiscount);
|
|
135
|
+
this.totalPricePresentment = defaultPresentmentFrom(props === null || props === void 0 ? void 0 : props.totalPricePresentment, this.totalPrice);
|
|
136
|
+
this.totalRefundedPresentment = defaultPresentmentFrom(props === null || props === void 0 ? void 0 : props.totalRefundedPresentment, this.totalRefunded);
|
|
137
|
+
this.totalShippingPricePresentment = defaultPresentmentFrom(props === null || props === void 0 ? void 0 : props.totalShippingPricePresentment, this.totalShippingPrice);
|
|
138
|
+
this.totalTaxPresentment = defaultPresentmentFrom(props === null || props === void 0 ? void 0 : props.totalTaxPresentment, this.totalTax);
|
|
139
|
+
this.creditDiscountPresentment = defaultPresentmentFrom(props === null || props === void 0 ? void 0 : props.creditDiscountPresentment, this.creditDiscount);
|
|
140
|
+
this.saleDiscountPresentment = defaultPresentmentFrom(props === null || props === void 0 ? void 0 : props.saleDiscountPresentment, this.saleDiscount);
|
|
141
|
+
this.additionalDiscountPresentment = defaultPresentmentFrom(props === null || props === void 0 ? void 0 : props.additionalDiscountPresentment, this.additionalDiscount);
|
|
129
142
|
this.createdAtTimestamp = (props === null || props === void 0 ? void 0 : props.createdAtTimestamp) || 0;
|
|
130
143
|
this.updatedAtTimestamp = (props === null || props === void 0 ? void 0 : props.updatedAtTimestamp) || 0;
|
|
131
144
|
this.adjustments = (props === null || props === void 0 ? void 0 : props.adjustments) || [];
|
package/lib/models/Product.d.ts
CHANGED
|
@@ -12,8 +12,6 @@ export default class Product extends Base {
|
|
|
12
12
|
toProductInputObjForShopify(location?: string): any;
|
|
13
13
|
toProductInputObjForShopifyV2(locationId: string, weightUnit?: string): any[];
|
|
14
14
|
toProductInputObjForShopifyV3(locationId: string, weightUnit?: string): {
|
|
15
|
-
title: string;
|
|
16
|
-
status: string;
|
|
17
15
|
productOptions: {
|
|
18
16
|
name: string;
|
|
19
17
|
values: {
|
|
@@ -21,14 +19,14 @@ export default class Product extends Base {
|
|
|
21
19
|
}[];
|
|
22
20
|
}[];
|
|
23
21
|
descriptionHtml: string;
|
|
24
|
-
productType: string;
|
|
25
|
-
vendor: string;
|
|
26
22
|
tags: (string | null)[];
|
|
27
23
|
files: {
|
|
28
24
|
originalSource: string;
|
|
29
25
|
contentType: string;
|
|
30
26
|
}[];
|
|
31
27
|
variants: any[];
|
|
28
|
+
status?: string | undefined;
|
|
29
|
+
title: string;
|
|
32
30
|
};
|
|
33
31
|
toObjForTextTranslation(): TranslatableAttributes;
|
|
34
32
|
toObjForTypesense(isCanonicalMerchant?: boolean): TypesenseProductObj;
|
package/lib/models/Product.js
CHANGED
|
@@ -333,6 +333,9 @@ class Product extends Base_1.default {
|
|
|
333
333
|
const variantsFromInventory = Array.isArray(this.attributes.variantInventory)
|
|
334
334
|
? this.attributes.variantInventory
|
|
335
335
|
: [];
|
|
336
|
+
const hasShopifyId = !!this.attributes.shopifyId;
|
|
337
|
+
const currentStatus = String(this.consignmentAttributes.status || '').toUpperCase();
|
|
338
|
+
const statusToInclude = !hasShopifyId || currentStatus.includes('SOLD') ? 'DRAFT' : undefined;
|
|
336
339
|
if (variantsFromInventory.length === 0) {
|
|
337
340
|
// Fallback: single-variant product (legacy behavior)
|
|
338
341
|
const variant = Object.assign(Object.assign({ id: '' }, baseVariantFields()), { inventoryQuantities: [
|
|
@@ -351,17 +354,8 @@ class Product extends Base_1.default {
|
|
|
351
354
|
variant.price = this.consignmentAttributes.salePrice;
|
|
352
355
|
variant.compareAtPrice = this.attributes.price || variant.compareAtPrice;
|
|
353
356
|
}
|
|
354
|
-
return {
|
|
355
|
-
|
|
356
|
-
status: 'DRAFT',
|
|
357
|
-
productOptions: [{ name: 'Variant', values: [{ name: title }] }],
|
|
358
|
-
descriptionHtml: this.attributes.description,
|
|
359
|
-
productType: this.filterAttributes.productType,
|
|
360
|
-
vendor: this.attributes.vendorId,
|
|
361
|
-
tags,
|
|
362
|
-
files,
|
|
363
|
-
variants: [variant],
|
|
364
|
-
};
|
|
357
|
+
return Object.assign(Object.assign({ title }, (statusToInclude ? { status: statusToInclude } : {})), { productOptions: [{ name: 'Variant', values: [{ name: title }] }], descriptionHtml: this.attributes.description, tags,
|
|
358
|
+
files, variants: [variant] });
|
|
365
359
|
}
|
|
366
360
|
// Multi-variant: derive axes and values from variantInventory
|
|
367
361
|
const axisOrder = [];
|
|
@@ -437,17 +431,9 @@ class Product extends Base_1.default {
|
|
|
437
431
|
}
|
|
438
432
|
return variant;
|
|
439
433
|
});
|
|
440
|
-
return {
|
|
441
|
-
title,
|
|
442
|
-
status: 'DRAFT',
|
|
443
|
-
productOptions,
|
|
444
|
-
descriptionHtml: this.attributes.description,
|
|
445
|
-
productType: this.filterAttributes.productType,
|
|
446
|
-
vendor: this.attributes.vendorId,
|
|
447
|
-
tags,
|
|
434
|
+
return Object.assign(Object.assign({ title }, (statusToInclude ? { status: statusToInclude } : {})), { productOptions, descriptionHtml: this.attributes.description, tags,
|
|
448
435
|
files,
|
|
449
|
-
variants
|
|
450
|
-
};
|
|
436
|
+
variants });
|
|
451
437
|
}
|
|
452
438
|
toObjForTextTranslation() {
|
|
453
439
|
return {
|