@salla.sa/twilight-components 2.13.93 → 2.13.95
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/dist/cjs/app-globals-c5340b59.js.map +1 -1
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/salla-add-product-button_48.cjs.entry.js.map +1 -1
- package/dist/cjs/salla-metadata.cjs.entry.js +19 -5
- package/dist/cjs/salla-metadata.cjs.entry.js.map +1 -1
- package/dist/cjs/salla-product-options.cjs.entry.js +110 -39
- package/dist/cjs/salla-product-options.cjs.entry.js.map +1 -1
- package/dist/cjs/twilight.cjs.js +1 -1
- package/dist/collection/components/salla-metadata/salla-metadata.js +22 -8
- package/dist/collection/components/salla-metadata/salla-metadata.js.map +1 -1
- package/dist/collection/components/salla-product-options/interfaces.js +2 -0
- package/dist/collection/components/salla-product-options/interfaces.js.map +1 -1
- package/dist/collection/components/salla-product-options/salla-product-options.js +118 -40
- package/dist/collection/components/salla-product-options/salla-product-options.js.map +1 -1
- package/dist/components/index.js.map +1 -1
- package/dist/components/salla-metadata.js +20 -6
- package/dist/components/salla-metadata.js.map +1 -1
- package/dist/components/salla-product-options.js +111 -39
- package/dist/components/salla-product-options.js.map +1 -1
- package/dist/components/salla-quick-buy2.js.map +1 -1
- package/dist/esm/app-globals-0280e1d0.js.map +1 -1
- package/dist/esm/loader.js +1 -1
- package/dist/esm/salla-add-product-button_48.entry.js.map +1 -1
- package/dist/esm/salla-metadata.entry.js +19 -5
- package/dist/esm/salla-metadata.entry.js.map +1 -1
- package/dist/esm/salla-product-options.entry.js +110 -39
- package/dist/esm/salla-product-options.entry.js.map +1 -1
- package/dist/esm/twilight.js +1 -1
- package/dist/esm-es5/app-globals-0280e1d0.js.map +1 -1
- package/dist/esm-es5/loader.js +1 -1
- package/dist/esm-es5/loader.js.map +1 -1
- package/dist/esm-es5/salla-add-product-button_48.entry.js.map +1 -1
- package/dist/esm-es5/salla-metadata.entry.js +1 -1
- package/dist/esm-es5/salla-metadata.entry.js.map +1 -1
- package/dist/esm-es5/salla-product-options.entry.js +2 -2
- package/dist/esm-es5/salla-product-options.entry.js.map +1 -1
- package/dist/esm-es5/twilight.js +1 -1
- package/dist/esm-es5/twilight.js.map +1 -1
- package/dist/twilight/p-4a9df09e.js.map +1 -1
- package/dist/twilight/p-4c2194e3.system.js.map +1 -1
- package/dist/twilight/p-54e1a882.system.js +1 -1
- package/dist/twilight/p-54e1a882.system.js.map +1 -1
- package/dist/twilight/p-903962d6.system.entry.js.map +1 -1
- package/dist/twilight/p-a9ab9d77.entry.js +5 -0
- package/dist/twilight/p-a9ab9d77.entry.js.map +1 -0
- package/dist/twilight/p-c59441ec.entry.js +5 -0
- package/dist/twilight/p-c59441ec.entry.js.map +1 -0
- package/dist/twilight/p-c612fde8.entry.js.map +1 -1
- package/dist/twilight/p-dc2eef69.system.entry.js +5 -0
- package/dist/twilight/p-dc2eef69.system.entry.js.map +1 -0
- package/dist/twilight/p-eb2edde3.system.entry.js +5 -0
- package/dist/twilight/p-eb2edde3.system.entry.js.map +1 -0
- package/dist/twilight/twilight.esm.js +1 -1
- package/dist/twilight/twilight.esm.js.map +1 -1
- package/dist/types/components/salla-metadata/salla-metadata.d.ts +2 -1
- package/dist/types/components/salla-product-options/interfaces.d.ts +5 -0
- package/dist/types/components/salla-product-options/salla-product-options.d.ts +14 -3
- package/dist/types/components.d.ts +2 -2
- package/package.json +5 -5
- package/dist/twilight/p-1ae3cce4.system.entry.js +0 -5
- package/dist/twilight/p-1ae3cce4.system.entry.js.map +0 -1
- package/dist/twilight/p-81b169bc.system.entry.js +0 -5
- package/dist/twilight/p-81b169bc.system.entry.js.map +0 -1
- package/dist/twilight/p-d3b196a8.entry.js +0 -5
- package/dist/twilight/p-d3b196a8.entry.js.map +0 -1
- package/dist/twilight/p-e057192c.entry.js +0 -5
- package/dist/twilight/p-e057192c.entry.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/components/salla-product-options/interfaces.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/components/salla-product-options/interfaces.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,WAsBX;AAtBD,WAAY,WAAW;EACrB,8BAAe,CAAA;EACf,4BAAa,CAAA;EACb,oCAAqB,CAAA;EACrB,oCAAqB,CAAA;EACrB,8BAAe,CAAA;EACf,oDAAqC,CAAA;EACrC,gCAAiB,CAAA;EACjB,8CAA+B,CAAA;EAC/B,wDAAyC,CAAA;EACzC,kCAAmB,CAAA;EACnB,oCAAqB,CAAA;EACrB,4BAAa,CAAA;EACb,oCAAqB,CAAA;EACrB,sCAAuB,CAAA;EACvB,4BAAa,CAAA;EACb,8BAAe,CAAA;EACf,oCAAqB,CAAA;EACrB,0BAAW,CAAA;EACX,4BAAa,CAAA;EACb,4CAA6B,CAAA;EAC7B,kCAAmB,CAAA;AACrB,CAAC,EAtBW,WAAW,KAAX,WAAW,QAsBtB;AAqID,MAAM,CAAN,IAAY,QAEX;AAFD,WAAY,QAAQ;EAClB,uBAAW,CAAA;AACb,CAAC,EAFW,QAAQ,KAAR,QAAQ,QAEnB","sourcesContent":["export enum DisplayType {\n COLOR = \"color\",\n DATE = \"date\",\n DATETIME = \"datetime\",\n DONATION = \"donation\",\n IMAGE = \"image\",\n MULTIPLE_OPTIONS = \"multiple-options\",\n NUMBER = \"number\",\n SINGLE_OPTION = \"single-option\",\n DIGITAL_CARD_VALUE = \"digital-code-value\",\n COUNTRY = \"country\",\n SPLITTER = \"splitter\",\n TEXT = \"text\",\n TEXTAREA = \"textarea\",\n THUMBNAIL = \"thumbnail\",\n TIME = \"time\",\n RADIO = \"radio\",\n CHECKBOX = \"checkbox\",\n MAP = \"map\",\n FILE = \"file\", // similar to image type (file-uploader component)\n COLOR_PICKER = \"color_picker\",\n BOOKING = \"booking\"\n}\n\nexport interface ProductDetail {\n id: string;\n sku: string;\n name: string;\n description: string;\n url: string;\n promotion_title: string;\n subtitle: string;\n type: string;\n status: string;\n price: number;\n sale_price: number;\n regular_price: number;\n starting_price: null;\n quantity: number;\n max_quantity: number;\n discount_ends: number;\n is_taxable: boolean;\n has_read_more: boolean;\n can_add_note: boolean;\n can_show_remained_quantity: boolean;\n can_upload_file: boolean;\n has_custom_form: boolean;\n is_on_sale: boolean;\n is_hidden_quantity: boolean;\n is_available: boolean;\n is_out_of_stock: boolean;\n weight: null;\n calories: null;\n image: SimpleImage;\n brand: Brand;\n donation?: ProductDonation;\n images: Image[];\n tags: Tag[];\n notify_availability: null;\n rating: Rating;\n options: Option[];\n sold_quantity: number;\n category: Category;\n}\n\nexport interface SimpleImage {\n url: string;\n alt: string;\n}\n\nexport interface Category {\n name: string;\n url: string;\n icon: string;\n}\n\nexport interface ProductDonation {\n target_message?: string;\n collected_amount?: number;\n target_amount?: number;\n target_percent?: number;\n target_end_date?: string;\n can_donate: boolean;\n custom_amount_enabled: boolean;\n}\n\nexport interface Image {\n id: number;\n url: string;\n main: boolean;\n three_d_image_url: string;\n alt: string;\n video_url: string;\n type: string;\n sort: number;\n}\n\nexport interface Option {\n id: number;\n name: string;\n required: boolean;\n type: string;\n placeholder: string;\n option_type: string;\n not_same_day_order: boolean;\n availability_range: number;\n from_date_time: null;\n to_date_time: null;\n visibility_condition?: { option: number, operator: \"=\" | \"!=\", value: number };\n details?: Detail[];\n condition_attributes: string;\n value?: any;\n length?: number;\n donation?: Donation\n}\n\nexport interface Donation {\n custom_amount_enabled: boolean;\n target_message?: string;\n target_date: string | \"2023-04-18\";\n target_end_date: string | \"2023-04-18\";\n target_amount: number;\n collected_amount: number;\n can_donate: boolean;\n}\n\nexport interface Detail {\n id: number;\n option_id: number;\n name: string;\n additional_price: number;\n option_value: null | string;\n image: null | string;\n color: null | string;\n is_out: boolean;\n skus_availability?: { [sku_id: number]: boolean };\n is_selected: boolean;\n is_default?: 0 | 1;\n code?: string;\n type?: string;\n\n}\n\nexport interface Brand {\n id: string;\n url: string;\n name: string;\n logo: string;\n}\n\nexport interface PreTaxPrice {\n amount: number;\n currency: Currency;\n}\n\nexport enum Currency {\n Sar = \"SAR\",\n}\n\nexport interface Promotion {\n title: string;\n sub_title: string;\n}\n\nexport interface Rating {\n count: number;\n stars: number;\n}\n\nexport interface Tag {\n name: string;\n url: string;\n}\n"]}
|
|
@@ -17,8 +17,13 @@ export class SallaProductOptions {
|
|
|
17
17
|
txt: 'text/plain',
|
|
18
18
|
};
|
|
19
19
|
this.outSkus = [];
|
|
20
|
+
/**
|
|
21
|
+
* Avoid selection of previous default or selected card value option
|
|
22
|
+
* when switching between digital card country options for the 1st time
|
|
23
|
+
*/
|
|
24
|
+
this.ignoreDefaultCardValue = false;
|
|
20
25
|
this.handleDonationOptions = (event, detail, type) => {
|
|
21
|
-
if (detail
|
|
26
|
+
if (detail === 'custom' && type === 'input') {
|
|
22
27
|
salla.helpers.inputDigitsOnly(event.target);
|
|
23
28
|
salla.event.emit('product-options::donation-changed', {
|
|
24
29
|
id: this.productId,
|
|
@@ -37,7 +42,7 @@ export class SallaProductOptions {
|
|
|
37
42
|
else {
|
|
38
43
|
this.donationInput.value = event.target.value;
|
|
39
44
|
}
|
|
40
|
-
if (detail
|
|
45
|
+
if (detail === 'custom') {
|
|
41
46
|
return;
|
|
42
47
|
}
|
|
43
48
|
salla.event.emit('product-options::donation-changed', {
|
|
@@ -56,11 +61,11 @@ export class SallaProductOptions {
|
|
|
56
61
|
if (!option.donation) {
|
|
57
62
|
return;
|
|
58
63
|
}
|
|
59
|
-
|
|
64
|
+
const completed = option.donation.target_amount <= option.donation.collected_amount;
|
|
60
65
|
return h("div", { class: { "s-product-options-donation-message": true, "s-product-options-donation-completed": completed, "s-product-options-donation-expired": !completed } }, h("p", null, option.donation.target_message), h("span", null, completed ? salla.money(option.donation.target_amount) : ''));
|
|
61
66
|
};
|
|
62
67
|
this.optionsData = undefined;
|
|
63
|
-
this.outOfStockText =
|
|
68
|
+
this.outOfStockText = "";
|
|
64
69
|
this.donationAmount = salla.lang.get('pages.products.donation_amount');
|
|
65
70
|
this.selectDonationAmount = salla.lang.getWithDefault('pages.products.select_donation_amount', 'تحديد مبلغ التبرع');
|
|
66
71
|
this.selectAmount = salla.lang.getWithDefault('pages.products.select_amount', 'اختر المبلغ');
|
|
@@ -69,6 +74,7 @@ export class SallaProductOptions {
|
|
|
69
74
|
this.canDisabled = undefined;
|
|
70
75
|
this.selectedSkus = undefined;
|
|
71
76
|
this.selectedOutSkus = undefined;
|
|
77
|
+
this.availableDigitalCardValues = [];
|
|
72
78
|
this.productId = salla.config.get('page.id');
|
|
73
79
|
this.options = undefined;
|
|
74
80
|
this.canDisabled = !salla.config.get('store.settings.product.notify_options_availability');
|
|
@@ -98,7 +104,7 @@ export class SallaProductOptions {
|
|
|
98
104
|
setOptionsData(optionsData) {
|
|
99
105
|
var _a, _b;
|
|
100
106
|
this.optionsData = optionsData;
|
|
101
|
-
|
|
107
|
+
const that = this;
|
|
102
108
|
(_b = (_a = this.optionsData[0]) === null || _a === void 0 ? void 0 : _a.details) === null || _b === void 0 ? void 0 : _b.forEach(function (detail) {
|
|
103
109
|
Object.entries(detail.skus_availability || {})
|
|
104
110
|
.filter(sku => !sku[1])
|
|
@@ -109,10 +115,12 @@ export class SallaProductOptions {
|
|
|
109
115
|
* Get the id's of the selected options.
|
|
110
116
|
* */
|
|
111
117
|
async getSelectedOptionsData() {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
formData.forEach(
|
|
115
|
-
|
|
118
|
+
const selectedOptions = {};
|
|
119
|
+
const formData = this.host.getElementSallaData();
|
|
120
|
+
formData.forEach((value, key) => {
|
|
121
|
+
if (key.startsWith('options[')) {
|
|
122
|
+
(selectedOptions[key.replace('options[', '').replace(']', '')] = value);
|
|
123
|
+
}
|
|
116
124
|
});
|
|
117
125
|
return selectedOptions;
|
|
118
126
|
}
|
|
@@ -120,7 +128,7 @@ export class SallaProductOptions {
|
|
|
120
128
|
* Report options form validity.
|
|
121
129
|
* */
|
|
122
130
|
async reportValidity() {
|
|
123
|
-
|
|
131
|
+
const requiredElements = this.host.querySelectorAll('[required]');
|
|
124
132
|
let pass = true;
|
|
125
133
|
for (let i = 0; i < requiredElements.length; i++) {
|
|
126
134
|
//if there is only one invalid option, return false
|
|
@@ -158,24 +166,27 @@ export class SallaProductOptions {
|
|
|
158
166
|
closestProductOption.classList.add('s-product-options-option-error');
|
|
159
167
|
}
|
|
160
168
|
changedHandler(event, option) {
|
|
161
|
-
|
|
169
|
+
const data = { event: event, option: option, detail: null };
|
|
162
170
|
if (option.details) {
|
|
163
|
-
|
|
171
|
+
const detail = option.details.find((detail) => {
|
|
164
172
|
return Number(detail.id) === Number(event.target.value);
|
|
165
173
|
});
|
|
166
174
|
data.detail = detail;
|
|
167
175
|
}
|
|
168
|
-
|
|
176
|
+
if (option.type === 'country') {
|
|
177
|
+
this.handleCountryOptionChange(event, data.detail);
|
|
178
|
+
}
|
|
179
|
+
const optionElement = event.target.closest('.s-product-options-option');
|
|
169
180
|
if (event.target.value
|
|
170
|
-
|| ((option.type
|
|
171
|
-
|| (option.type
|
|
181
|
+
|| ((option.type === DisplayType.FILE || option.type === DisplayType.IMAGE) && event.type === 'added')
|
|
182
|
+
|| (option.type === DisplayType.MAP && event.type === 'selected' && (event.target.lat && event.target.lng))) {
|
|
172
183
|
setTimeout(() => {
|
|
173
184
|
optionElement.classList.remove('s-product-options-option-error');
|
|
174
185
|
}, 200);
|
|
175
186
|
}
|
|
176
187
|
const index = this.selectedOptions.findIndex(option => option.option_id === data.option.id);
|
|
177
188
|
index > -1 ? this.selectedOptions[index] = Object.assign(Object.assign({}, data.detail), { option_id: data.option.id }) : this.selectedOptions.push(Object.assign(Object.assign({}, data.detail), { option_id: data.option.id }));
|
|
178
|
-
if (option.type
|
|
189
|
+
if (option.type === DisplayType.DONATION) {
|
|
179
190
|
salla.event.emit('product-options::donation-changed', {
|
|
180
191
|
id: this.productId,
|
|
181
192
|
price: event.target.value
|
|
@@ -204,7 +215,7 @@ export class SallaProductOptions {
|
|
|
204
215
|
}
|
|
205
216
|
getLatLng(value, type) {
|
|
206
217
|
return value
|
|
207
|
-
? value.split(',')[type
|
|
218
|
+
? value.split(',')[type === 'lat' ? 0 : 1]
|
|
208
219
|
: '';
|
|
209
220
|
}
|
|
210
221
|
getDisplayForType(option) {
|
|
@@ -220,6 +231,12 @@ export class SallaProductOptions {
|
|
|
220
231
|
if (option.type === DisplayType.SINGLE_OPTION) {
|
|
221
232
|
return this.singleOption(option);
|
|
222
233
|
}
|
|
234
|
+
if (option.type === DisplayType.DIGITAL_CARD_VALUE) {
|
|
235
|
+
return this.digitalCardValuesOption(option);
|
|
236
|
+
}
|
|
237
|
+
if (option.type === DisplayType.COUNTRY) {
|
|
238
|
+
return this.countryOption(option);
|
|
239
|
+
}
|
|
223
240
|
if (option.type === DisplayType.BOOKING && salla.url.is_page("cart")) {
|
|
224
241
|
return h("salla-booking-field", { onInvalidInput: (e) => this.invalidHandler(e, option), option: option, productId: option.value });
|
|
225
242
|
}
|
|
@@ -231,8 +248,43 @@ export class SallaProductOptions {
|
|
|
231
248
|
? { "data-show-when": `options[${option.visibility_condition.option}] ${option.visibility_condition.operator} ${option.visibility_condition.value}` }
|
|
232
249
|
: {};
|
|
233
250
|
}
|
|
251
|
+
getAvailableDigitalCardSKUs(detail) {
|
|
252
|
+
const digitalCardOption = this.optionsData.find(({ type }) => type === 'digital-code-value');
|
|
253
|
+
if (!digitalCardOption)
|
|
254
|
+
throw new Error('product-options:: No digital card options found');
|
|
255
|
+
const outofStockSKUs = Object.keys(detail.skus_availability).filter(key => detail.skus_availability[key] === false);
|
|
256
|
+
this.availableDigitalCardValues = digitalCardOption.details.filter((op) => {
|
|
257
|
+
return !Object.keys(op.skus_availability).filter(SKU_key => outofStockSKUs.includes(SKU_key)).length;
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
handleCountryOptionChange(event, detail) {
|
|
261
|
+
event.stopImmediatePropagation();
|
|
262
|
+
this.ignoreDefaultCardValue = true;
|
|
263
|
+
const currentCardValue = this.host.querySelector("input[data-code-value]:checked");
|
|
264
|
+
if (currentCardValue)
|
|
265
|
+
currentCardValue.checked = false;
|
|
266
|
+
const digitalCardOption = this.optionsData.find(({ type }) => type === 'digital-code-value');
|
|
267
|
+
if (!digitalCardOption)
|
|
268
|
+
throw new Error('product-options:: No digital card options found');
|
|
269
|
+
this.getAvailableDigitalCardSKUs(detail);
|
|
270
|
+
}
|
|
271
|
+
getSelectedDigitalCardOptions(option) {
|
|
272
|
+
const selectedOption = option.details.find(detail => detail.is_selected);
|
|
273
|
+
const defaultOption = option.details.find(detail => !!detail.is_default) || option.details[0]; /*option.details[0] only applys for counrty options*/
|
|
274
|
+
if (!['digital-code-value', 'country'].includes(option.type))
|
|
275
|
+
return;
|
|
276
|
+
return selectedOption || defaultOption;
|
|
277
|
+
}
|
|
234
278
|
//we need the cart Id for productOption Image
|
|
235
279
|
componentWillLoad() {
|
|
280
|
+
const shouldSelectDefaultOption = this.optionsData.filter(({ type }) => ["country", "digital-card-value"].includes(type)).length > 0 && salla.url.is_page('cart');
|
|
281
|
+
if (shouldSelectDefaultOption) {
|
|
282
|
+
const countryOption = this.optionsData.find(option => option.type === 'country');
|
|
283
|
+
const defaultSelection = countryOption && this.getSelectedDigitalCardOptions(countryOption);
|
|
284
|
+
if (defaultSelection) {
|
|
285
|
+
this.getAvailableDigitalCardSKUs(defaultSelection);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
236
288
|
this.outOfStockText = salla.lang.get('pages.products.out_of_stock');
|
|
237
289
|
return salla.onReady(() => {
|
|
238
290
|
const needsCartId = (!salla.storage.get('cart.id') && this.optionsData.some(option => ['file', 'image'].includes(option.type)));
|
|
@@ -241,19 +293,19 @@ export class SallaProductOptions {
|
|
|
241
293
|
}
|
|
242
294
|
render() {
|
|
243
295
|
var _a;
|
|
244
|
-
if (((_a = this.optionsData) === null || _a === void 0 ? void 0 : _a.length)
|
|
296
|
+
if (((_a = this.optionsData) === null || _a === void 0 ? void 0 : _a.length) === 0) {
|
|
245
297
|
return;
|
|
246
298
|
}
|
|
247
|
-
return (h(Host, { class: "s-product-options-wrapper" }, h("salla-conditional-fields", null, this.optionsData.map((option) => h("div", Object.assign({ class: `s-product-options-option-container${option.visibility_condition ? ' hidden' : ''}`, "data-option-id": option.id }, this.getOptionShownWhen(option)), option.name
|
|
299
|
+
return (h(Host, { class: "s-product-options-wrapper" }, h("salla-conditional-fields", null, this.optionsData.map((option) => h("div", Object.assign({ key: option.id, class: `s-product-options-option-container${option.visibility_condition ? ' hidden' : ''}`, "data-option-id": option.id }, this.getOptionShownWhen(option)), option.name === 'splitter' ?
|
|
248
300
|
this.splitterOption()
|
|
249
|
-
: h("div", { class: { "s-product-options-option": true, "s-product-options-option-booking": option.type === DisplayType.BOOKING && salla.url.is_page("cart") }, "data-option-type": option.type, "data-option-required": `${option.required}` }, h("label", { htmlFor:
|
|
301
|
+
: h("div", { class: { "s-product-options-option": true, "s-product-options-option-booking": option.type === DisplayType.BOOKING && salla.url.is_page("cart") }, "data-option-type": option.type, "data-option-required": `${option.required}` }, h("label", { htmlFor: `options[${option.id}]`, class: `s-product-options-option-label ${this.hideLabel(option) ? 's-product-options-option-label-hidden' : ''}` }, h("b", null, option.name, option.required && h("span", null, " * "), " "), h("small", null, option.placeholder)), h("div", { class: `s-product-options-option-content ${this.hideLabel(option) || (option.type === DisplayType.BOOKING && salla.url.is_page("cart")) ? 's-product-options-option-content-full-width' : ''}` }, this.getDisplayForType(option))))))));
|
|
250
302
|
}
|
|
251
303
|
componentDidLoad() {
|
|
252
304
|
var _a, _b;
|
|
253
|
-
if (((_a = this.optionsData) === null || _a === void 0 ? void 0 : _a.length)
|
|
305
|
+
if (((_a = this.optionsData) === null || _a === void 0 ? void 0 : _a.length) === 0 && !this.optionsData.some(option => option.type === DisplayType.DONATION)) {
|
|
254
306
|
return;
|
|
255
307
|
}
|
|
256
|
-
|
|
308
|
+
const selectedDonationOption = (_b = this.optionsData.find(option => option.type === DisplayType.DONATION)) === null || _b === void 0 ? void 0 : _b.details.find(detail => detail.is_selected);
|
|
257
309
|
if (!selectedDonationOption) {
|
|
258
310
|
return;
|
|
259
311
|
}
|
|
@@ -269,13 +321,13 @@ export class SallaProductOptions {
|
|
|
269
321
|
var _a, _b;
|
|
270
322
|
return h("div", { class: "s-product-options-donation-wrapper" }, ((_a = option.donation) === null || _a === void 0 ? void 0 : _a.can_donate) ? [
|
|
271
323
|
option.donation ?
|
|
272
|
-
h("div", { class: "s-product-options-donation-progress" }, h("salla-progress-bar", { donation: option.donation }))
|
|
324
|
+
h("div", { key: option.id, class: "s-product-options-donation-progress" }, h("salla-progress-bar", { donation: option.donation }))
|
|
273
325
|
: '',
|
|
274
326
|
option.details.length ?
|
|
275
|
-
[h("h4",
|
|
276
|
-
h("div", { class: "s-product-options-donation-options-item" }, h("input", { id:
|
|
327
|
+
[h("h4", { key: option.id }, this.selectAmount), h("div", { key: option.id, class: "s-product-options-donation-options" }, option.details.map((detail, i) => h("div", { key: option.id, class: "s-product-options-donation-options-item" }, h("input", { id: `donation-option-${i}`, type: "radio", name: "donating_option", checked: detail.is_selected, value: detail.additional_price, onChange: e => this.handleDonationOptions(e, detail, 'option') }), h("label", { htmlFor: `donation-option-${i}` }, h("span", null, salla.money(detail.name))))), ((_b = option.donation) === null || _b === void 0 ? void 0 : _b.custom_amount_enabled) ?
|
|
328
|
+
h("div", { class: "s-product-options-donation-options-item" }, h("input", { id: "donation-option-custom", type: "radio", name: "donating_option", value: "custom", onChange: e => this.handleDonationOptions(e, 'custom', 'option') }), h("label", { htmlFor: "donation-option-custom" }, h("span", null, " ", this.selectDonationAmount, " ")))
|
|
277
329
|
: '')] : '',
|
|
278
|
-
h("div", { class: { "s-product-options-donation-input-group": true, "shown": !option.details.length || (option.details.length && this.isCustomDonation) } }, h("input", { type: "text", id: "donating-amount", name: "donation_amount", class: "s-form-control", ref: el => this.donationInput = el, value: option.details.length
|
|
330
|
+
h("div", { key: option.id, class: { "s-product-options-donation-input-group": true, "shown": !option.details.length || (option.details.length && this.isCustomDonation) } }, h("input", { type: "text", id: "donating-amount", name: "donation_amount", class: "s-form-control", ref: el => { this.donationInput = el; }, value: option.details.length
|
|
279
331
|
&& option.details.some(detail => detail.is_selected)
|
|
280
332
|
? option.details.find(detail => detail.is_selected).additional_price
|
|
281
333
|
: option.value,
|
|
@@ -285,7 +337,8 @@ export class SallaProductOptions {
|
|
|
285
337
|
this.getExpireDonationMessage(option));
|
|
286
338
|
}
|
|
287
339
|
fileUploader(option, additions = null) {
|
|
288
|
-
|
|
340
|
+
var _a;
|
|
341
|
+
return h("salla-file-upload", Object.assign({}, (additions || {}), { "payload-name": "file", value: option.value, "instant-upload": true, name: `options[${option.id}]`, required: !option.visibility_condition && option.required, height: "120px", onAdded: (e) => this.changedHandler(e, option), url: salla.cart.api.getUploadImageEndpoint(), "form-data": { cart_item_id: this.productId, product_id: this.productId }, onInvalidInput: (e) => this.invalidHandler(e, option), class: { "s-product-options-image-input": true, required: option.required } }), h("div", { class: "s-product-options-filepond-placeholder" }, h("span", { class: "s-product-options-filepond-placeholder-icon", innerHTML: ((_a = additions.accept) === null || _a === void 0 ? void 0 : _a.split(',').every(type => type.includes('image')))
|
|
289
342
|
? CameraIcon
|
|
290
343
|
: FileIcon }), h("p", { class: "s-product-options-filepond-placeholder-text" }, salla.lang.get('common.uploader.drag_and_drop')), h("span", { class: "filepond--label-action" }, salla.lang.get('common.uploader.browse'))));
|
|
291
344
|
}
|
|
@@ -295,7 +348,7 @@ export class SallaProductOptions {
|
|
|
295
348
|
}
|
|
296
349
|
//@ts-ignore
|
|
297
350
|
fileOption(option) {
|
|
298
|
-
|
|
351
|
+
const types = option.details.map(detail => this.fileTypes[detail.name]).filter(Boolean);
|
|
299
352
|
return (types === null || types === void 0 ? void 0 : types.length)
|
|
300
353
|
? this.fileUploader(option, { accept: types.join(',') })
|
|
301
354
|
: 'File types not selected.';
|
|
@@ -346,7 +399,7 @@ export class SallaProductOptions {
|
|
|
346
399
|
* ============= Advanced options =============
|
|
347
400
|
*/
|
|
348
401
|
getOptionDetailName(detail, outOfStock = true, optionType) {
|
|
349
|
-
if (optionType && optionType
|
|
402
|
+
if (optionType && optionType === DisplayType.COLOR) {
|
|
350
403
|
return detail.name
|
|
351
404
|
+ ((outOfStock && this.isOptionDetailOut(detail)) ? ` <br/> <p> ${this.outOfStockText} </p>` : '')
|
|
352
405
|
+ (detail.additional_price ? ` <p> (${salla.money(detail.additional_price)}) </p>` : '');
|
|
@@ -360,15 +413,15 @@ export class SallaProductOptions {
|
|
|
360
413
|
if (detail.is_out || !detail.skus_availability || !((_a = this.selectedSkus) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
361
414
|
return detail.is_out;
|
|
362
415
|
}
|
|
363
|
-
|
|
416
|
+
const isDetailSelected = this.selectedOptions.filter(option => option.id === detail.id).length;
|
|
364
417
|
//if the current options is the only selected option, so we are sure that it's not out, because there is no other options selected yet
|
|
365
|
-
if (isDetailSelected && this.selectedOptions.length
|
|
418
|
+
if (isDetailSelected && this.selectedOptions.length === 1) {
|
|
366
419
|
return false;
|
|
367
420
|
}
|
|
368
421
|
//if current details has sku in the possible outSkus it's out for sure
|
|
369
422
|
if (isDetailSelected) {
|
|
370
423
|
//here we will get the possible outSkus for current selected options
|
|
371
|
-
|
|
424
|
+
const outSelectableSkus = this.selectedSkus.filter(sku => this.outSkus.includes(sku));
|
|
372
425
|
return Object.keys(detail.skus_availability).some(sku => outSelectableSkus.includes(Number(sku)));
|
|
373
426
|
}
|
|
374
427
|
return this.selectedOptions.some(option => option.is_out && option.option_id !== detail.option_id);
|
|
@@ -376,30 +429,46 @@ export class SallaProductOptions {
|
|
|
376
429
|
singleOption(option) {
|
|
377
430
|
return h("div", null, h("select", { name: `options[${option.id}]`, required: !option.visibility_condition && option.required, class: "s-form-control", onInvalid: (e) => this.invalidHandler(e, option), onChange: e => this.changedHandler(e, option) }, h("option", { value: "" }, option.placeholder), option === null || option === void 0 ? void 0 :
|
|
378
431
|
option.details.map((detail) => {
|
|
379
|
-
return h("option", { value: detail.id, disabled: this.canDisabled && this.isOptionDetailOut(detail), selected: detail.is_selected }, this.getOptionDetailName(detail));
|
|
432
|
+
return h("option", { key: detail.id, value: detail.id, disabled: this.canDisabled && this.isOptionDetailOut(detail), selected: detail.is_selected }, this.getOptionDetailName(detail));
|
|
380
433
|
})));
|
|
381
434
|
}
|
|
382
435
|
multipleOptions(option) {
|
|
383
|
-
|
|
436
|
+
const is_required = option.required && !option.details.some(detail => detail.is_selected) && !option.visibility_condition;
|
|
384
437
|
return h("div", { class: { "s-product-options-multiple-options-wrapper": true, 'required': option.required } }, option === null || option === void 0 ? void 0 : option.details.map((detail) => {
|
|
385
|
-
return h("div",
|
|
438
|
+
return h("div", { key: detail.id }, h("input", { type: "checkbox", value: detail.id, disabled: this.isOptionDetailOut(detail), checked: detail.is_selected, required: is_required, name: `options[${option.id}][]`, id: `field-${option.id}-${detail.id}`, onChange: (e) => this.changedHandler(e, option), onInvalid: (e) => this.invalidHandler(e, option), "aria-describedby": `options[${option.id}]-description` }), h("label", { htmlFor: `field-${option.id}-${detail.id}` }, this.getOptionDetailName(detail)));
|
|
386
439
|
}));
|
|
387
440
|
}
|
|
388
441
|
//@ts-ignore
|
|
389
442
|
colorOption(option) {
|
|
390
|
-
return h("fieldset", { class: "s-product-options-colors-wrapper" }, option === null || option === void 0 ? void 0 : option.details.map((detail) => h("div", { class: "s-product-options-colors-item" }, h("input", { type: "radio", value: detail.id, required: !option.visibility_condition && option.required, checked: detail.is_selected, name: `options[${option.id}]`, disabled: this.canDisabled && this.isOptionDetailOut(detail), id: `color-${this.productId}-${option.id}-${detail.id}`, onInvalid: (e) => this.invalidHandler(e, option), onChange: e => this.changedHandler(e, option) }), h("label", { htmlFor: `color-${this.productId}-${option.id}-${detail.id}` }, h("span", { style: { "background-color": detail.color } }), h("div", { innerHTML: this.getOptionDetailName(detail, true, option.type) })))));
|
|
443
|
+
return h("fieldset", { class: "s-product-options-colors-wrapper" }, option === null || option === void 0 ? void 0 : option.details.map((detail) => h("div", { class: "s-product-options-colors-item", key: detail.id }, h("input", { type: "radio", value: detail.id, required: !option.visibility_condition && option.required, checked: detail.is_selected, name: `options[${option.id}]`, disabled: this.canDisabled && this.isOptionDetailOut(detail), id: `color-${this.productId}-${option.id}-${detail.id}`, onInvalid: (e) => this.invalidHandler(e, option), onChange: e => this.changedHandler(e, option) }), h("label", { htmlFor: `color-${this.productId}-${option.id}-${detail.id}` }, h("span", { style: { "background-color": detail.color } }), h("div", { innerHTML: this.getOptionDetailName(detail, true, option.type) })))));
|
|
391
444
|
}
|
|
392
445
|
//@ts-ignore
|
|
393
446
|
thumbnailOption(option) {
|
|
394
447
|
return h("div", { class: "s-product-options-thumbnails-wrapper" }, option.details.map((detail) => {
|
|
395
|
-
return h("div",
|
|
448
|
+
return h("div", { key: detail.id }, h("input", { type: "radio", value: detail.id, "data-itemid": detail.id, required: !option.visibility_condition && option.required, checked: detail.is_selected, name: `options[${option.id}]`, "data-img-id": detail.option_value, disabled: this.canDisabled && this.isOptionDetailOut(detail), id: `option_${this.productId}-${option.id}_${detail.id}`, onInvalid: (e) => this.invalidHandler(e, option), onChange: (e) => this.changedHandler(e, option) }), h("label", { htmlFor: `option_${this.productId}-${option.id}_${detail.id}`, "data-img-id": detail.option_value, class: "go-to-slide" }, h("img", { "data-src": detail.image, src: detail.image, title: detail.name, alt: detail.name }), h("span", { innerHTML: CheckCircleIcon, class: "s-product-options-thumbnails-icon" }), this.isOptionDetailOut(detail) ?
|
|
396
449
|
[
|
|
397
|
-
h("small", { class: "s-product-options-thumbnails-stock-badge" }, this.outOfStockText),
|
|
398
|
-
this.canDisabled ? h("div", { class: "s-product-options-thumbnails-badge-overlay" }) : '',
|
|
450
|
+
h("small", { key: detail.id, class: "s-product-options-thumbnails-stock-badge" }, this.outOfStockText),
|
|
451
|
+
this.canDisabled ? h("div", { key: detail.id, class: "s-product-options-thumbnails-badge-overlay" }) : '',
|
|
399
452
|
]
|
|
400
453
|
: ''), h("p", null, this.getOptionDetailName(detail, false), " "));
|
|
401
454
|
}));
|
|
402
455
|
}
|
|
456
|
+
// Digital card options
|
|
457
|
+
digitalCardValuesOption(option) {
|
|
458
|
+
return h("div", { class: "s-product-options-digital-card-wrapper" }, this.availableDigitalCardValues.length > 0 ? this.availableDigitalCardValues.map((detail) => {
|
|
459
|
+
var _a, _b, _c;
|
|
460
|
+
const id = String(detail.id);
|
|
461
|
+
return h("label", { htmlFor: id, key: id, class: "s-product-options-digital-card-option" }, h("input", { type: "radio", "data-code-value": true, class: "s-form-control s-product-options-digital-card-input", value: detail.id, name: `options[${option.id}]`, id: id, required: !option.visibility_condition && option.required, onInvalid: (e) => this.invalidHandler(e, option), checked: !this.ignoreDefaultCardValue && ((_a = this.getSelectedDigitalCardOptions(option)) === null || _a === void 0 ? void 0 : _a.id) === detail.id }), h("span", null, detail.name, " ", (_c = (_b = salla.config) === null || _b === void 0 ? void 0 : _b.currency()) === null || _c === void 0 ? void 0 :
|
|
462
|
+
_c.symbol));
|
|
463
|
+
})
|
|
464
|
+
: h("div", { class: "s-product-options-digital-card-out-of-stock" }, this.outOfStockText));
|
|
465
|
+
}
|
|
466
|
+
countryOption(option) {
|
|
467
|
+
return h("div", { class: "s-product-options-digital-card-wrapper" }, option.details.map((detail) => {
|
|
468
|
+
var _a;
|
|
469
|
+
return (h("label", { htmlFor: String(detail.id), key: detail.id, class: "s-product-options-digital-card-option" }, h("input", { id: String(detail.id), type: "radio", class: "s-form-control s-product-options-digital-card-input", value: detail.id, name: `options[${option.id}]`, required: !option.visibility_condition && option.required, onInvalid: (e) => this.invalidHandler(e, option), onChange: e => this.changedHandler(e, option), checked: ((_a = this.getSelectedDigitalCardOptions(option)) === null || _a === void 0 ? void 0 : _a.id) === detail.id && salla.url.is_page('cart') }), h("div", { class: "s-product-options-country-flag-wrapper" }, h("div", { class: `s-product-options-country-flag flag iti__flag iti__${String(detail.code).toLocaleLowerCase()}` })), h("span", null, detail.name)));
|
|
470
|
+
}));
|
|
471
|
+
}
|
|
403
472
|
static get is() { return "salla-product-options"; }
|
|
404
473
|
static get originalStyleUrls() {
|
|
405
474
|
return {
|
|
@@ -461,7 +530,8 @@ export class SallaProductOptions {
|
|
|
461
530
|
"selectedOptions": {},
|
|
462
531
|
"canDisabled": {},
|
|
463
532
|
"selectedSkus": {},
|
|
464
|
-
"selectedOutSkus": {}
|
|
533
|
+
"selectedOutSkus": {},
|
|
534
|
+
"availableDigitalCardValues": {}
|
|
465
535
|
};
|
|
466
536
|
}
|
|
467
537
|
static get events() {
|
|
@@ -492,6 +562,14 @@ export class SallaProductOptions {
|
|
|
492
562
|
"Promise": {
|
|
493
563
|
"location": "global",
|
|
494
564
|
"id": "global::Promise"
|
|
565
|
+
},
|
|
566
|
+
"HTMLElement": {
|
|
567
|
+
"location": "global",
|
|
568
|
+
"id": "global::HTMLElement"
|
|
569
|
+
},
|
|
570
|
+
"FormData": {
|
|
571
|
+
"location": "global",
|
|
572
|
+
"id": "global::FormData"
|
|
495
573
|
}
|
|
496
574
|
},
|
|
497
575
|
"return": "Promise<{}>"
|