rerobe-js-orm 3.0.14 → 3.0.16

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.
@@ -20,6 +20,8 @@ class ProductFromAlgoliaJSONDoc extends ProductFactory_1.default {
20
20
  weight: String(props.grams),
21
21
  variantId: '',
22
22
  reservedBy: [],
23
+ weightRange: '',
24
+ weightUnit: 'GRAMS',
23
25
  };
24
26
  const productFilterAttributes = this.shopifyHelpers.tagsExtractor(props.named_tags);
25
27
  return new Product_1.default(Object.assign(Object.assign({}, productAttributes), productFilterAttributes));
@@ -20,6 +20,8 @@ class ProductFromFormState extends ProductFactory_1.default {
20
20
  vendorId: props.fields.vendorId.selectedValue || ((_h = props.props) === null || _h === void 0 ? void 0 : _h.vendorId) || '',
21
21
  vendorName: props.fields.vendorName.selectedValue || '',
22
22
  weight: props.fields.weight.inputValue,
23
+ weightRange: props.fields.weightRange.selectedValue || '',
24
+ weightUnit: props.fields.weightUnit.selectedValue || '',
23
25
  variantId: ((_j = props.props) === null || _j === void 0 ? void 0 : _j.variantId) || '',
24
26
  reservedBy: ((_k = props.props) === null || _k === void 0 ? void 0 : _k.reservedBy) || [],
25
27
  options: props.fields.options.selectedValue,
@@ -20,6 +20,8 @@ class ProductFromShopifyJSClientJSONDoc extends ProductFactory_1.default {
20
20
  vendorId: props.vendor,
21
21
  variantId: this.getVariantId(props.variants),
22
22
  reservedBy: [],
23
+ weightRange: '',
24
+ weightUnit: 'GRAMS',
23
25
  };
24
26
  const productFilterAttributes = this.shopifyHelpers.tagsExtractor(props.tags);
25
27
  return new Product_1.default(Object.assign(Object.assign({}, productAttributes), productFilterAttributes));
@@ -20,6 +20,8 @@ class ProductFromShopifyWebhookJSONDoc extends ProductFactory_1.default {
20
20
  vendorId: props.vendor,
21
21
  variantId: this.getVariantId(props.variants),
22
22
  reservedBy: [],
23
+ weightRange: '',
24
+ weightUnit: 'GRAMS',
23
25
  };
24
26
  const productFilterAttributes = this.shopifyHelpers.tagsExtractor(props.tags.split(', '));
25
27
  return new Product_1.default(Object.assign(Object.assign({}, productAttributes), productFilterAttributes));
@@ -34,6 +34,10 @@ export default class ProductFormState extends FormState {
34
34
  private priceInputChangeHandler;
35
35
  private setGenderFromPassedOptions;
36
36
  private genderSelectHandler;
37
+ private geWeightArray;
38
+ private findWeightRange;
39
+ private weightRangeSelectHandler;
40
+ private weightInputChangeHandler;
37
41
  private conditionSelectHandler;
38
42
  private productCategorySelectHandler;
39
43
  private productTypeSelectHandler;
@@ -15,6 +15,8 @@ class ProductFormState extends FormState_1.default {
15
15
  this.fields.title = this.fieldFactory('textInput', 'title');
16
16
  this.fields.price = this.fieldFactory('textInput', 'price');
17
17
  this.fields.weight = this.fieldFactory('textInput', 'weight');
18
+ this.fields.weightRange = this.fieldFactory('singleSelect', 'weightRange', options_1.productWeightRanges);
19
+ this.fields.weightUnit = this.fieldFactory('singleSelect', 'weightUnit', options_1.weightUnits);
18
20
  this.fields.officialFilesToUpload = {
19
21
  selectedValues: [],
20
22
  valid: false,
@@ -144,6 +146,41 @@ class ProductFormState extends FormState_1.default {
144
146
  this.fields.size.valid = false;
145
147
  this.fields.size.selectedValue = '';
146
148
  }
149
+ geWeightArray(range) {
150
+ if (!range)
151
+ return ['', ''];
152
+ if (range.endsWith('+')) {
153
+ return ['0', range.replace('+', '').trim()];
154
+ }
155
+ const [min, max] = range.split('-');
156
+ return [min.trim(), max.trim()];
157
+ }
158
+ findWeightRange(weightRanges, weight) {
159
+ for (const rangeStr of weightRanges) {
160
+ const [min, max] = this.geWeightArray(rangeStr);
161
+ if (weight >= parseFloat(min) && weight <= parseFloat(max)) {
162
+ return rangeStr;
163
+ }
164
+ }
165
+ return weightRanges[weightRanges.length - 1];
166
+ }
167
+ weightRangeSelectHandler(value) {
168
+ const [_, max] = this.geWeightArray(value);
169
+ // Mutate weightRange selectedValue and valid prop
170
+ this.fields.weightRange.selectedValue = value;
171
+ this.fields.weightRange.valid = !!value;
172
+ // Reset weight fields except options
173
+ this.fields.weight.hidden = false;
174
+ this.fields.weight.valid = !!max;
175
+ this.fields.weight.inputValue = max;
176
+ }
177
+ weightInputChangeHandler(value) {
178
+ const weightRanges = this.fields.weightRange.options.map((i) => i.value);
179
+ const matchRange = this.findWeightRange(weightRanges, parseFloat(value));
180
+ this.fields.weightRange.selectedValue = matchRange;
181
+ this.fields.weightRange.valid = !!matchRange;
182
+ this.fields.weight.inputValue = value;
183
+ }
147
184
  conditionSelectHandler(value) {
148
185
  // Mutate condition selectedValue and valid prop
149
186
  this.fields.condition.selectedValue = value;
@@ -557,6 +594,16 @@ class ProductFormState extends FormState_1.default {
557
594
  options = this.utilities.uniqObjArray([...selectedColorOptions, ...colorsOptions], 'value');
558
595
  }
559
596
  }
597
+ if (fieldKey === 'weightRange') {
598
+ onChangeHandler = (val) => this.weightRangeSelectHandler(val);
599
+ let selectedOptions = [];
600
+ if (this.props.weightRange) {
601
+ selectedOptions = [{ label: this.props.weightRange, value: this.props.weightRange }];
602
+ if (!options.map((o) => o.value).includes(this.props.weightRange)) {
603
+ options.splice(0, 0, ...selectedOptions);
604
+ }
605
+ }
606
+ }
560
607
  if (fieldKey === 'primaryAgeCategory') {
561
608
  let selectedPrimaryAgeCategoryOptions = [];
562
609
  if (this.props.primaryAgeCategory) {
@@ -573,13 +620,20 @@ class ProductFormState extends FormState_1.default {
573
620
  }
574
621
  }
575
622
  if (fieldKey === 'condition') {
623
+ let selectedOptions = [];
624
+ if (this.props.condition) {
625
+ selectedOptions = [{ label: this.props.condition, value: this.props.condition, description: '' }];
626
+ if (!options.map((o) => o.value).includes(this.props.condition)) {
627
+ options.splice(0, 0, ...selectedOptions);
628
+ }
629
+ }
576
630
  if ((_p = (_o = this.opts) === null || _o === void 0 ? void 0 : _o.conditions) === null || _p === void 0 ? void 0 : _p.length) {
577
631
  const conditionsOptions = this.opts.conditions.map((t) => ({
578
632
  label: t.label || '',
579
633
  value: t.value || '',
580
634
  description: t.description || '',
581
635
  }));
582
- options = this.utilities.uniqObjArray(conditionsOptions, 'value');
636
+ options = this.utilities.uniqObjArray([...selectedOptions, ...conditionsOptions], 'value');
583
637
  }
584
638
  onChangeHandler = (val) => this.conditionSelectHandler(val);
585
639
  }
@@ -682,6 +736,9 @@ class ProductFormState extends FormState_1.default {
682
736
  valid = true;
683
737
  onChangeHandler = (val) => this.discountValueChangeHandler(val);
684
738
  }
739
+ if (fieldKey === 'weight') {
740
+ onChangeHandler = (val) => this.weightInputChangeHandler(val);
741
+ }
685
742
  return {
686
743
  inputValue,
687
744
  valid,
@@ -111,6 +111,14 @@ export const unisexShoes: {
111
111
  value: string;
112
112
  styles: string[];
113
113
  }[];
114
+ export const productWeightRanges: {
115
+ label: string;
116
+ value: string;
117
+ }[];
118
+ export const weightUnits: {
119
+ label: string;
120
+ value: string;
121
+ }[];
114
122
  export const bags: {
115
123
  label: string;
116
124
  value: string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- 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.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.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;
4
4
  const product_constants_1 = require("../../constants/product-constants");
5
5
  const lodash_1 = require("lodash");
6
6
  const availableForSaleOptions = [
@@ -1818,6 +1818,25 @@ const shoeSizes = [
1818
1818
  { label: '45.3', value: '45.3' },
1819
1819
  ];
1820
1820
  exports.shoeSizes = shoeSizes;
1821
+ const productWeightRanges = [
1822
+ '0.01 - 0.1',
1823
+ '0.01 - 0.2',
1824
+ '0.01 - 0.5',
1825
+ '0.2 - 1.0',
1826
+ '0.5 - 1.0',
1827
+ '1.0 - 2.0',
1828
+ '2.0 - 5.0',
1829
+ '5.0 - 10.0',
1830
+ '10.0 - 20.0',
1831
+ '20.0 - 50.0',
1832
+ '50.0 - 100.0',
1833
+ '100.0 - 200.0',
1834
+ '100.0+',
1835
+ '200.0+',
1836
+ ].map((i) => ({ label: i, value: i }));
1837
+ exports.productWeightRanges = productWeightRanges;
1838
+ const weightUnits = ['GRAMS', 'KILOGRAMS', 'OUNCES', 'POUNDS'].map((i) => ({ label: i, value: i }));
1839
+ exports.weightUnits = weightUnits;
1821
1840
  const clothingMaterials = [
1822
1841
  {
1823
1842
  label: 'Acetate',
@@ -25,7 +25,7 @@ class OrderHelpers {
25
25
  if (shippingLines[0].title === 'Localy delivery') {
26
26
  return Order_1.default.SHIPPING_TYPES.localDelivery;
27
27
  }
28
- return shippingLines[0].price_set.shop_money.amount > 0
28
+ return Number(shippingLines[0].price_set.shop_money.amount) > 0
29
29
  ? Order_1.default.SHIPPING_TYPES.localDelivery
30
30
  : Order_1.default.SHIPPING_TYPES.localPickUp;
31
31
  }
@@ -221,7 +221,7 @@ class OrderHelpers {
221
221
  return 0;
222
222
  }
223
223
  const subtotal = this.getSubtotalPrice(lineItems);
224
- return subtotal > userAvailableCredit ? Number(userAvailableCredit) : subtotal;
224
+ return subtotal > Number(userAvailableCredit) ? Number(userAvailableCredit) : subtotal;
225
225
  }
226
226
  getSaleDiscount(lineItems = []) {
227
227
  return lineItems.reduce((acc, cur) => {
@@ -19,6 +19,8 @@ class Product extends Base_1.default {
19
19
  updatedAt: (props === null || props === void 0 ? void 0 : props.updatedAt) || '',
20
20
  publishedAt: (props === null || props === void 0 ? void 0 : props.publishedAt) || '',
21
21
  weight: (props === null || props === void 0 ? void 0 : props.weight) || '999',
22
+ weightRange: (props === null || props === void 0 ? void 0 : props.weightRange) || '',
23
+ weightUnit: (props === null || props === void 0 ? void 0 : props.weightUnit) || 'GRAMS',
22
24
  vendorId: (props === null || props === void 0 ? void 0 : props.vendorId) || '',
23
25
  vendorName: (props === null || props === void 0 ? void 0 : props.vendorName) || '',
24
26
  variantId: (props === null || props === void 0 ? void 0 : props.variantId) || '',
@@ -292,6 +294,8 @@ class Product extends Base_1.default {
292
294
  title: this.utilities.sanitizeString(this.attributes.title),
293
295
  vendorName: this.utilities.sanitizeString(this.attributes.vendorName),
294
296
  vendorId: this.utilities.sanitizeString(this.attributes.vendorId),
297
+ weightRange: this.utilities.sanitizeString(this.attributes.weightRange),
298
+ weightUnit: this.utilities.sanitizeString(this.attributes.weightUnit),
295
299
  createdAtTimestamp,
296
300
  createdAtHour,
297
301
  createdAtDay,
@@ -769,6 +773,18 @@ class Product extends Base_1.default {
769
773
  type: 'string',
770
774
  optional: true,
771
775
  },
776
+ {
777
+ facet: true,
778
+ name: 'weightRange',
779
+ type: 'string',
780
+ optional: true,
781
+ },
782
+ {
783
+ facet: true,
784
+ name: 'weightUnit',
785
+ type: 'string',
786
+ optional: true,
787
+ },
772
788
  ],
773
789
  name,
774
790
  };
@@ -11,6 +11,8 @@ declare type ProductAttributes = {
11
11
  updatedAt: string;
12
12
  publishedAt: string;
13
13
  weight: string;
14
+ weightRange: string;
15
+ weightUnit: WeightUnit;
14
16
  vendorId: string;
15
17
  vendorName?: string;
16
18
  variantId: string;
@@ -141,6 +143,8 @@ declare type ProductAttributesFormFields = {
141
143
  title: TextInputFormField<string>;
142
144
  price: TextInputFormField<string>;
143
145
  weight: TextInputFormField<string>;
146
+ weightRange: SingleSelectFormField<string>;
147
+ weightUnit: SingleSelectFormField<WeightUnit>;
144
148
  officialFilesToUpload: MultiMediaSelectFormField;
145
149
  options: SingleSelectFormField<ProductOptions>;
146
150
  costPerItem: TextInputFormField<string>;
@@ -214,6 +218,7 @@ declare type Measurements = {
214
218
  unit?: string;
215
219
  [key: string]: any;
216
220
  };
221
+ declare type WeightUnit = 'GRAMS' | 'KILOGRAMS' | 'OUNCES' | 'POUNDS';
217
222
  declare type ProductLineItem = {
218
223
  title: string;
219
224
  variant: {
@@ -303,5 +308,7 @@ declare type TypesenseProductObj = {
303
308
  createdAtMonth: string;
304
309
  createdAtHour: string;
305
310
  createdAtYear: string;
311
+ weightRange: string;
312
+ weightUnit: string;
306
313
  [key: string]: any;
307
314
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rerobe-js-orm",
3
- "version": "3.0.14",
3
+ "version": "3.0.16",
4
4
  "description": "ReRobe's Javascript ORM Framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",