rerobe-js-orm 3.0.26 → 3.0.28

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.
File without changes
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ // import OrderFactory from './OrderFactory';
3
+ // import Order from '../../models/Order';
4
+ // import OrderHelpers from '../../helpers/OrderHelpers';
5
+ // const orderHelpers: OrderHelpers = new OrderHelpers();
6
+ // export default class OrderToShipmondo extends OrderFactory {
7
+ // createOrder(order: ReRobeOrderObj): any {
8
+ // const { amount, currencyCode } = {
9
+ // amount: order.originalTotalPrice?.amount ?? 0,
10
+ // currencyCode: order.originalTotalPrice?.currencyCode ?? '',
11
+ // };
12
+ // const taxAmount = order.totalTax?.amount ?? 0;
13
+ // const shipmondoOrder = {
14
+ // order_id: order.orderNumber,
15
+ // ship_to: {
16
+ // name: '',
17
+ // address1: order.shippingAddress?.address1,
18
+ // zipcode: order.shippingAddress?.zip,
19
+ // city: order.shippingAddress?.zip,
20
+ // country_code: order.shippingAddress?.countryCode,
21
+ // },
22
+ // // bill_to: {
23
+ // // name,
24
+ // // address1: shipping_address,
25
+ // // zipcode: '',
26
+ // // city: '',
27
+ // // country_code: '',
28
+ // // },
29
+ // sender: {
30
+ // // name,
31
+ // // address1: shipping_address,
32
+ // // zipcode: '',
33
+ // // city: '',
34
+ // // country_code: '',
35
+ // },
36
+ // payment_details: {
37
+ // amount_including_vat: +amount + +taxAmount,
38
+ // currency_code: currencyCode,
39
+ // vat_amount: taxAmount,
40
+ // },
41
+ // order_lines: order.lineItems.map((item: ReRobeOrderLineItem) => ({
42
+ // line_type: 'item',
43
+ // item_name: item.title,
44
+ // quantity: item.quantity,
45
+ // unit_price_excluding_vat: item.presentmentUnitPrice?.amount,
46
+ // discount_amount_excluding_vat: item.discountedTotalPrice?.amount,
47
+ // currency_code: item.presentmentUnitPrice?.currencyCode || item.discountedTotalPrice?.currencyCode,
48
+ // image_url: item.image?.originalSrc,
49
+ // })),
50
+ // };
51
+ // return shipmondoOrder;
52
+ // }
53
+ // }
@@ -18,5 +18,6 @@ export default class OrderFormState extends FormState {
18
18
  }): void;
19
19
  discountChangeHandler(val: string): void;
20
20
  shippingPriceChangeHandler(val: string): void;
21
+ private orderStateChangeHandler;
21
22
  private fieldFactory;
22
23
  }
@@ -47,6 +47,7 @@ class OrderFormState extends FormState_1.default {
47
47
  this.fields.shippingInfo = this.fieldFactory('singleSelect', 'shippingInfo');
48
48
  this.fields.pickupLocation = this.fieldFactory('singleSelect', 'pickupLocation');
49
49
  this.fields.presentmentData = this.fieldFactory('singleSelect', 'presentmentData');
50
+ this.fields.state = this.fieldFactory('singleSelect', 'state');
50
51
  }
