merchi_sdk_js 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/address.js +109 -0
- package/dist/assignment.js +175 -0
- package/dist/automatic_payment_relationship.js +72 -0
- package/dist/backup.js +32 -0
- package/dist/bank.js +25 -0
- package/dist/cart.js +133 -0
- package/dist/cart_item.js +71 -0
- package/dist/cart_shipment_group.js +23 -0
- package/dist/cart_shipment_quote.js +26 -0
- package/dist/category.js +68 -0
- package/dist/company.js +248 -0
- package/dist/company_invitation.js +70 -0
- package/dist/component.js +107 -0
- package/dist/component_tag.js +60 -0
- package/dist/component_version.js +21 -0
- package/dist/country_tax.js +93 -0
- package/dist/dictionary.js +130 -0
- package/dist/discount.js +22 -0
- package/dist/discount_group.js +18 -0
- package/dist/domain.js +245 -0
- package/dist/domain_invitation.js +17 -0
- package/dist/domain_tag.js +87 -0
- package/dist/domain_types.js +22 -0
- package/dist/draft.js +97 -0
- package/dist/draft_comment.js +45 -0
- package/dist/draft_template.js +39 -0
- package/dist/email_address.js +34 -0
- package/dist/email_counter.js +47 -0
- package/dist/enrolled_domain.js +88 -0
- package/dist/exchange_rate.js +66 -0
- package/dist/field_types.js +19 -0
- package/dist/helpers.js +86 -0
- package/dist/internal_tag.js +98 -0
- package/dist/inventory.js +100 -0
- package/dist/inventory_unit_variation.js +19 -0
- package/dist/invoice.js +225 -0
- package/dist/invoice_types.js +11 -0
- package/dist/item.js +25 -0
- package/dist/job.js +536 -0
- package/dist/job_comment.js +45 -0
- package/dist/job_status.js +47 -0
- package/dist/matching_inventory.js +21 -0
- package/dist/md5.js +149 -0
- package/dist/menu.js +37 -0
- package/dist/menu_item.js +24 -0
- package/dist/merchi.js +1004 -0
- package/dist/merchi_file.js +165 -0
- package/dist/model.js +753 -0
- package/dist/notification.js +151 -0
- package/dist/notification_types.js +199 -0
- package/dist/output.cjs.js +31317 -0
- package/dist/output.esm.js +31312 -0
- package/dist/page.js +41 -0
- package/dist/payment.js +32 -0
- package/dist/payment_device.js +21 -0
- package/dist/payment_types.js +20 -0
- package/dist/phone_number.js +37 -0
- package/dist/product.js +288 -0
- package/dist/product_types.js +32 -0
- package/dist/production_comment.js +44 -0
- package/dist/quote.js +91 -0
- package/dist/quote_item.js +59 -0
- package/dist/roles.js +29 -0
- package/dist/seo_domain_page.js +42 -0
- package/dist/session.js +103 -0
- package/dist/set.js +29 -0
- package/dist/shipment.js +181 -0
- package/dist/shipment_item.js +17 -0
- package/dist/shipment_item_fulfillment.js +17 -0
- package/dist/shipment_method.js +81 -0
- package/dist/shipment_method_variation.js +38 -0
- package/dist/subscription_plan.js +75 -0
- package/dist/supply_domain.js +65 -0
- package/dist/system_role.js +12 -0
- package/dist/theme.js +180 -0
- package/dist/theme_css_setting.js +61 -0
- package/dist/theme_status.js +11 -0
- package/dist/user.js +409 -0
- package/dist/user_company.js +19 -0
- package/dist/user_types.js +23 -0
- package/dist/uuid.js +12 -0
- package/dist/variation.js +233 -0
- package/dist/variation_field.js +233 -0
- package/dist/variation_fields_option.js +41 -0
- package/dist/variation_option.js +62 -0
- package/dist/variations_group.js +43 -0
- package/dist/white_label_accessibilities.js +11 -0
- package/package.json +30 -0
- package/src/address.js +107 -0
- package/src/assignment.js +165 -0
- package/src/automatic_payment_relationship.js +65 -0
- package/src/backup.js +29 -0
- package/src/bank.js +21 -0
- package/src/cart.js +131 -0
- package/src/cart_item.js +71 -0
- package/src/cart_shipment_group.js +20 -0
- package/src/cart_shipment_quote.js +23 -0
- package/src/category.js +62 -0
- package/src/company.js +267 -0
- package/src/company_invitation.js +63 -0
- package/src/component.js +100 -0
- package/src/component_tag.js +53 -0
- package/src/component_version.js +17 -0
- package/src/country_tax.js +89 -0
- package/src/dictionary.js +135 -0
- package/src/discount.js +19 -0
- package/src/discount_group.js +15 -0
- package/src/domain.js +254 -0
- package/src/domain_invitation.js +13 -0
- package/src/domain_tag.js +79 -0
- package/src/domain_types.js +18 -0
- package/src/draft.js +92 -0
- package/src/draft_comment.js +41 -0
- package/src/draft_template.js +35 -0
- package/src/email_address.js +27 -0
- package/src/email_counter.js +42 -0
- package/src/enrolled_domain.js +79 -0
- package/src/exchange_rate.js +61 -0
- package/src/field_types.js +15 -0
- package/src/helpers.js +81 -0
- package/src/internal_tag.js +90 -0
- package/src/inventory.js +99 -0
- package/src/inventory_unit_variation.js +18 -0
- package/src/invoice.js +224 -0
- package/src/invoice_types.js +7 -0
- package/src/item.js +22 -0
- package/src/job.js +616 -0
- package/src/job_comment.js +41 -0
- package/src/job_status.js +51 -0
- package/src/matching_inventory.js +17 -0
- package/src/md5.js +162 -0
- package/src/menu.js +32 -0
- package/src/menu_item.js +22 -0
- package/src/merchi.js +1074 -0
- package/src/merchi_file.js +163 -0
- package/src/model.js +820 -0
- package/src/notification.js +153 -0
- package/src/notification_types.js +246 -0
- package/src/page.js +38 -0
- package/src/payment.js +32 -0
- package/src/payment_device.js +17 -0
- package/src/payment_types.js +18 -0
- package/src/phone_number.js +30 -0
- package/src/product.js +309 -0
- package/src/product_types.js +28 -0
- package/src/production_comment.js +40 -0
- package/src/quote.js +89 -0
- package/src/quote_item.js +51 -0
- package/src/roles.js +27 -0
- package/src/seo_domain_page.js +35 -0
- package/src/session.js +102 -0
- package/src/set.js +28 -0
- package/src/shipment.js +191 -0
- package/src/shipment_item.js +13 -0
- package/src/shipment_item_fulfillment.js +13 -0
- package/src/shipment_method.js +73 -0
- package/src/shipment_method_variation.js +34 -0
- package/src/subscription_plan.js +68 -0
- package/src/supply_domain.js +60 -0
- package/src/system_role.js +8 -0
- package/src/theme.js +188 -0
- package/src/theme_css_setting.js +54 -0
- package/src/theme_status.js +6 -0
- package/src/user.js +442 -0
- package/src/user_company.js +15 -0
- package/src/user_types.js +19 -0
- package/src/uuid.js +3 -0
- package/src/variation.js +257 -0
- package/src/variation_field.js +261 -0
- package/src/variation_fields_option.js +41 -0
- package/src/variation_option.js +59 -0
- package/src/variations_group.js +43 -0
- package/src/white_label_accessibilities.js +6 -0
package/src/variation.js
ADDED
@@ -0,0 +1,257 @@
|
|
1
|
+
import { generateUUID } from './uuid.js';
|
2
|
+
import { fieldTypes } from './field_types.js';
|
3
|
+
import { addPropertyTo } from './model.js';
|
4
|
+
import { isUndefined } from './helpers.js';
|
5
|
+
import { VariationOption } from './variation_option.js';
|
6
|
+
import { VariationField } from './variation_field.js';
|
7
|
+
import { MerchiFile } from './merchi_file.js';
|
8
|
+
|
9
|
+
export function Variation() {
|
10
|
+
this.resource = '/variation';
|
11
|
+
this.json = 'variation';
|
12
|
+
this.temporaryId = generateUUID();
|
13
|
+
|
14
|
+
addPropertyTo(this, 'id');
|
15
|
+
addPropertyTo(this, 'value');
|
16
|
+
addPropertyTo(this, 'quantity');
|
17
|
+
addPropertyTo(this, 'cost');
|
18
|
+
addPropertyTo(this, 'onceOffCost');
|
19
|
+
addPropertyTo(this, 'unitCost');
|
20
|
+
addPropertyTo(this, 'unitCostTotal');
|
21
|
+
addPropertyTo(this, 'selectableOptions', VariationOption);
|
22
|
+
addPropertyTo(this, 'selectedOptions', VariationOption);
|
23
|
+
addPropertyTo(this, 'variationField', VariationField);
|
24
|
+
addPropertyTo(this, 'variationFiles', MerchiFile);
|
25
|
+
|
26
|
+
this.unitCostAndOnceOffCost = function () {
|
27
|
+
var unitCost = this.unitCost() ? this.unitCost() : 0,
|
28
|
+
onceOffCost = this.onceOffCost() ? this.onceOffCost() : 0;
|
29
|
+
return unitCost + onceOffCost;
|
30
|
+
}
|
31
|
+
|
32
|
+
this.unitCostTotalAndOnceOffCost = function () {
|
33
|
+
var unitCostTotal = this.unitCostTotal() ? this.unitCostTotal() : 0,
|
34
|
+
onceOffCost = this.onceOffCost() ? this.onceOffCost() : 0;
|
35
|
+
return unitCostTotal + onceOffCost;
|
36
|
+
}
|
37
|
+
|
38
|
+
this.isTextField = function () {
|
39
|
+
var field = this.variationField();
|
40
|
+
return Boolean(field) && field.isTextType();
|
41
|
+
};
|
42
|
+
this.isNumberField = function () {
|
43
|
+
var field = this.variationField();
|
44
|
+
return Boolean(field) && field.isNumberType();
|
45
|
+
};
|
46
|
+
|
47
|
+
this.isSelectField = function () {
|
48
|
+
var field = this.variationField();
|
49
|
+
return Boolean(field) && field.isSelectType();
|
50
|
+
};
|
51
|
+
|
52
|
+
this.isCheckBoxField = function () {
|
53
|
+
var field = this.variationField();
|
54
|
+
return Boolean(field) && field.isCheckboxType();
|
55
|
+
};
|
56
|
+
|
57
|
+
this.isRadioField = function () {
|
58
|
+
var field = this.variationField();
|
59
|
+
return Boolean(field) && field.isRadioType();
|
60
|
+
};
|
61
|
+
|
62
|
+
this.isColourSelectField = function () {
|
63
|
+
var field = this.variationField();
|
64
|
+
return Boolean(field) && field.isColourSelectType();
|
65
|
+
};
|
66
|
+
|
67
|
+
this.isImageSelectField = function () {
|
68
|
+
var field = this.variationField();
|
69
|
+
return Boolean(field) && field.isImageSelectType();
|
70
|
+
};
|
71
|
+
|
72
|
+
this.isCheckboxOrRadioField = function () {
|
73
|
+
return this.isRadioField() || this.isCheckBoxField();
|
74
|
+
};
|
75
|
+
|
76
|
+
this.isSelectableField = function () {
|
77
|
+
var field = this.variationField();
|
78
|
+
return Boolean(field) && field.isSelectable();
|
79
|
+
};
|
80
|
+
|
81
|
+
this.canHaveMultipleSelected = function () {
|
82
|
+
var field = this.variationField();
|
83
|
+
return Boolean(field) && field.isDefaultMultiSelect();
|
84
|
+
};
|
85
|
+
|
86
|
+
this.isTextAreaField = function () {
|
87
|
+
var field = this.variationField();
|
88
|
+
return Boolean(field) && field.isTextAreaType();
|
89
|
+
};
|
90
|
+
|
91
|
+
this.isInstructionsField = function () {
|
92
|
+
var field = this.variationField();
|
93
|
+
return Boolean(field) && field.isInstructionsType();
|
94
|
+
};
|
95
|
+
|
96
|
+
this.isFileUpload = function () {
|
97
|
+
var field = this.variationField();
|
98
|
+
return Boolean(field) && field.isFileInput();
|
99
|
+
};
|
100
|
+
|
101
|
+
this.valueArray = function (updateValueArray) {
|
102
|
+
var valuesArray = [], i;
|
103
|
+
if (!isUndefined(updateValueArray)) {
|
104
|
+
this.value(updateValueArray.join(','));
|
105
|
+
return updateValueArray;
|
106
|
+
}
|
107
|
+
if (this.value() === "") {
|
108
|
+
return [];
|
109
|
+
}
|
110
|
+
valuesArray = String(this.value()).split(',');
|
111
|
+
for (i = 0; i < valuesArray.length; i++) {
|
112
|
+
valuesArray[i] = parseInt(valuesArray[i], 10);
|
113
|
+
}
|
114
|
+
return valuesArray;
|
115
|
+
};
|
116
|
+
|
117
|
+
this.textValue = function () {
|
118
|
+
var field = this.variationField(),
|
119
|
+
text = "", i;
|
120
|
+
if (field) {
|
121
|
+
if (this.isTextField() || this.isNumberField() ||
|
122
|
+
this.isTextAreaField()) {
|
123
|
+
return this.value();
|
124
|
+
}
|
125
|
+
if (this.isSelectableField() && this.selectedOptions()) {
|
126
|
+
for (i = 0; i < this.selectedOptions().length; i++) {
|
127
|
+
text += this.selectedOptions()[i].value() + " ";
|
128
|
+
}
|
129
|
+
return text;
|
130
|
+
}
|
131
|
+
}
|
132
|
+
return null;
|
133
|
+
};
|
134
|
+
this.optionIsSelected = function(id) {
|
135
|
+
const selectedIds = this.valueArray();
|
136
|
+
return -1 < selectedIds.findIndex(
|
137
|
+
(_id) => String(_id) === String(id));
|
138
|
+
};
|
139
|
+
|
140
|
+
this.selectedSelectableOptions = function () {
|
141
|
+
var self = this,
|
142
|
+
options = this.selectableOptions() ?
|
143
|
+
this.selectableOptions() : [];
|
144
|
+
return options.filter((o) =>
|
145
|
+
self.optionIsSelected(o.optionId()));
|
146
|
+
};
|
147
|
+
|
148
|
+
this.selectedFieldOptions = function () {
|
149
|
+
var field = this.variationField(),
|
150
|
+
options = field.options() ? field.options() : [],
|
151
|
+
valueArray = this.valueArray(),
|
152
|
+
optionsArray = [], selectedId, option, i, z;
|
153
|
+
for (i = 0; i < valueArray.length; i++) {
|
154
|
+
selectedId = valueArray[i];
|
155
|
+
for (z = 0; z < options.length; z++) {
|
156
|
+
option = options[z];
|
157
|
+
if (selectedId === option.id()) {
|
158
|
+
optionsArray.push(option);
|
159
|
+
}
|
160
|
+
}
|
161
|
+
}
|
162
|
+
return optionsArray;
|
163
|
+
};
|
164
|
+
|
165
|
+
this.findOptionValueIndex = function (optionId) {
|
166
|
+
return this.valueArray().indexOf(parseInt(optionId, 10));
|
167
|
+
};
|
168
|
+
|
169
|
+
this.optionIsChecked = function (optionId) {
|
170
|
+
return this.findOptionValueIndex(optionId) > -1;
|
171
|
+
};
|
172
|
+
|
173
|
+
this.addOptionToValueArray = function (optionId) {
|
174
|
+
var newValueArray = this.valueArray();
|
175
|
+
if (!this.optionIsChecked(optionId)) {
|
176
|
+
newValueArray.push(optionId);
|
177
|
+
this.valueArray(newValueArray);
|
178
|
+
}
|
179
|
+
};
|
180
|
+
|
181
|
+
this.removeOptionFromValueArray = function (optionId) {
|
182
|
+
var index = this.findOptionValueIndex(optionId),
|
183
|
+
newValueArray = this.valueArray();
|
184
|
+
newValueArray.splice(index, 1);
|
185
|
+
this.valueArray(newValueArray);
|
186
|
+
};
|
187
|
+
|
188
|
+
this.fieldName = function () {
|
189
|
+
return this.variationField().name();
|
190
|
+
};
|
191
|
+
|
192
|
+
this.fieldType = function () {
|
193
|
+
return this.variationField().fieldType();
|
194
|
+
};
|
195
|
+
|
196
|
+
this.hasOptions = function () {
|
197
|
+
return Boolean(this.selectedOptions());
|
198
|
+
};
|
199
|
+
this.hasMultipleOptions = function () {
|
200
|
+
return parseInt(this.fieldType(), 10) ===
|
201
|
+
fieldTypes.get("CHECKBOX");
|
202
|
+
};
|
203
|
+
|
204
|
+
this.isFileUpload = function () {
|
205
|
+
return parseInt(this.fieldType(), 10) ===
|
206
|
+
fieldTypes.get("FILE_UPLOAD");
|
207
|
+
};
|
208
|
+
|
209
|
+
this.isColourPicker = function () {
|
210
|
+
return parseInt(this.fieldType(), 10) ===
|
211
|
+
fieldTypes.get("COLOUR_PICKER");
|
212
|
+
};
|
213
|
+
|
214
|
+
this.clone = function () {
|
215
|
+
var cloneVariation = new Variation();
|
216
|
+
cloneVariation.value(this.value());
|
217
|
+
cloneVariation.cost(this.cost());
|
218
|
+
cloneVariation.variationField(this.variationField());
|
219
|
+
cloneVariation.variationFiles(this.variationFiles());
|
220
|
+
return cloneVariation;
|
221
|
+
};
|
222
|
+
|
223
|
+
this.valueIdArray = function () {
|
224
|
+
var value = this.value();
|
225
|
+
return value ? value.split(',') : [];
|
226
|
+
}
|
227
|
+
this.concatinatedSelectedOptionValues = function () {
|
228
|
+
var optionIds = this.valueIdArray(),
|
229
|
+
optionIdsLength = optionIds.length - 1,
|
230
|
+
field = this.variationField(),
|
231
|
+
value = '',
|
232
|
+
option,
|
233
|
+
i;
|
234
|
+
for (i = 0; i < optionIds.length; i++) {
|
235
|
+
option = field.findOptionById(optionIds[i]);
|
236
|
+
value += option.value();
|
237
|
+
if (optionIdsLength > i) {
|
238
|
+
value += ', ';
|
239
|
+
}
|
240
|
+
}
|
241
|
+
return value;
|
242
|
+
}
|
243
|
+
|
244
|
+
this.valueString = function () {
|
245
|
+
var field = this.variationField();
|
246
|
+
if (field.isSelectable()) {
|
247
|
+
return this.concatinatedSelectedOptionValues();
|
248
|
+
} else if (this.isFileUpload() && this.variationFiles()) {
|
249
|
+
if (this.variationFiles().length > 1) {
|
250
|
+
return 'uploaded files';
|
251
|
+
}
|
252
|
+
return 'uploaded file';
|
253
|
+
}
|
254
|
+
return this.value();
|
255
|
+
};
|
256
|
+
|
257
|
+
}
|
@@ -0,0 +1,261 @@
|
|
1
|
+
import { generateUUID } from './uuid.js';
|
2
|
+
import { fieldTypes } from './field_types.js';
|
3
|
+
import { addPropertyTo } from './model.js';
|
4
|
+
import { isUndefinedOrNull, clone } from './helpers.js';
|
5
|
+
import { DiscountGroup } from './discount_group.js';
|
6
|
+
import { VariationFieldsOption } from './variation_fields_option.js';
|
7
|
+
import { Variation } from './variation.js';
|
8
|
+
import { VariationOption } from './variation_option.js';
|
9
|
+
|
10
|
+
export function VariationField() {
|
11
|
+
this.resource = '/variationFields';
|
12
|
+
this.json = 'variationField';
|
13
|
+
this.temporaryId = generateUUID();
|
14
|
+
|
15
|
+
addPropertyTo(this, 'id');
|
16
|
+
addPropertyTo(this, 'fieldType');
|
17
|
+
addPropertyTo(this, 'name');
|
18
|
+
addPropertyTo(this, 'position');
|
19
|
+
addPropertyTo(this, 'placeholder');
|
20
|
+
addPropertyTo(this, 'defaultValue');
|
21
|
+
addPropertyTo(this, 'required');
|
22
|
+
addPropertyTo(this, 'independent');
|
23
|
+
addPropertyTo(this, 'variationCost');
|
24
|
+
addPropertyTo(this, 'variationCostDiscountGroup', DiscountGroup);
|
25
|
+
addPropertyTo(this, 'variationUnitCost');
|
26
|
+
addPropertyTo(this, 'variationUnitCostDiscountGroup', DiscountGroup);
|
27
|
+
addPropertyTo(this, 'options', VariationFieldsOption);
|
28
|
+
addPropertyTo(this, 'defaultOptions', VariationFieldsOption);
|
29
|
+
addPropertyTo(this, 'multipleSelect');
|
30
|
+
addPropertyTo(this, 'rows');
|
31
|
+
addPropertyTo(this, 'fieldMin');
|
32
|
+
addPropertyTo(this, 'fieldMax');
|
33
|
+
addPropertyTo(this, 'showFilePreview');
|
34
|
+
addPropertyTo(this, 'allowDecimal');
|
35
|
+
addPropertyTo(this, 'allowFileMultiple');
|
36
|
+
addPropertyTo(this, 'allowFileJpeg');
|
37
|
+
addPropertyTo(this, 'allowFileGif');
|
38
|
+
addPropertyTo(this, 'allowFilePdf');
|
39
|
+
addPropertyTo(this, 'allowFilePng');
|
40
|
+
addPropertyTo(this, 'allowFileAi');
|
41
|
+
addPropertyTo(this, 'sellerProductEditable');
|
42
|
+
|
43
|
+
this.isType = function (typeString) {
|
44
|
+
return parseInt(this.fieldType(), 10) ===
|
45
|
+
fieldTypes.get(typeString);
|
46
|
+
};
|
47
|
+
|
48
|
+
this.isTextType = function () {
|
49
|
+
return this.isType('TEXT_INPUT');
|
50
|
+
};
|
51
|
+
|
52
|
+
this.isNumberType = function () {
|
53
|
+
return this.isType('NUMBER_INPUT');
|
54
|
+
};
|
55
|
+
|
56
|
+
this.isSelectType = function () {
|
57
|
+
return this.isType('SELECT');
|
58
|
+
};
|
59
|
+
|
60
|
+
this.isDefaultMultiSelect = function () {
|
61
|
+
return this.isType('CHECKBOX') || this.isType('IMAGE_SELECT') &&
|
62
|
+
this.multipleSelect();
|
63
|
+
};
|
64
|
+
|
65
|
+
this.isCheckboxType = function () {
|
66
|
+
return this.isType('CHECKBOX');
|
67
|
+
};
|
68
|
+
|
69
|
+
this.isRadioType = function () {
|
70
|
+
return this.isType('RADIO');
|
71
|
+
};
|
72
|
+
this.hasOptions = function () {
|
73
|
+
return Boolean(this.options());
|
74
|
+
};
|
75
|
+
|
76
|
+
this.isCheckboxOrRadio = function () {
|
77
|
+
return this.isCheckboxType() || this.isRadioType();
|
78
|
+
};
|
79
|
+
|
80
|
+
this.isTextAreaType = function () {
|
81
|
+
return this.isType('TEXT_AREA');
|
82
|
+
};
|
83
|
+
|
84
|
+
this.isInstructionsType = function () {
|
85
|
+
return this.isType('FIELD_INSTRUCTIONS');
|
86
|
+
};
|
87
|
+
|
88
|
+
this.isFileInput = function () {
|
89
|
+
return this.isType('FILE_UPLOAD');
|
90
|
+
};
|
91
|
+
|
92
|
+
this.isColourPickerType = function () {
|
93
|
+
return this.isType('COLOUR_PICKER');
|
94
|
+
};
|
95
|
+
|
96
|
+
this.isColourSelectType = function () {
|
97
|
+
return this.isType('COLOUR_SELECT');
|
98
|
+
};
|
99
|
+
|
100
|
+
this.isImageSelectType = function () {
|
101
|
+
return this.isType('IMAGE_SELECT');
|
102
|
+
};
|
103
|
+
this.isSelectable = function () {
|
104
|
+
return this.isSelectType() || this.isCheckboxOrRadio() ||
|
105
|
+
this.isImageSelectType() || this.isColourSelectType();
|
106
|
+
};
|
107
|
+
|
108
|
+
this.canMultiSelect = function () {
|
109
|
+
return this.isImageSelectType() || this.isColourSelectType();
|
110
|
+
}
|
111
|
+
|
112
|
+
this.fieldInputTypeAttributeValue = function () {
|
113
|
+
var inputType = this.fieldType(),
|
114
|
+
inputTypeString = null;
|
115
|
+
if (inputType === fieldTypes.get("TEXT_INPUT")) {
|
116
|
+
inputTypeString = 'text';
|
117
|
+
} else if (inputType === fieldTypes.get('FILE_UPLOAD')) {
|
118
|
+
inputTypeString = 'file';
|
119
|
+
} else if (inputType === fieldTypes.get('NUMBER_INPUT')) {
|
120
|
+
inputTypeString = 'number';
|
121
|
+
} else if (inputType === fieldTypes.get('RADIO')) {
|
122
|
+
inputTypeString = 'radio';
|
123
|
+
} else if (inputType === fieldTypes.get('IMAGE_SELECT')) {
|
124
|
+
if (this.multipleSelect()) {
|
125
|
+
inputTypeString = 'checkbox';
|
126
|
+
} else {
|
127
|
+
inputTypeString = 'radio';
|
128
|
+
}
|
129
|
+
} else if (inputType === fieldTypes.get('CHECKBOX')) {
|
130
|
+
inputTypeString = 'checkbox';
|
131
|
+
} else if (inputType === fieldTypes.get('COLOUR_PICKER')) {
|
132
|
+
inputTypeString = 'color';
|
133
|
+
}
|
134
|
+
return inputTypeString;
|
135
|
+
};
|
136
|
+
|
137
|
+
this.hasMultipleDefaults = function () {
|
138
|
+
return this.optionsDefaults().length > 1;
|
139
|
+
};
|
140
|
+
|
141
|
+
this.setSingleOptionDefault = function (index) {
|
142
|
+
var i, options = this.options();
|
143
|
+
for (i = 0; i < options.length; i++) {
|
144
|
+
options[i].default(false);
|
145
|
+
}
|
146
|
+
options[index].default(true);
|
147
|
+
}
|
148
|
+
|
149
|
+
this.optionsDefaults = function () {
|
150
|
+
var i, defaultsArray = [],
|
151
|
+
options = this.options();
|
152
|
+
for (i = 0; i < options.length; i++) {
|
153
|
+
if (options[i].default()) {
|
154
|
+
defaultsArray.push(options[i]);
|
155
|
+
}
|
156
|
+
}
|
157
|
+
return defaultsArray;
|
158
|
+
};
|
159
|
+
|
160
|
+
this.findOptionById = function (id) {
|
161
|
+
var i = 0, options;
|
162
|
+
options = this.options();
|
163
|
+
for (i = 0; i < options.length; i++) {
|
164
|
+
if (parseInt(options[i].id(), 10) === parseInt(id, 10)) {
|
165
|
+
return options[i];
|
166
|
+
}
|
167
|
+
}
|
168
|
+
return null;
|
169
|
+
};
|
170
|
+
|
171
|
+
|
172
|
+
this.allowFileJpegString = function () {
|
173
|
+
return Boolean(this.allowFileJpeg()) ? ".jpeg, .jpg" : "";
|
174
|
+
};
|
175
|
+
|
176
|
+
this.allowFileGifString = function () {
|
177
|
+
return Boolean(this.allowFileGif()) ? ".gif" : "";
|
178
|
+
};
|
179
|
+
|
180
|
+
this.allowFilePdfString = function () {
|
181
|
+
return Boolean(this.allowFilePdf()) ? ".pdf" : "";
|
182
|
+
};
|
183
|
+
|
184
|
+
this.allowFilePngString = function () {
|
185
|
+
return Boolean(this.allowFilePng()) ? ".png" : "";
|
186
|
+
};
|
187
|
+
|
188
|
+
this.allowFileAiString = function () {
|
189
|
+
return Boolean(this.allowFileAi()) ? ".ai" : "";
|
190
|
+
};
|
191
|
+
|
192
|
+
this.allowedFileTypesString = function () {
|
193
|
+
function appendType(fileTypeString) {
|
194
|
+
if (fileTypeString !== "") {
|
195
|
+
return fileTypeString + ", ";
|
196
|
+
}
|
197
|
+
return "";
|
198
|
+
}
|
199
|
+
return appendType(this.allowFileJpegString()) +
|
200
|
+
appendType(this.allowFileGifString()) +
|
201
|
+
appendType(this.allowFilePdfString()) +
|
202
|
+
appendType(this.allowFilePngString()) +
|
203
|
+
appendType(this.allowFileAiString());
|
204
|
+
};
|
205
|
+
this.allowFileMultipleString = function () {
|
206
|
+
if (this.allowFileMultiple()) {
|
207
|
+
return "multiple";
|
208
|
+
}
|
209
|
+
return "";
|
210
|
+
};
|
211
|
+
this.buildEmptyVariation = function () {
|
212
|
+
var variationBuilt = new Variation(),
|
213
|
+
value, options, i,
|
214
|
+
onceOffCost = 0,
|
215
|
+
selectableOptions = [],
|
216
|
+
sellerProductEditable = this.sellerProductEditable();
|
217
|
+
if (this.isSelectable()) {
|
218
|
+
options = this.options();
|
219
|
+
value = [];
|
220
|
+
for (i = 0; i < options.length; i++) {
|
221
|
+
const selectableOption = new VariationOption();
|
222
|
+
selectableOption.copyFieldOption(options[i]);
|
223
|
+
selectableOptions.push(selectableOption);
|
224
|
+
if ((!sellerProductEditable && options[i].default()) ||
|
225
|
+
(sellerProductEditable && options[i].include())) {
|
226
|
+
value.push(options[i].id());
|
227
|
+
onceOffCost += options[i].variationCost();
|
228
|
+
}
|
229
|
+
}
|
230
|
+
variationBuilt.value(value.join());
|
231
|
+
variationBuilt.onceOffCost(onceOffCost);
|
232
|
+
} else {
|
233
|
+
variationBuilt.value(this.defaultValue());
|
234
|
+
variationBuilt.unitCost(this.variationUnitCost());
|
235
|
+
variationBuilt.onceOffCost(this.variationCost());
|
236
|
+
}
|
237
|
+
variationBuilt.unitCostTotal('0');
|
238
|
+
variationBuilt.cost(variationBuilt.onceOffCost());
|
239
|
+
variationBuilt.variationField(clone(this));
|
240
|
+
variationBuilt.selectableOptions(selectableOptions);
|
241
|
+
return variationBuilt;
|
242
|
+
};
|
243
|
+
|
244
|
+
this.optionsHaveCost = function () {
|
245
|
+
var i, options, o;
|
246
|
+
function hasCost(cost) {
|
247
|
+
return !isUndefinedOrNull(cost);
|
248
|
+
}
|
249
|
+
if (this.isSelectable()) {
|
250
|
+
options = this.options();
|
251
|
+
for (i = 0; i < options.length; i++) {
|
252
|
+
o = options[i];
|
253
|
+
if (hasCost(o.variationCost()) ||
|
254
|
+
hasCost(o.variationUnitCost())) {
|
255
|
+
return true;
|
256
|
+
}
|
257
|
+
}
|
258
|
+
}
|
259
|
+
return false;
|
260
|
+
}
|
261
|
+
}
|
@@ -0,0 +1,41 @@
|
|
1
|
+
import { generateUUID } from './uuid.js';
|
2
|
+
import { addPropertyTo } from './model.js';
|
3
|
+
import { DiscountGroup } from './discount_group.js';
|
4
|
+
import { MerchiFile } from './merchi_file.js';
|
5
|
+
import { VariationField } from './variation_field.js';
|
6
|
+
|
7
|
+
export function VariationFieldsOption() {
|
8
|
+
this.resource = '/variationFieldOptions';
|
9
|
+
this.json = 'variationFieldOption';
|
10
|
+
this.temporaryId = generateUUID();
|
11
|
+
|
12
|
+
addPropertyTo(this, 'id');
|
13
|
+
addPropertyTo(this, 'value');
|
14
|
+
addPropertyTo(this, 'position');
|
15
|
+
addPropertyTo(this, 'default');
|
16
|
+
addPropertyTo(this, 'include');
|
17
|
+
addPropertyTo(this, 'colour');
|
18
|
+
addPropertyTo(this, 'variationCost');
|
19
|
+
addPropertyTo(this, 'variationCostDiscountGroup', DiscountGroup);
|
20
|
+
addPropertyTo(this, 'variationUnitCost');
|
21
|
+
addPropertyTo(this, 'variationUnitCostDiscountGroup', DiscountGroup);
|
22
|
+
addPropertyTo(this, 'linkedFile', MerchiFile);
|
23
|
+
addPropertyTo(this, 'variationField', VariationField)
|
24
|
+
|
25
|
+
this.totalCost = function (quantity) {
|
26
|
+
var total = this.variationCost() ?
|
27
|
+
this.variationCost() : 0;
|
28
|
+
if (this.variationUnitCost() && quantity) {
|
29
|
+
total += (quantity * this.variationUnitCost());
|
30
|
+
}
|
31
|
+
return total;
|
32
|
+
};
|
33
|
+
|
34
|
+
this.onceOffCost = function () {
|
35
|
+
return this.variationCost();
|
36
|
+
};
|
37
|
+
|
38
|
+
this.unitCost = function () {
|
39
|
+
return this.variationUnitCost();
|
40
|
+
};
|
41
|
+
}
|
@@ -0,0 +1,59 @@
|
|
1
|
+
import { generateUUID } from './uuid.js';
|
2
|
+
import { addPropertyTo } from './model.js';
|
3
|
+
import { MerchiFile } from './merchi_file.js';
|
4
|
+
import { Variation } from './variation.js';
|
5
|
+
|
6
|
+
export function VariationOption() {
|
7
|
+
this.json = 'variation_option';
|
8
|
+
this.temporaryId = generateUUID();
|
9
|
+
|
10
|
+
addPropertyTo(this, 'optionId');
|
11
|
+
addPropertyTo(this, 'value');
|
12
|
+
addPropertyTo(this, 'available');
|
13
|
+
addPropertyTo(this, 'position');
|
14
|
+
addPropertyTo(this, 'default');
|
15
|
+
addPropertyTo(this, 'include');
|
16
|
+
addPropertyTo(this, 'colour');
|
17
|
+
addPropertyTo(this, 'quantity');
|
18
|
+
addPropertyTo(this, 'onceOffCost');
|
19
|
+
addPropertyTo(this, 'unitCost');
|
20
|
+
addPropertyTo(this, 'unitCostTotal');
|
21
|
+
addPropertyTo(this, 'totalCost');
|
22
|
+
addPropertyTo(this, 'fieldName');
|
23
|
+
addPropertyTo(this, 'linkedFile', MerchiFile);
|
24
|
+
|
25
|
+
this.copyFieldOption = function (option) {
|
26
|
+
this.optionId(option.id());
|
27
|
+
this.value(option.value());
|
28
|
+
this.colour(option.colour());
|
29
|
+
this.position(option.position());
|
30
|
+
this.default(option.default());
|
31
|
+
this.onceOffCost(option.variationCost());
|
32
|
+
this.unitCost(option.variationUnitCost());
|
33
|
+
this.linkedFile(option.linkedFile());
|
34
|
+
}
|
35
|
+
|
36
|
+
// a hack around function for job cloneable renderering
|
37
|
+
this.covertToVariation = function () {
|
38
|
+
var variationConverted = new Variation(),
|
39
|
+
unitCost = this.unitCost(),
|
40
|
+
fieldName = this.fieldName(),
|
41
|
+
optionValue = this.value();
|
42
|
+
variationConverted.value(this.optionId());
|
43
|
+
variationConverted.quantity(this.quantity());
|
44
|
+
variationConverted.onceOffCost(this.onceOffCost());
|
45
|
+
variationConverted.unitCostTotal(this.unitCostTotal());
|
46
|
+
|
47
|
+
// hack around for variation unit cost
|
48
|
+
variationConverted.unitCost = function () {
|
49
|
+
return unitCost;
|
50
|
+
};
|
51
|
+
variationConverted.valueString = function () {
|
52
|
+
return optionValue;
|
53
|
+
};
|
54
|
+
variationConverted.fieldName = function () {
|
55
|
+
return fieldName;
|
56
|
+
};
|
57
|
+
return variationConverted;
|
58
|
+
};
|
59
|
+
}
|
@@ -0,0 +1,43 @@
|
|
1
|
+
import { generateUUID } from './uuid.js';
|
2
|
+
import { addPropertyTo } from './model.js';
|
3
|
+
import { Variation } from './variation.js';
|
4
|
+
|
5
|
+
export function VariationsGroup() {
|
6
|
+
this.resource = '/variationsGroups';
|
7
|
+
this.json = 'variationsGroup';
|
8
|
+
this.temporaryId = generateUUID();
|
9
|
+
|
10
|
+
addPropertyTo(this, 'id');
|
11
|
+
addPropertyTo(this, 'inventoryCount');
|
12
|
+
addPropertyTo(this, 'inventorySufficient');
|
13
|
+
addPropertyTo(this, 'quantity');
|
14
|
+
addPropertyTo(this, 'groupCost');
|
15
|
+
addPropertyTo(this, 'variations', Variation);
|
16
|
+
|
17
|
+
this.clone = function () {
|
18
|
+
var groupClone = new VariationsGroup(),
|
19
|
+
variationsClone = [], i;
|
20
|
+
groupClone.groupCost(this.groupCost());
|
21
|
+
groupClone.quantity(this.quantity());
|
22
|
+
for (i = 0; i < this.variations().length; i++) {
|
23
|
+
variationsClone.push(this.variations()[i].clone());
|
24
|
+
}
|
25
|
+
return groupClone.variations(variationsClone);
|
26
|
+
};
|
27
|
+
|
28
|
+
this.loopVariationsAndReturnAttributeTotal = function (attribute) {
|
29
|
+
var variations = this.variations() ?
|
30
|
+
this.variations() : [],
|
31
|
+
total = 0,
|
32
|
+
i;
|
33
|
+
for (i = 0; i < variations.length; i++) {
|
34
|
+
total += variations[i][attribute]();
|
35
|
+
}
|
36
|
+
return parseFloat(total).toFixed(2);
|
37
|
+
};
|
38
|
+
|
39
|
+
this.variationsUnitCostAndOnceOffCost = function () {
|
40
|
+
return this.loopVariationsAndReturnAttributeTotal(
|
41
|
+
'unitCostAndOnceOffCost');
|
42
|
+
};
|
43
|
+
}
|