@salla.sa/twilight-components 2.13.94 → 2.13.96
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-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-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-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-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-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-84bf4247.entry.js +5 -0
- package/dist/twilight/p-84bf4247.entry.js.map +1 -0
- package/dist/twilight/p-903962d6.system.entry.js.map +1 -1
- package/dist/twilight/p-c612fde8.entry.js.map +1 -1
- package/dist/twilight/p-d5b85f12.system.entry.js +5 -0
- package/dist/twilight/p-d5b85f12.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-product-options/interfaces.d.ts +5 -0
- package/dist/types/components/salla-product-options/salla-product-options.d.ts +14 -3
- package/dist/types/global.d.ts +20 -0
- 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-e057192c.entry.js +0 -5
- package/dist/twilight/p-e057192c.entry.js.map +0 -1
|
@@ -19,6 +19,8 @@ var DisplayType;
|
|
|
19
19
|
DisplayType["MULTIPLE_OPTIONS"] = "multiple-options";
|
|
20
20
|
DisplayType["NUMBER"] = "number";
|
|
21
21
|
DisplayType["SINGLE_OPTION"] = "single-option";
|
|
22
|
+
DisplayType["DIGITAL_CARD_VALUE"] = "digital-code-value";
|
|
23
|
+
DisplayType["COUNTRY"] = "country";
|
|
22
24
|
DisplayType["SPLITTER"] = "splitter";
|
|
23
25
|
DisplayType["TEXT"] = "text";
|
|
24
26
|
DisplayType["TEXTAREA"] = "textarea";
|
|
@@ -58,8 +60,13 @@ const SallaProductOptions = class {
|
|
|
58
60
|
txt: 'text/plain',
|
|
59
61
|
};
|
|
60
62
|
this.outSkus = [];
|
|
63
|
+
/**
|
|
64
|
+
* Avoid selection of previous default or selected card value option
|
|
65
|
+
* when switching between digital card country options for the 1st time
|
|
66
|
+
*/
|
|
67
|
+
this.ignoreDefaultCardValue = false;
|
|
61
68
|
this.handleDonationOptions = (event, detail, type) => {
|
|
62
|
-
if (detail
|
|
69
|
+
if (detail === 'custom' && type === 'input') {
|
|
63
70
|
salla.helpers.inputDigitsOnly(event.target);
|
|
64
71
|
salla.event.emit('product-options::donation-changed', {
|
|
65
72
|
id: this.productId,
|
|
@@ -78,7 +85,7 @@ const SallaProductOptions = class {
|
|
|
78
85
|
else {
|
|
79
86
|
this.donationInput.value = event.target.value;
|
|
80
87
|
}
|
|
81
|
-
if (detail
|
|
88
|
+
if (detail === 'custom') {
|
|
82
89
|
return;
|
|
83
90
|
}
|
|
84
91
|
salla.event.emit('product-options::donation-changed', {
|
|
@@ -97,11 +104,11 @@ const SallaProductOptions = class {
|
|
|
97
104
|
if (!option.donation) {
|
|
98
105
|
return;
|
|
99
106
|
}
|
|
100
|
-
|
|
107
|
+
const completed = option.donation.target_amount <= option.donation.collected_amount;
|
|
101
108
|
return index.h("div", { class: { "s-product-options-donation-message": true, "s-product-options-donation-completed": completed, "s-product-options-donation-expired": !completed } }, index.h("p", null, option.donation.target_message), index.h("span", null, completed ? salla.money(option.donation.target_amount) : ''));
|
|
102
109
|
};
|
|
103
110
|
this.optionsData = undefined;
|
|
104
|
-
this.outOfStockText =
|
|
111
|
+
this.outOfStockText = "";
|
|
105
112
|
this.donationAmount = salla.lang.get('pages.products.donation_amount');
|
|
106
113
|
this.selectDonationAmount = salla.lang.getWithDefault('pages.products.select_donation_amount', 'تحديد مبلغ التبرع');
|
|
107
114
|
this.selectAmount = salla.lang.getWithDefault('pages.products.select_amount', 'اختر المبلغ');
|
|
@@ -110,6 +117,7 @@ const SallaProductOptions = class {
|
|
|
110
117
|
this.canDisabled = undefined;
|
|
111
118
|
this.selectedSkus = undefined;
|
|
112
119
|
this.selectedOutSkus = undefined;
|
|
120
|
+
this.availableDigitalCardValues = [];
|
|
113
121
|
this.productId = salla.config.get('page.id');
|
|
114
122
|
this.options = undefined;
|
|
115
123
|
this.canDisabled = !salla.config.get('store.settings.product.notify_options_availability');
|
|
@@ -139,7 +147,7 @@ const SallaProductOptions = class {
|
|
|
139
147
|
setOptionsData(optionsData) {
|
|
140
148
|
var _a, _b;
|
|
141
149
|
this.optionsData = optionsData;
|
|
142
|
-
|
|
150
|
+
const that = this;
|
|
143
151
|
(_b = (_a = this.optionsData[0]) === null || _a === void 0 ? void 0 : _a.details) === null || _b === void 0 ? void 0 : _b.forEach(function (detail) {
|
|
144
152
|
Object.entries(detail.skus_availability || {})
|
|
145
153
|
.filter(sku => !sku[1])
|
|
@@ -150,10 +158,12 @@ const SallaProductOptions = class {
|
|
|
150
158
|
* Get the id's of the selected options.
|
|
151
159
|
* */
|
|
152
160
|
async getSelectedOptionsData() {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
formData.forEach(
|
|
156
|
-
|
|
161
|
+
const selectedOptions = {};
|
|
162
|
+
const formData = this.host.getElementSallaData();
|
|
163
|
+
formData.forEach((value, key) => {
|
|
164
|
+
if (key.startsWith('options[')) {
|
|
165
|
+
(selectedOptions[key.replace('options[', '').replace(']', '')] = value);
|
|
166
|
+
}
|
|
157
167
|
});
|
|
158
168
|
return selectedOptions;
|
|
159
169
|
}
|
|
@@ -161,7 +171,7 @@ const SallaProductOptions = class {
|
|
|
161
171
|
* Report options form validity.
|
|
162
172
|
* */
|
|
163
173
|
async reportValidity() {
|
|
164
|
-
|
|
174
|
+
const requiredElements = this.host.querySelectorAll('[required]');
|
|
165
175
|
let pass = true;
|
|
166
176
|
for (let i = 0; i < requiredElements.length; i++) {
|
|
167
177
|
//if there is only one invalid option, return false
|
|
@@ -199,24 +209,27 @@ const SallaProductOptions = class {
|
|
|
199
209
|
closestProductOption.classList.add('s-product-options-option-error');
|
|
200
210
|
}
|
|
201
211
|
changedHandler(event, option) {
|
|
202
|
-
|
|
212
|
+
const data = { event: event, option: option, detail: null };
|
|
203
213
|
if (option.details) {
|
|
204
|
-
|
|
214
|
+
const detail = option.details.find((detail) => {
|
|
205
215
|
return Number(detail.id) === Number(event.target.value);
|
|
206
216
|
});
|
|
207
217
|
data.detail = detail;
|
|
208
218
|
}
|
|
209
|
-
|
|
219
|
+
if (option.type === 'country') {
|
|
220
|
+
this.handleCountryOptionChange(event, data.detail);
|
|
221
|
+
}
|
|
222
|
+
const optionElement = event.target.closest('.s-product-options-option');
|
|
210
223
|
if (event.target.value
|
|
211
|
-
|| ((option.type
|
|
212
|
-
|| (option.type
|
|
224
|
+
|| ((option.type === DisplayType.FILE || option.type === DisplayType.IMAGE) && event.type === 'added')
|
|
225
|
+
|| (option.type === DisplayType.MAP && event.type === 'selected' && (event.target.lat && event.target.lng))) {
|
|
213
226
|
setTimeout(() => {
|
|
214
227
|
optionElement.classList.remove('s-product-options-option-error');
|
|
215
228
|
}, 200);
|
|
216
229
|
}
|
|
217
230
|
const index = this.selectedOptions.findIndex(option => option.option_id === data.option.id);
|
|
218
231
|
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 }));
|
|
219
|
-
if (option.type
|
|
232
|
+
if (option.type === DisplayType.DONATION) {
|
|
220
233
|
salla.event.emit('product-options::donation-changed', {
|
|
221
234
|
id: this.productId,
|
|
222
235
|
price: event.target.value
|
|
@@ -245,7 +258,7 @@ const SallaProductOptions = class {
|
|
|
245
258
|
}
|
|
246
259
|
getLatLng(value, type) {
|
|
247
260
|
return value
|
|
248
|
-
? value.split(',')[type
|
|
261
|
+
? value.split(',')[type === 'lat' ? 0 : 1]
|
|
249
262
|
: '';
|
|
250
263
|
}
|
|
251
264
|
getDisplayForType(option) {
|
|
@@ -261,6 +274,12 @@ const SallaProductOptions = class {
|
|
|
261
274
|
if (option.type === DisplayType.SINGLE_OPTION) {
|
|
262
275
|
return this.singleOption(option);
|
|
263
276
|
}
|
|
277
|
+
if (option.type === DisplayType.DIGITAL_CARD_VALUE) {
|
|
278
|
+
return this.digitalCardValuesOption(option);
|
|
279
|
+
}
|
|
280
|
+
if (option.type === DisplayType.COUNTRY) {
|
|
281
|
+
return this.countryOption(option);
|
|
282
|
+
}
|
|
264
283
|
if (option.type === DisplayType.BOOKING && salla.url.is_page("cart")) {
|
|
265
284
|
return index.h("salla-booking-field", { onInvalidInput: (e) => this.invalidHandler(e, option), option: option, productId: option.value });
|
|
266
285
|
}
|
|
@@ -272,8 +291,43 @@ const SallaProductOptions = class {
|
|
|
272
291
|
? { "data-show-when": `options[${option.visibility_condition.option}] ${option.visibility_condition.operator} ${option.visibility_condition.value}` }
|
|
273
292
|
: {};
|
|
274
293
|
}
|
|
294
|
+
getAvailableDigitalCardSKUs(detail) {
|
|
295
|
+
const digitalCardOption = this.optionsData.find(({ type }) => type === 'digital-code-value');
|
|
296
|
+
if (!digitalCardOption)
|
|
297
|
+
throw new Error('product-options:: No digital card options found');
|
|
298
|
+
const outofStockSKUs = Object.keys(detail.skus_availability).filter(key => detail.skus_availability[key] === false);
|
|
299
|
+
this.availableDigitalCardValues = digitalCardOption.details.filter((op) => {
|
|
300
|
+
return !Object.keys(op.skus_availability).filter(SKU_key => outofStockSKUs.includes(SKU_key)).length;
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
handleCountryOptionChange(event, detail) {
|
|
304
|
+
event.stopImmediatePropagation();
|
|
305
|
+
this.ignoreDefaultCardValue = true;
|
|
306
|
+
const currentCardValue = this.host.querySelector("input[data-code-value]:checked");
|
|
307
|
+
if (currentCardValue)
|
|
308
|
+
currentCardValue.checked = false;
|
|
309
|
+
const digitalCardOption = this.optionsData.find(({ type }) => type === 'digital-code-value');
|
|
310
|
+
if (!digitalCardOption)
|
|
311
|
+
throw new Error('product-options:: No digital card options found');
|
|
312
|
+
this.getAvailableDigitalCardSKUs(detail);
|
|
313
|
+
}
|
|
314
|
+
getSelectedDigitalCardOptions(option) {
|
|
315
|
+
const selectedOption = option.details.find(detail => detail.is_selected);
|
|
316
|
+
const defaultOption = option.details.find(detail => !!detail.is_default) || option.details[0]; /*option.details[0] only applys for counrty options*/
|
|
317
|
+
if (!['digital-code-value', 'country'].includes(option.type))
|
|
318
|
+
return;
|
|
319
|
+
return selectedOption || defaultOption;
|
|
320
|
+
}
|
|
275
321
|
//we need the cart Id for productOption Image
|
|
276
322
|
componentWillLoad() {
|
|
323
|
+
const shouldSelectDefaultOption = this.optionsData.filter(({ type }) => ["country", "digital-card-value"].includes(type)).length > 0 && salla.url.is_page('cart');
|
|
324
|
+
if (shouldSelectDefaultOption) {
|
|
325
|
+
const countryOption = this.optionsData.find(option => option.type === 'country');
|
|
326
|
+
const defaultSelection = countryOption && this.getSelectedDigitalCardOptions(countryOption);
|
|
327
|
+
if (defaultSelection) {
|
|
328
|
+
this.getAvailableDigitalCardSKUs(defaultSelection);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
277
331
|
this.outOfStockText = salla.lang.get('pages.products.out_of_stock');
|
|
278
332
|
return salla.onReady(() => {
|
|
279
333
|
const needsCartId = (!salla.storage.get('cart.id') && this.optionsData.some(option => ['file', 'image'].includes(option.type)));
|
|
@@ -282,19 +336,19 @@ const SallaProductOptions = class {
|
|
|
282
336
|
}
|
|
283
337
|
render() {
|
|
284
338
|
var _a;
|
|
285
|
-
if (((_a = this.optionsData) === null || _a === void 0 ? void 0 : _a.length)
|
|
339
|
+
if (((_a = this.optionsData) === null || _a === void 0 ? void 0 : _a.length) === 0) {
|
|
286
340
|
return;
|
|
287
341
|
}
|
|
288
|
-
return (index.h(index.Host, { class: "s-product-options-wrapper" }, index.h("salla-conditional-fields", null, this.optionsData.map((option) => index.h("div", Object.assign({ class: `s-product-options-option-container${option.visibility_condition ? ' hidden' : ''}`, "data-option-id": option.id }, this.getOptionShownWhen(option)), option.name
|
|
342
|
+
return (index.h(index.Host, { class: "s-product-options-wrapper" }, index.h("salla-conditional-fields", null, this.optionsData.map((option) => index.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' ?
|
|
289
343
|
this.splitterOption()
|
|
290
|
-
: index.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}` }, index.h("label", { htmlFor:
|
|
344
|
+
: index.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}` }, index.h("label", { htmlFor: `options[${option.id}]`, class: `s-product-options-option-label ${this.hideLabel(option) ? 's-product-options-option-label-hidden' : ''}` }, index.h("b", null, option.name, option.required && index.h("span", null, " * "), " "), index.h("small", null, option.placeholder)), index.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))))))));
|
|
291
345
|
}
|
|
292
346
|
componentDidLoad() {
|
|
293
347
|
var _a, _b;
|
|
294
|
-
if (((_a = this.optionsData) === null || _a === void 0 ? void 0 : _a.length)
|
|
348
|
+
if (((_a = this.optionsData) === null || _a === void 0 ? void 0 : _a.length) === 0 && !this.optionsData.some(option => option.type === DisplayType.DONATION)) {
|
|
295
349
|
return;
|
|
296
350
|
}
|
|
297
|
-
|
|
351
|
+
const selectedDonationOption = (_b = this.optionsData.find(option => option.type === DisplayType.DONATION)) === null || _b === void 0 ? void 0 : _b.details.find(detail => detail.is_selected);
|
|
298
352
|
if (!selectedDonationOption) {
|
|
299
353
|
return;
|
|
300
354
|
}
|
|
@@ -310,13 +364,13 @@ const SallaProductOptions = class {
|
|
|
310
364
|
var _a, _b;
|
|
311
365
|
return index.h("div", { class: "s-product-options-donation-wrapper" }, ((_a = option.donation) === null || _a === void 0 ? void 0 : _a.can_donate) ? [
|
|
312
366
|
option.donation ?
|
|
313
|
-
index.h("div", { class: "s-product-options-donation-progress" }, index.h("salla-progress-bar", { donation: option.donation }))
|
|
367
|
+
index.h("div", { key: option.id, class: "s-product-options-donation-progress" }, index.h("salla-progress-bar", { donation: option.donation }))
|
|
314
368
|
: '',
|
|
315
369
|
option.details.length ?
|
|
316
|
-
[index.h("h4",
|
|
317
|
-
index.h("div", { class: "s-product-options-donation-options-item" }, index.h("input", { id:
|
|
370
|
+
[index.h("h4", { key: option.id }, this.selectAmount), index.h("div", { key: option.id, class: "s-product-options-donation-options" }, option.details.map((detail, i) => index.h("div", { key: option.id, class: "s-product-options-donation-options-item" }, index.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') }), index.h("label", { htmlFor: `donation-option-${i}` }, index.h("span", null, salla.money(detail.name))))), ((_b = option.donation) === null || _b === void 0 ? void 0 : _b.custom_amount_enabled) ?
|
|
371
|
+
index.h("div", { class: "s-product-options-donation-options-item" }, index.h("input", { id: "donation-option-custom", type: "radio", name: "donating_option", value: "custom", onChange: e => this.handleDonationOptions(e, 'custom', 'option') }), index.h("label", { htmlFor: "donation-option-custom" }, index.h("span", null, " ", this.selectDonationAmount, " ")))
|
|
318
372
|
: '')] : '',
|
|
319
|
-
index.h("div", { class: { "s-product-options-donation-input-group": true, "shown": !option.details.length || (option.details.length && this.isCustomDonation) } }, index.h("input", { type: "text", id: "donating-amount", name: "donation_amount", class: "s-form-control", ref: el => this.donationInput = el, value: option.details.length
|
|
373
|
+
index.h("div", { key: option.id, class: { "s-product-options-donation-input-group": true, "shown": !option.details.length || (option.details.length && this.isCustomDonation) } }, index.h("input", { type: "text", id: "donating-amount", name: "donation_amount", class: "s-form-control", ref: el => { this.donationInput = el; }, value: option.details.length
|
|
320
374
|
&& option.details.some(detail => detail.is_selected)
|
|
321
375
|
? option.details.find(detail => detail.is_selected).additional_price
|
|
322
376
|
: option.value,
|
|
@@ -326,7 +380,8 @@ const SallaProductOptions = class {
|
|
|
326
380
|
this.getExpireDonationMessage(option));
|
|
327
381
|
}
|
|
328
382
|
fileUploader(option, additions = null) {
|
|
329
|
-
|
|
383
|
+
var _a;
|
|
384
|
+
return index.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 } }), index.h("div", { class: "s-product-options-filepond-placeholder" }, index.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')))
|
|
330
385
|
? camera.CameraIcon
|
|
331
386
|
: FileIcon }), index.h("p", { class: "s-product-options-filepond-placeholder-text" }, salla.lang.get('common.uploader.drag_and_drop')), index.h("span", { class: "filepond--label-action" }, salla.lang.get('common.uploader.browse'))));
|
|
332
387
|
}
|
|
@@ -336,7 +391,7 @@ const SallaProductOptions = class {
|
|
|
336
391
|
}
|
|
337
392
|
//@ts-ignore
|
|
338
393
|
fileOption(option) {
|
|
339
|
-
|
|
394
|
+
const types = option.details.map(detail => this.fileTypes[detail.name]).filter(Boolean);
|
|
340
395
|
return (types === null || types === void 0 ? void 0 : types.length)
|
|
341
396
|
? this.fileUploader(option, { accept: types.join(',') })
|
|
342
397
|
: 'File types not selected.';
|
|
@@ -387,7 +442,7 @@ const SallaProductOptions = class {
|
|
|
387
442
|
* ============= Advanced options =============
|
|
388
443
|
*/
|
|
389
444
|
getOptionDetailName(detail, outOfStock = true, optionType) {
|
|
390
|
-
if (optionType && optionType
|
|
445
|
+
if (optionType && optionType === DisplayType.COLOR) {
|
|
391
446
|
return detail.name
|
|
392
447
|
+ ((outOfStock && this.isOptionDetailOut(detail)) ? ` <br/> <p> ${this.outOfStockText} </p>` : '')
|
|
393
448
|
+ (detail.additional_price ? ` <p> (${salla.money(detail.additional_price)}) </p>` : '');
|
|
@@ -401,15 +456,15 @@ const SallaProductOptions = class {
|
|
|
401
456
|
if (detail.is_out || !detail.skus_availability || !((_a = this.selectedSkus) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
402
457
|
return detail.is_out;
|
|
403
458
|
}
|
|
404
|
-
|
|
459
|
+
const isDetailSelected = this.selectedOptions.filter(option => option.id === detail.id).length;
|
|
405
460
|
//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
|
|
406
|
-
if (isDetailSelected && this.selectedOptions.length
|
|
461
|
+
if (isDetailSelected && this.selectedOptions.length === 1) {
|
|
407
462
|
return false;
|
|
408
463
|
}
|
|
409
464
|
//if current details has sku in the possible outSkus it's out for sure
|
|
410
465
|
if (isDetailSelected) {
|
|
411
466
|
//here we will get the possible outSkus for current selected options
|
|
412
|
-
|
|
467
|
+
const outSelectableSkus = this.selectedSkus.filter(sku => this.outSkus.includes(sku));
|
|
413
468
|
return Object.keys(detail.skus_availability).some(sku => outSelectableSkus.includes(Number(sku)));
|
|
414
469
|
}
|
|
415
470
|
return this.selectedOptions.some(option => option.is_out && option.option_id !== detail.option_id);
|
|
@@ -417,30 +472,46 @@ const SallaProductOptions = class {
|
|
|
417
472
|
singleOption(option) {
|
|
418
473
|
return index.h("div", null, index.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) }, index.h("option", { value: "" }, option.placeholder), option === null || option === void 0 ? void 0 :
|
|
419
474
|
option.details.map((detail) => {
|
|
420
|
-
return index.h("option", { value: detail.id, disabled: this.canDisabled && this.isOptionDetailOut(detail), selected: detail.is_selected }, this.getOptionDetailName(detail));
|
|
475
|
+
return index.h("option", { key: detail.id, value: detail.id, disabled: this.canDisabled && this.isOptionDetailOut(detail), selected: detail.is_selected }, this.getOptionDetailName(detail));
|
|
421
476
|
})));
|
|
422
477
|
}
|
|
423
478
|
multipleOptions(option) {
|
|
424
|
-
|
|
479
|
+
const is_required = option.required && !option.details.some(detail => detail.is_selected) && !option.visibility_condition;
|
|
425
480
|
return index.h("div", { class: { "s-product-options-multiple-options-wrapper": true, 'required': option.required } }, option === null || option === void 0 ? void 0 : option.details.map((detail) => {
|
|
426
|
-
return index.h("div",
|
|
481
|
+
return index.h("div", { key: detail.id }, index.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` }), index.h("label", { htmlFor: `field-${option.id}-${detail.id}` }, this.getOptionDetailName(detail)));
|
|
427
482
|
}));
|
|
428
483
|
}
|
|
429
484
|
//@ts-ignore
|
|
430
485
|
colorOption(option) {
|
|
431
|
-
return index.h("fieldset", { class: "s-product-options-colors-wrapper" }, option === null || option === void 0 ? void 0 : option.details.map((detail) => index.h("div", { class: "s-product-options-colors-item" }, index.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) }), index.h("label", { htmlFor: `color-${this.productId}-${option.id}-${detail.id}` }, index.h("span", { style: { "background-color": detail.color } }), index.h("div", { innerHTML: this.getOptionDetailName(detail, true, option.type) })))));
|
|
486
|
+
return index.h("fieldset", { class: "s-product-options-colors-wrapper" }, option === null || option === void 0 ? void 0 : option.details.map((detail) => index.h("div", { class: "s-product-options-colors-item", key: detail.id }, index.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) }), index.h("label", { htmlFor: `color-${this.productId}-${option.id}-${detail.id}` }, index.h("span", { style: { "background-color": detail.color } }), index.h("div", { innerHTML: this.getOptionDetailName(detail, true, option.type) })))));
|
|
432
487
|
}
|
|
433
488
|
//@ts-ignore
|
|
434
489
|
thumbnailOption(option) {
|
|
435
490
|
return index.h("div", { class: "s-product-options-thumbnails-wrapper" }, option.details.map((detail) => {
|
|
436
|
-
return index.h("div",
|
|
491
|
+
return index.h("div", { key: detail.id }, index.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) }), index.h("label", { htmlFor: `option_${this.productId}-${option.id}_${detail.id}`, "data-img-id": detail.option_value, class: "go-to-slide" }, index.h("img", { "data-src": detail.image, src: detail.image, title: detail.name, alt: detail.name }), index.h("span", { innerHTML: check.CheckCircleIcon, class: "s-product-options-thumbnails-icon" }), this.isOptionDetailOut(detail) ?
|
|
437
492
|
[
|
|
438
|
-
index.h("small", { class: "s-product-options-thumbnails-stock-badge" }, this.outOfStockText),
|
|
439
|
-
this.canDisabled ? index.h("div", { class: "s-product-options-thumbnails-badge-overlay" }) : '',
|
|
493
|
+
index.h("small", { key: detail.id, class: "s-product-options-thumbnails-stock-badge" }, this.outOfStockText),
|
|
494
|
+
this.canDisabled ? index.h("div", { key: detail.id, class: "s-product-options-thumbnails-badge-overlay" }) : '',
|
|
440
495
|
]
|
|
441
496
|
: ''), index.h("p", null, this.getOptionDetailName(detail, false), " "));
|
|
442
497
|
}));
|
|
443
498
|
}
|
|
499
|
+
// Digital card options
|
|
500
|
+
digitalCardValuesOption(option) {
|
|
501
|
+
return index.h("div", { class: "s-product-options-digital-card-wrapper" }, this.availableDigitalCardValues.length > 0 ? this.availableDigitalCardValues.map((detail) => {
|
|
502
|
+
var _a, _b, _c;
|
|
503
|
+
const id = String(detail.id);
|
|
504
|
+
return index.h("label", { htmlFor: id, key: id, class: "s-product-options-digital-card-option" }, index.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 }), index.h("span", null, detail.name, " ", (_c = (_b = salla.config) === null || _b === void 0 ? void 0 : _b.currency()) === null || _c === void 0 ? void 0 :
|
|
505
|
+
_c.symbol));
|
|
506
|
+
})
|
|
507
|
+
: index.h("div", { class: "s-product-options-digital-card-out-of-stock" }));
|
|
508
|
+
}
|
|
509
|
+
countryOption(option) {
|
|
510
|
+
return index.h("div", { class: "s-product-options-digital-card-wrapper" }, option.details.map((detail) => {
|
|
511
|
+
var _a;
|
|
512
|
+
return (index.h("label", { htmlFor: String(detail.id), key: detail.id, class: { "s-product-options-digital-card-option": true, "s-product-options-digital-card-option-stock-out": detail.is_out } }, index.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') }), index.h("div", { class: "s-product-options-country-flag-wrapper" }, index.h("div", { class: `s-product-options-country-flag flag iti__flag iti__${String(detail.code).toLocaleLowerCase()}` })), index.h("span", null, detail.name)));
|
|
513
|
+
}));
|
|
514
|
+
}
|
|
444
515
|
get host() { return index.getElement(this); }
|
|
445
516
|
};
|
|
446
517
|
SallaProductOptions.style = sallaProductOptionsCss;
|