51
52
  createOrder() {
52
53
  const orderFactory = new OrderFromFormState_1.default();
@@ -97,6 +98,15 @@ class OrderFormState extends FormState_1.default {
97
98
  // Update total price
98
99
  this.fields.totalPrice.inputValue = Number(Number(this.fields.subtotalPrice.inputValue) - Number(this.fields.totalDiscount.inputValue) + Number(val)).toFixed(2);
99
100
  }
101
+ orderStateChangeHandler(val) {
102
+ const values = Object.values(order_constants_1.ORDER_STATES);
103
+ if (!values.includes(val)) {
104
+ this.fields.state.selectedValue = order_constants_1.ORDER_STATES.draft;
105
+ }
106
+ else {
107
+ this.fields.state.selectedValue = val;
108
+ }
109
+ }
100
110
  fieldFactory(fieldType, fieldKey, fieldOptions) {
101
111
  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;
102
112
  let options = fieldOptions || [];
@@ -145,6 +155,7 @@ class OrderFormState extends FormState_1.default {
145
155
  }
146
156
  if (fieldType === 'singleSelect') {
147
157
  let selectedValue = this.props[fieldKey] || '';
158
+ let onChangeHandler = (val) => this.singleSelectChangeHandler(fieldKey, val);
148
159
  if (fieldKey === 'pickupLocation') {
149
160
  if (((_c = this.props) === null || _c === void 0 ? void 0 : _c.shippingType) === order_constants_1.SHIPPING_TYPES.localPickUp &&
150
161
  ((_d = this.props) === null || _d === void 0 ? void 0 : _d.fulfillmentLocations) &&
@@ -188,8 +199,15 @@ class OrderFormState extends FormState_1.default {
188
199
  displayName: this.props.customerName,
189
200
  };
190
201
  }
202
+ if (fieldKey === 'state') {
203
+ const values = Object.values(order_constants_1.ORDER_STATES);
204
+ if (!values.includes(selectedValue)) {
205
+ selectedValue = order_constants_1.ORDER_STATES.draft;
206
+ }
207
+ options = values.map((i) => ({ label: i, value: i }));
208
+ onChangeHandler = (val) => this.orderStateChangeHandler(val);
209
+ }
191
210
  const valid = !!this.props[fieldKey];
192
- const onChangeHandler = (val) => this.singleSelectChangeHandler(fieldKey, val);
193
211
  if (fieldKey === 'shippingType') {
194
212
  if ((_0 = (_z = this.opts) === null || _z === void 0 ? void 0 : _z.shippingTypeOptions) === null || _0 === void 0 ? void 0 : _0.length) {
195
213
  options = this.utilities.uniqObjArray(this.opts.shippingTypeOptions, 'value');
@@ -42,7 +42,7 @@ export default class ProductFormState extends FormState {
42
42
  private productTypeSelectHandler;
43
43
  private setPriceRangeFromPrice;
44
44
  private setGenderFromPassedOptions;
45
- private setProductCategoreisFromGender;
45
+ private setProductCategoriesFromGender;
46
46
  private setProductTypesFromCategory;
47
47
  private setProductTypesFromPassedOptions;
48
48
  private setProductStylesFromCategoryAndType;
@@ -35,7 +35,7 @@ class ProductFormState extends FormState_1.default {
35
35
  this.fields.condition = this.fieldFactory('singleSelect', 'condition', options_1.conditions);
36
36
  this.fields.majorDefects = this.fieldFactory('multiSelect', 'majorDefects', options_1.majorDefectOptions);
37
37
  this.fields.minorDefects = this.fieldFactory('multiSelect', 'minorDefects', options_1.minorDefectOptions);
38
- this.fields.gender = this.fieldFactory('singleSelect', 'gender', options_1.gender);
38
+ this.fields.gender = this.fieldFactory('singleSelect', 'gender', options_1.genderOptions);
39
39
  this.fields.materialComposition = this.fieldFactory('singleSelect', 'materialComposition', options_1.clothingMaterials);
40
40
  this.fields.priceRange = this.fieldFactory('textInput', 'priceRange');
41
41
  this.fields.productCategory = this.fieldFactory('singleSelect', 'productCategory', options_1.productCategories);
@@ -105,7 +105,7 @@ class ProductFormState extends FormState_1.default {
105
105
  this.fields.gender.selectedValue = value;
106
106
  this.fields.gender.valid = !!value;
107
107
  // Reset productCategory fields except options
108
- this.fields.productCategory.options = this.setProductCategoreisFromGender(value);
108
+ this.fields.productCategory.options = this.setProductCategoriesFromGender(value);
109
109
  this.fields.productCategory.hidden = true;
110
110
  this.fields.productCategory.valid = false;
111
111
  this.fields.productCategory.selectedValue = '';
@@ -256,25 +256,35 @@ class ProductFormState extends FormState_1.default {
256
256
  return '1000+';
257
257
  }
258
258
  setGenderFromPassedOptions() {
259
+ let options = options_1.genderOptions;
260
+ let selectedGenderOptions = [];
261
+ if (this.props.gender) {
262
+ selectedGenderOptions = [{ label: this.props.gender, value: this.props.gender }];
263
+ if (!options.map((o) => o.value).includes(this.props.gender)) {
264
+ options.splice(0, 0, ...selectedGenderOptions);
265
+ }
266
+ }
259
267
  if (this.opts && this.opts.taxonomy && Object.keys(this.opts.taxonomy).length > 0) {
260
- return Object.keys(this.opts.taxonomy).map((t) => ({ label: t, value: t }));
268
+ const passedOptions = Object.keys(this.opts.taxonomy).map((t) => ({ label: t, value: t }));
269
+ options = this.utilities.uniqObjArray([...selectedGenderOptions, ...passedOptions], 'value');
261
270
  }
262
- return options_1.gender;
271
+ return options;
263
272
  }
264
- setProductCategoreisFromGender(genderSelected) {
265
- let productCategoryOptions = [];
273
+ setProductCategoriesFromGender(genderSelected) {
274
+ let options = options_1.productCategories;
275
+ let selectedProductCategoryOptions = [];
276
+ if (this.props.productCategory) {
277
+ selectedProductCategoryOptions = [{ label: this.props.productCategory, value: this.props.productCategory }];
278
+ if (!options.map((o) => o.value).includes(this.props.productCategory)) {
279
+ options.splice(0, 0, ...selectedProductCategoryOptions);
280
+ }
281
+ }
266
282
  if (this.opts && this.opts.taxonomy && Object.keys(this.opts.taxonomy).length > 0 && genderSelected) {
267
283
  const t = this.opts.taxonomy;
268
284
  const { [genderSelected]: genderObj = {} } = t;
269
- productCategoryOptions = Object.keys(genderObj).map((k) => ({ label: k, value: k }));
270
- }
271
- else {
272
- productCategoryOptions = options_1.productCategories;
285
+ const passedOptions = Object.keys(genderObj).map((k) => ({ label: k, value: k }));
286
+ options = this.utilities.uniqObjArray([...selectedProductCategoryOptions, ...passedOptions], 'value');
273
287
  }
274
- const selectedCategoryOptions = this.props.productCategory
275
- ? [{ label: this.props.productCategory, value: this.props.productCategory }]
276
- : [];
277
- const options = this.utilities.uniqObjArray([...productCategoryOptions, ...selectedCategoryOptions], 'value');
278
288
  return options;
279
289
  }
280
290
  setProductTypesFromCategory(productCategory, genderSelected) {
@@ -324,6 +334,7 @@ class ProductFormState extends FormState_1.default {
324
334
  }
325
335
  }
326
336
  setProductTypesFromPassedOptions(productCategory, genderSelected) {
337
+ let options = this.setProductTypesFromCategory(productCategory, genderSelected);
327
338
  if (productCategory &&
328
339
  genderSelected &&
329
340
  this.opts &&
@@ -331,9 +342,16 @@ class ProductFormState extends FormState_1.default {
331
342
  Object.keys(this.opts.taxonomy).length > 0) {
332
343
  const t = this.opts.taxonomy;
333
344
  const { [genderSelected]: { [productCategory]: productTypeArr = [] } = {} } = t;
334
- return productTypeArr;
345
+ options = productTypeArr;
346
+ }
347
+ let selectedProductTypeOptions = [];
348
+ if (this.props.productType) {
349
+ selectedProductTypeOptions = [{ label: this.props.productType, value: this.props.productType, styles: [] }];
350
+ if (!options.map((o) => o.value).includes(this.props.productType)) {
351
+ options.splice(0, 0, ...selectedProductTypeOptions);
352
+ }
335
353
  }
336
- return this.setProductTypesFromCategory(productCategory, genderSelected);
354
+ return options;
337
355
  }
338
356
  setProductStylesFromCategoryAndType(productCategory, productType) {
339
357
  switch (productCategory) {
@@ -397,6 +415,7 @@ class ProductFormState extends FormState_1.default {
397
415
  }
398
416
  }
399
417
  setProductStylesFromPassedOptions(productCategory, productType) {
418
+ let options = this.setProductStylesFromCategoryAndType(productCategory, productType);
400
419
  if (this.opts &&
401
420
  this.opts.taxonomy &&
402
421
  Object.keys(this.opts.taxonomy).length > 0 &&
@@ -407,11 +426,16 @@ class ProductFormState extends FormState_1.default {
407
426
  const { [genderSelected]: { [productCategory]: productTypeArr = [] } = {} } = t;
408
427
  const [pType] = productTypeArr.filter((p) => p.value === productType);
409
428
  if (pType) {
410
- return pType.styles.map((s) => ({ label: s, value: s }));
429
+ options = pType.styles.map((s) => ({ label: s, value: s }));
411
430
  }
412
- return [];
413
431
  }
414
- return this.setProductStylesFromCategoryAndType(productCategory, productType);
432
+ if (this.props.productStyle && Array.isArray(this.props.productStyle) && this.props.productStyle.length > 0) {
433
+ options = [...new Set([...this.props.productStyle, ...options.map((o) => o.value)])].map((s) => ({
434
+ label: s,
435
+ value: s,
436
+ }));
437
+ }
438
+ return options;
415
439
  }
416
440
  discountTypeChangeHandler(val) {
417
441
  const prevVal = this.fields.discountType.selectedValue;
@@ -521,7 +545,7 @@ class ProductFormState extends FormState_1.default {
521
545
  onChangeHandler = (val) => this.genderSelectHandler(val);
522
546
  }
523
547
  if (fieldKey === 'productCategory') {
524
- options = this.setProductCategoreisFromGender(this.props.gender);
548
+ options = this.setProductCategoriesFromGender(this.props.gender);
525
549
  onChangeHandler = (val) => this.productCategorySelectHandler(val);
526
550
  }
527
551
  if (fieldKey === 'productType') {
@@ -59,7 +59,7 @@ export const conditions: ({
59
59
  key: string;
60
60
  color?: undefined;
61
61
  })[];
62
- export const gender: {
62
+ export const genderOptions: {
63
63
  label: string;
64
64
  value: string;
65
65
  }[];
@@ -79,7 +79,6 @@ export const clothingMaterials: {
79
79
  export const productCategories: {
80
80
  label: string;
81
81
  value: string;
82
- color: string;
83
82
  }[];
84
83
  export const clothing: {
85
84
  label: string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.measurementCategoryOptions = exports.minorDefectOptions = exports.majorDefectOptions = exports.productOptions = exports.productIsOnSaleOptions = exports.discountTypeOptions = exports.salesChannelOptions = exports.unisexJewelry = exports.mensJewelry = exports.jewelry = exports.unisexAccessories = exports.mensAccessories = exports.accessories = exports.unisexBags = exports.mensBags = exports.bags = exports.weightUnits = exports.productWeightRanges = exports.unisexShoes = exports.mensShoes = exports.shoes = exports.unisexClothing = exports.mensClothing = exports.clothing = exports.productCategories = exports.clothingMaterials = exports.shoeSizes = exports.jeanSizes = exports.gender = exports.conditions = exports.colors = exports.brands = exports.sizeCommentOptions = exports.manClothingSizeOptions = exports.womanClothingSizeOptions = exports.clothingSizeOptions = exports.sizeOptions = exports.statusOptions = exports.publishTypeOptions = exports.availableForSaleOptions = void 0;
3
+ exports.measurementCategoryOptions = exports.minorDefectOptions = exports.majorDefectOptions = exports.productOptions = exports.productIsOnSaleOptions = exports.discountTypeOptions = exports.salesChannelOptions = exports.unisexJewelry = exports.mensJewelry = exports.jewelry = exports.unisexAccessories = exports.mensAccessories = exports.accessories = exports.unisexBags = exports.mensBags = exports.bags = exports.weightUnits = exports.productWeightRanges = exports.unisexShoes = exports.mensShoes = exports.shoes = exports.unisexClothing = exports.mensClothing = exports.clothing = exports.productCategories = exports.clothingMaterials = exports.shoeSizes = exports.jeanSizes = exports.genderOptions = exports.conditions = exports.colors = exports.brands = exports.sizeCommentOptions = exports.manClothingSizeOptions = exports.womanClothingSizeOptions = exports.clothingSizeOptions = exports.sizeOptions = exports.statusOptions = exports.publishTypeOptions = exports.availableForSaleOptions = void 0;
4
4
  const product_constants_1 = require("../../constants/product-constants");
5
5
  const lodash_1 = require("lodash");
6
6
  const availableForSaleOptions = [
@@ -1816,7 +1816,7 @@ const minorDefectOptions = [
1816
1816
  { label: 'Other minor Issue', value: 'Other minor issue' },
1817
1817
  ];
1818
1818
  exports.minorDefectOptions = minorDefectOptions;
1819
- const gender = [
1819
+ const genderOptions = [
1820
1820
  {
1821
1821
  label: 'Woman',
1822
1822
  value: 'Woman',
@@ -1842,7 +1842,7 @@ const gender = [
1842
1842
  value: 'NA',
1843
1843
  },
1844
1844
  ];
1845
- exports.gender = gender;
1845
+ exports.genderOptions = genderOptions;
1846
1846
  const jeanSizes = [
1847
1847
  { label: '24', value: '24' },
1848
1848
  { label: '25', value: '25' },
@@ -2089,27 +2089,22 @@ const productCategories = [
2089
2089
  {
2090
2090
  label: 'Clothing',
2091
2091
  value: 'Clothing',
2092
- color: '#cfdfff',
2093
2092
  },
2094
2093
  {
2095
2094
  label: 'Shoes',
2096
2095
  value: 'Shoes',
2097
- color: '#d0f0fd',
2098
2096
  },
2099
2097
  {
2100
2098
  label: 'Bags',
2101
2099
  value: 'Bags',
2102
- color: '#d0f0fd',
2103
2100
  },
2104
2101
  {
2105
2102
  label: 'Accessories',
2106
2103
  value: 'Accessories',
2107
- color: '#d0f0fd',
2108
2104
  },
2109
2105
  {
2110
2106
  label: 'Jewelry',
2111
2107
  value: 'Jewelry',
2112
- color: '#d0f0fd',
2113
2108
  },
2114
2109
  ];
2115
2110
  exports.productCategories = productCategories;
@@ -731,6 +731,7 @@ declare type OrderAttributesFormFields = {
731
731
  shippingInfo: SingleSelectFormField<OrderShippingInfo>;
732
732
  pickupLocation: SingleSelectFormField<string>;
733
733
  presentmentData: SingleSelectFormField<OrderPresentmentData>;
734
+ state: SingleSelectFormField<string>;
734
735
  };
735
736
  declare type OrderRefundFormFields = {
736
737
  totalRefunded: TextInputFormField<string | number>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rerobe-js-orm",
3
- "version": "3.0.26",
3
+ "version": "3.0.28",
4
4
  "description": "ReRobe's Javascript ORM Framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",