rerobe-js-orm 2.9.9 → 3.0.3
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/factories/Order/OrderFromFormState.js +12 -12
- package/lib/form-states/Order/OrderFormState.d.ts +0 -1
- package/lib/form-states/Order/OrderFormState.js +6 -12
- package/lib/helpers/Utilities.d.ts +4 -0
- package/lib/helpers/Utilities.js +9 -0
- package/lib/models/Product.d.ts +1 -0
- package/lib/models/Product.js +102 -0
- package/package.json +1 -1
|
@@ -5,24 +5,24 @@ const Order_1 = require("../../models/Order");
|
|
|
5
5
|
const order_constants_1 = require("../../constants/order-constants");
|
|
6
6
|
class OrderFromFormState extends OrderFactory_1.default {
|
|
7
7
|
createOrder(fs) {
|
|
8
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u
|
|
8
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
|
|
9
9
|
const currencyCode = fs.fields.currencyCode.inputValue || 'SEK';
|
|
10
10
|
const customer = fs.fields.customer.selectedValue || {};
|
|
11
11
|
const customerAttr = {
|
|
12
12
|
userId: (customer === null || customer === void 0 ? void 0 : customer.uid) || (customer === null || customer === void 0 ? void 0 : customer.documentId) || '',
|
|
13
|
-
customerName:
|
|
13
|
+
customerName: `${fs.fields.firstName.inputValue} ${fs.fields.lastName.inputValue}`.trim(),
|
|
14
14
|
email: fs.fields.email.inputValue || '',
|
|
15
15
|
phone: fs.fields.phone.inputValue || '',
|
|
16
|
-
customerUrl: ((
|
|
16
|
+
customerUrl: ((_a = fs.props) === null || _a === void 0 ? void 0 : _a.customerUrl) || '',
|
|
17
17
|
};
|
|
18
18
|
const discountsAttr = {
|
|
19
19
|
appliedDiscount: {
|
|
20
|
-
amount: ((
|
|
21
|
-
value: ((
|
|
22
|
-
title: fs.fields.presentmentData.selectedValue.discountTitlePresentment || ((
|
|
20
|
+
amount: ((_b = fs.fields) === null || _b === void 0 ? void 0 : _b.totalDiscount.inputValue) || 0,
|
|
21
|
+
value: ((_c = fs.fields) === null || _c === void 0 ? void 0 : _c.totalDiscount.inputValue) || 0,
|
|
22
|
+
title: fs.fields.presentmentData.selectedValue.discountTitlePresentment || ((_d = fs.fields) === null || _d === void 0 ? void 0 : _d.discountTitle.inputValue) || '',
|
|
23
23
|
valueType: 'FIXED_AMOUNT',
|
|
24
24
|
},
|
|
25
|
-
discountApplications: ((
|
|
25
|
+
discountApplications: ((_e = fs.props) === null || _e === void 0 ? void 0 : _e.discountApplications) || [],
|
|
26
26
|
creditDiscount: { amount: fs.fields.creditDiscount.inputValue || 0, currencyCode },
|
|
27
27
|
saleDiscount: { amount: fs.fields.saleDiscount.inputValue || 0, currencyCode },
|
|
28
28
|
additionalDiscount: { amount: fs.fields.additionalDiscount.inputValue || 0, currencyCode },
|
|
@@ -38,11 +38,11 @@ class OrderFromFormState extends OrderFactory_1.default {
|
|
|
38
38
|
zip: '',
|
|
39
39
|
};
|
|
40
40
|
const shippingAndLocationAttr = {
|
|
41
|
-
fulfillmentLocations: ((
|
|
41
|
+
fulfillmentLocations: ((_f = fs.fields.shippingInfo.selectedValue) === null || _f === void 0 ? void 0 : _f.productsLocationsMapping) || [],
|
|
42
42
|
shippingAddress: fs.fields.shippingType.selectedValue === order_constants_1.SHIPPING_TYPES.localPickUp
|
|
43
43
|
? initShippingAddress
|
|
44
44
|
: fs.fields.shippingAddress.selectedValue || initShippingAddress,
|
|
45
|
-
shippingDiscountAllocations: ((
|
|
45
|
+
shippingDiscountAllocations: ((_g = fs.props) === null || _g === void 0 ? void 0 : _g.shippingDiscountAllocations) || [],
|
|
46
46
|
shippingLine: fs.fields.shippingLine
|
|
47
47
|
? fs.fields.shippingLine.selectedValue
|
|
48
48
|
: {
|
|
@@ -93,12 +93,12 @@ class OrderFromFormState extends OrderFactory_1.default {
|
|
|
93
93
|
originalTotalPrice: { amount: fs.fields.originalTotalPrice.inputValue || 0, currencyCode },
|
|
94
94
|
};
|
|
95
95
|
const statusesAttr = {
|
|
96
|
-
state: ((
|
|
96
|
+
state: ((_h = fs.props) === null || _h === void 0 ? void 0 : _h.state) || Order_1.default.ORDER_STATES.draft,
|
|
97
97
|
financialStatus: fs.fields.financialStatus.selectedValue,
|
|
98
98
|
fulfillmentStatus: fs.fields.fulfillmentStatus.selectedValue,
|
|
99
|
-
statusUrl: ((
|
|
99
|
+
statusUrl: ((_j = fs.props) === null || _j === void 0 ? void 0 : _j.statusUrl) || '',
|
|
100
100
|
};
|
|
101
|
-
const orderAttributes = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, totalPricesAttr), presentmentTotalPricesAttr), discountsAttr), shippingAndLocationAttr), customerAttr), statusesAttr), { id: ((
|
|
101
|
+
const orderAttributes = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, totalPricesAttr), presentmentTotalPricesAttr), discountsAttr), shippingAndLocationAttr), customerAttr), statusesAttr), { id: ((_k = fs.props) === null || _k === void 0 ? void 0 : _k.id) || '', documentId: ((_l = fs.props) === null || _l === void 0 ? void 0 : _l.documentId) || '', name: ((_m = fs.props) === null || _m === void 0 ? void 0 : _m.name) || '', orderNumber: (_o = fs.props) === null || _o === void 0 ? void 0 : _o.orderNumber, ribbnOrderNumber: (_p = fs.props) === null || _p === void 0 ? void 0 : _p.ribbnOrderNumber, merchantId: ((_q = fs.props) === null || _q === void 0 ? void 0 : _q.merchantId) || '', currencyCode: fs.fields.currencyCode.inputValue, lineItems: fs.fields.lineItems.selectedValues || [], fulfillments: ((_r = fs.props) === null || _r === void 0 ? void 0 : _r.fulfillments) || [], refunds: ((_s = fs.props) === null || _s === void 0 ? void 0 : _s.refunds) || [], paymentType: fs.fields.paymentType.selectedValue, paymentMethod: fs.fields.paymentMethod.selectedValue || '', paymentDetails: fs.fields.paymentDetails.selectedValue || {}, notes: fs.fields.notes.inputValue || '', tags: fs.fields.tags.selectedValues || [], cancelReason: fs.fields.cancelReason.selectedValue || '', canceledAt: ((_t = fs.props) === null || _t === void 0 ? void 0 : _t.canceledAt) || '', processedAt: ((_u = fs.props) === null || _u === void 0 ? void 0 : _u.processedAt) || new Date().toUTCString(), createdAtTimestamp: 0, updatedAtTimestamp: 0 });
|
|
102
102
|
return new Order_1.default(Object.assign({}, orderAttributes));
|
|
103
103
|
}
|
|
104
104
|
}
|
|
@@ -97,13 +97,6 @@ class OrderFormState extends FormState_1.default {
|
|
|
97
97
|
// Update total price
|
|
98
98
|
this.fields.totalPrice.inputValue = Number(Number(this.fields.subtotalPrice.inputValue) - Number(this.fields.totalDiscount.inputValue) + Number(val)).toFixed(2);
|
|
99
99
|
}
|
|
100
|
-
customerChangeHandler(customer) {
|
|
101
|
-
this.fields.customer.selectedValue = customer;
|
|
102
|
-
this.fields.email.inputValue = (customer === null || customer === void 0 ? void 0 : customer.email) || '';
|
|
103
|
-
this.fields.phone.inputValue = (customer === null || customer === void 0 ? void 0 : customer.phone) || '';
|
|
104
|
-
this.fields.firstName.inputValue = (customer === null || customer === void 0 ? void 0 : customer.displayName) || (customer === null || customer === void 0 ? void 0 : customer.firstName) || '';
|
|
105
|
-
this.fields.lastName.inputValue = !(customer === null || customer === void 0 ? void 0 : customer.displayName) && (customer === null || customer === void 0 ? void 0 : customer.lastName) ? customer === null || customer === void 0 ? void 0 : customer.lastName : '';
|
|
106
|
-
}
|
|
107
100
|
fieldFactory(fieldType, fieldKey, fieldOptions) {
|
|
108
101
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0;
|
|
109
102
|
let options = fieldOptions || [];
|
|
@@ -111,10 +104,12 @@ class OrderFormState extends FormState_1.default {
|
|
|
111
104
|
if (fieldType === 'textInput') {
|
|
112
105
|
let inputValue = this.props[fieldKey] || '';
|
|
113
106
|
if (fieldKey === 'firstName') {
|
|
114
|
-
|
|
107
|
+
const { firstName } = this.utilities.getFirstNameAndLastNameFromDisplayName(this.props.customerName || '');
|
|
108
|
+
inputValue = firstName;
|
|
115
109
|
}
|
|
116
110
|
if (fieldKey === 'lastName') {
|
|
117
|
-
|
|
111
|
+
const { lastName } = this.utilities.getFirstNameAndLastNameFromDisplayName(this.props.customerName || '');
|
|
112
|
+
inputValue = lastName;
|
|
118
113
|
}
|
|
119
114
|
if (fieldKey === 'discountTitle') {
|
|
120
115
|
inputValue = ((_b = (_a = this.props) === null || _a === void 0 ? void 0 : _a.appliedDiscount) === null || _b === void 0 ? void 0 : _b.title) || '';
|
|
@@ -186,16 +181,15 @@ class OrderFormState extends FormState_1.default {
|
|
|
186
181
|
additionalDiscountPresentment: ((_y = this.props) === null || _y === void 0 ? void 0 : _y.additionalDiscountPresentment) || { amount: 0 },
|
|
187
182
|
};
|
|
188
183
|
}
|
|
189
|
-
const valid = !!this.props[fieldKey];
|
|
190
|
-
let onChangeHandler = (val) => this.singleSelectChangeHandler(fieldKey, val);
|
|
191
184
|
if (fieldKey === 'customer') {
|
|
192
185
|
selectedValue = {
|
|
193
186
|
uid: this.props.userId,
|
|
194
187
|
email: this.props.email,
|
|
195
188
|
displayName: this.props.customerName,
|
|
196
189
|
};
|
|
197
|
-
onChangeHandler = (val) => this.customerChangeHandler(val);
|
|
198
190
|
}
|
|
191
|
+
const valid = !!this.props[fieldKey];
|
|
192
|
+
const onChangeHandler = (val) => this.singleSelectChangeHandler(fieldKey, val);
|
|
199
193
|
if (fieldKey === 'shippingType') {
|
|
200
194
|
if ((_0 = (_z = this.opts) === null || _z === void 0 ? void 0 : _z.shippingTypeOptions) === null || _0 === void 0 ? void 0 : _0.length) {
|
|
201
195
|
options = this.utilities.uniqObjArray(this.opts.shippingTypeOptions, 'value');
|
|
@@ -17,4 +17,8 @@ export default class Utilities {
|
|
|
17
17
|
isProperString(name: any): boolean;
|
|
18
18
|
toProperString(name: any): string;
|
|
19
19
|
getAddressLabel(address: AddressInput): string;
|
|
20
|
+
getFirstNameAndLastNameFromDisplayName(displayName: string): {
|
|
21
|
+
firstName: string;
|
|
22
|
+
lastName: string;
|
|
23
|
+
};
|
|
20
24
|
}
|
package/lib/helpers/Utilities.js
CHANGED
|
@@ -137,5 +137,14 @@ class Utilities {
|
|
|
137
137
|
return res;
|
|
138
138
|
}, '');
|
|
139
139
|
}
|
|
140
|
+
getFirstNameAndLastNameFromDisplayName(displayName) {
|
|
141
|
+
const res = { firstName: '', lastName: '' };
|
|
142
|
+
const fixedDisplayName = displayName ? displayName.trim() : '';
|
|
143
|
+
if (fixedDisplayName) {
|
|
144
|
+
res.firstName = fixedDisplayName.split(' ')[0];
|
|
145
|
+
res.lastName = fixedDisplayName.split(' ').length > 1 ? fixedDisplayName.split(' ')[1] : '';
|
|
146
|
+
}
|
|
147
|
+
return res;
|
|
148
|
+
}
|
|
140
149
|
}
|
|
141
150
|
exports.default = Utilities;
|
package/lib/models/Product.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export default class Product extends Base {
|
|
|
9
9
|
toPartialObj(): ShopifyProduct;
|
|
10
10
|
toObj(): CompleteProduct;
|
|
11
11
|
toProductInputObjForShopify(location?: string): any;
|
|
12
|
+
toProductInputObjForShopifyV2(locationId: string, weightUnit?: string): any[];
|
|
12
13
|
toObjForTextTranslation(): TranslatableAttributes;
|
|
13
14
|
toObjForTypesense(): TypesenseProductObj;
|
|
14
15
|
updateSelfFromTranslatedTextArray(translatedTextArray?: string[]): void;
|
package/lib/models/Product.js
CHANGED
|
@@ -220,6 +220,108 @@ class Product extends Base_1.default {
|
|
|
220
220
|
}
|
|
221
221
|
return productInputObj;
|
|
222
222
|
}
|
|
223
|
+
toProductInputObjForShopifyV2(locationId, weightUnit) {
|
|
224
|
+
const shopifyId = this.attributes.shopifyId;
|
|
225
|
+
const productInputObj = {
|
|
226
|
+
title: this.attributes.title,
|
|
227
|
+
descriptionHtml: this.attributes.description,
|
|
228
|
+
productType: this.filterAttributes.productType,
|
|
229
|
+
vendor: this.attributes.vendorId,
|
|
230
|
+
tags: [
|
|
231
|
+
`gender_attribute:${this.filterAttributes.gender}`,
|
|
232
|
+
`productcategory_attribute:${this.filterAttributes.productCategory}`,
|
|
233
|
+
`producttype_attribute:${this.filterAttributes.productType}`,
|
|
234
|
+
`brand_attribute:${this.filterAttributes.brand}`,
|
|
235
|
+
`pricerange_attribute:${this.filterAttributes.priceRange}`,
|
|
236
|
+
`color_attribute:${this.filterAttributes.color}`,
|
|
237
|
+
`condition_attribute:${this.filterAttributes.condition}`,
|
|
238
|
+
`publishType:${this.consignmentAttributes.publishType}`,
|
|
239
|
+
this.filterAttributes.jeanSize ? `jeansize_attribute:${this.filterAttributes.jeanSize}` : null,
|
|
240
|
+
this.filterAttributes.shoeSize ? `shoesize_attribute:${this.filterAttributes.shoeSize}` : null,
|
|
241
|
+
this.filterAttributes.documentId ? `documentId:${this.filterAttributes.documentId}` : null,
|
|
242
|
+
this.consignmentAttributes.sellRequestId ? `sellRequestId:${this.consignmentAttributes.sellRequestId}` : null,
|
|
243
|
+
this.consignmentAttributes.reRobeCommission
|
|
244
|
+
? `reRobeCommission:${this.consignmentAttributes.reRobeCommission}`
|
|
245
|
+
: null,
|
|
246
|
+
this.consignmentAttributes.suggestedResalePrice
|
|
247
|
+
? `suggestedResalePrice:${this.consignmentAttributes.suggestedResalePrice}`
|
|
248
|
+
: null,
|
|
249
|
+
this.consignmentAttributes.nextAvailableSeason
|
|
250
|
+
? `nextAvailableSeason:${this.consignmentAttributes.nextAvailableSeason}`
|
|
251
|
+
: null,
|
|
252
|
+
this.consignmentAttributes.notesForProductionTeam
|
|
253
|
+
? `notesForProductionTeam:${this.consignmentAttributes.notesForProductionTeam}`
|
|
254
|
+
: null,
|
|
255
|
+
this.consignmentAttributes.reviewedBy ? `reviewedBy:${this.consignmentAttributes.reviewedBy}` : null,
|
|
256
|
+
this.consignmentAttributes.conditionRemarks
|
|
257
|
+
? `conditionRemarks:${this.consignmentAttributes.conditionRemarks}`
|
|
258
|
+
: null,
|
|
259
|
+
this.consignmentAttributes.productRemarks
|
|
260
|
+
? `productRemarks:${this.consignmentAttributes.productRemarks}`
|
|
261
|
+
: null,
|
|
262
|
+
this.consignmentAttributes.status ? `status:${this.consignmentAttributes.status}` : null,
|
|
263
|
+
this.consignmentAttributes.purchasePrice ? `purchasePrice:${this.consignmentAttributes.purchasePrice}` : null,
|
|
264
|
+
this.consignmentAttributes.yearPurchased ? `yearPurchased:${this.consignmentAttributes.yearPurchased}` : null,
|
|
265
|
+
this.consignmentAttributes.rejectedReason
|
|
266
|
+
? `rejectedReason:${this.consignmentAttributes.rejectedReason}`
|
|
267
|
+
: null,
|
|
268
|
+
this.consignmentAttributes.dateSold ? `dateSold:${this.consignmentAttributes.dateSold}` : null,
|
|
269
|
+
this.consignmentAttributes.dateInQualityControl
|
|
270
|
+
? `dateInQualityControl:${this.consignmentAttributes.dateInQualityControl}`
|
|
271
|
+
: null,
|
|
272
|
+
this.consignmentAttributes.dateInPendingPublication
|
|
273
|
+
? `dateInPendingPublication:${this.consignmentAttributes.dateInPendingPublication}`
|
|
274
|
+
: null,
|
|
275
|
+
this.consignmentAttributes.dateListedOnline
|
|
276
|
+
? `dateListedOnline:${this.consignmentAttributes.dateListedOnline}`
|
|
277
|
+
: null,
|
|
278
|
+
this.consignmentAttributes.sizeComment ? `sizeComment:${this.consignmentAttributes.sizeComment}` : null,
|
|
279
|
+
this.consignmentAttributes.salePrice ? `salePrice:${this.consignmentAttributes.salePrice}` : null,
|
|
280
|
+
this.consignmentAttributes.isOnSale ? `isOnSale:${this.consignmentAttributes.isOnSale}` : null,
|
|
281
|
+
this.consignmentAttributes.discountType ? `discountType:${this.consignmentAttributes.discountType}` : null,
|
|
282
|
+
this.consignmentAttributes.discountValue ? `discountValue:${this.consignmentAttributes.discountValue}` : null,
|
|
283
|
+
this.consignmentAttributes.selectedForClearance
|
|
284
|
+
? `selectedForClearance:${this.consignmentAttributes.selectedForClearance}`
|
|
285
|
+
: null,
|
|
286
|
+
]
|
|
287
|
+
.concat(this.filterAttributes.clothingSize.map((s) => `clothingsize_attribute:${s}`))
|
|
288
|
+
.concat(this.filterAttributes.productStyle.map((s) => `productstyle_attribute:${s}`))
|
|
289
|
+
.concat(this.materialCompTagsArrayForShopify().map((mc) => `materialcomposition_attribute:${mc}`))
|
|
290
|
+
.concat(this.consignmentAttributes.previousSellers.map((prevSellerGid) => `previousSeller:${prevSellerGid}`))
|
|
291
|
+
.concat(this.consignmentAttributes.salesChannel.map((s) => `salesChannel:${s}`))
|
|
292
|
+
.filter((t) => t),
|
|
293
|
+
variants: [
|
|
294
|
+
{
|
|
295
|
+
inventoryPolicy: 'DENY',
|
|
296
|
+
inventoryQuantities: [
|
|
297
|
+
{
|
|
298
|
+
availableQuantity: this.attributes.availableForSale ? 1 : 0,
|
|
299
|
+
locationId: `${locationId}`,
|
|
300
|
+
},
|
|
301
|
+
],
|
|
302
|
+
price: this.attributes.price || '0',
|
|
303
|
+
taxable: false,
|
|
304
|
+
weight: parseFloat(this.attributes.weight) || parseFloat('999'),
|
|
305
|
+
weightUnit: weightUnit || 'GRAMS',
|
|
306
|
+
},
|
|
307
|
+
],
|
|
308
|
+
};
|
|
309
|
+
if (shopifyId) {
|
|
310
|
+
// Todo: use getDecodedShopifyId here
|
|
311
|
+
productInputObj.id = shopifyId;
|
|
312
|
+
productInputObj.variants = [
|
|
313
|
+
Object.assign({}, productInputObj.variants[0]),
|
|
314
|
+
];
|
|
315
|
+
}
|
|
316
|
+
if (this.attributes.imageUrls) {
|
|
317
|
+
const projectMediaObj = this.attributes.imageUrls.map((image) => ({
|
|
318
|
+
mediaContentType: 'IMAGE',
|
|
319
|
+
originalSource: image,
|
|
320
|
+
}));
|
|
321
|
+
return [productInputObj, projectMediaObj];
|
|
322
|
+
}
|
|
323
|
+
return [productInputObj];
|
|
324
|
+
}
|
|
223
325
|
toObjForTextTranslation() {
|
|
224
326
|
return {
|
|
225
327
|
description: this.attributes.description || this.FIELD_NOT_TRANSLATABLE_KEY,
|