@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
|
@@ -25,6 +25,8 @@ var DisplayType;
|
|
|
25
25
|
DisplayType["MULTIPLE_OPTIONS"] = "multiple-options";
|
|
26
26
|
DisplayType["NUMBER"] = "number";
|
|
27
27
|
DisplayType["SINGLE_OPTION"] = "single-option";
|
|
28
|
+
DisplayType["DIGITAL_CARD_VALUE"] = "digital-code-value";
|
|
29
|
+
DisplayType["COUNTRY"] = "country";
|
|
28
30
|
DisplayType["SPLITTER"] = "splitter";
|
|
29
31
|
DisplayType["TEXT"] = "text";
|
|
30
32
|
DisplayType["TEXTAREA"] = "textarea";
|
|
@@ -65,8 +67,13 @@ const SallaProductOptions$1 = /*@__PURE__*/ proxyCustomElement(class SallaProduc
|
|
|
65
67
|
txt: 'text/plain',
|
|
66
68
|
};
|
|
67
69
|
this.outSkus = [];
|
|
70
|
+
/**
|
|
71
|
+
* Avoid selection of previous default or selected card value option
|
|
72
|
+
* when switching between digital card country options for the 1st time
|
|
73
|
+
*/
|
|
74
|
+
this.ignoreDefaultCardValue = false;
|
|
68
75
|
this.handleDonationOptions = (event, detail, type) => {
|
|
69
|
-
if (detail
|
|
76
|
+
if (detail === 'custom' && type === 'input') {
|
|
70
77
|
salla.helpers.inputDigitsOnly(event.target);
|
|
71
78
|
salla.event.emit('product-options::donation-changed', {
|
|
72
79
|
id: this.productId,
|
|
@@ -85,7 +92,7 @@ const SallaProductOptions$1 = /*@__PURE__*/ proxyCustomElement(class SallaProduc
|
|
|
85
92
|
else {
|
|
86
93
|
this.donationInput.value = event.target.value;
|
|
87
94
|
}
|
|
88
|
-
if (detail
|
|
95
|
+
if (detail === 'custom') {
|
|
89
96
|
return;
|
|
90
97
|
}
|
|
91
98
|
salla.event.emit('product-options::donation-changed', {
|
|
@@ -104,11 +111,11 @@ const SallaProductOptions$1 = /*@__PURE__*/ proxyCustomElement(class SallaProduc
|
|
|
104
111
|
if (!option.donation) {
|
|
105
112
|
return;
|
|
106
113
|
}
|
|
107
|
-
|
|
114
|
+
const completed = option.donation.target_amount <= option.donation.collected_amount;
|
|
108
115
|
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) : ''));
|
|
109
116
|
};
|
|
110
117
|
this.optionsData = undefined;
|
|
111
|
-
this.outOfStockText =
|
|
118
|
+
this.outOfStockText = "";
|
|
112
119
|
this.donationAmount = salla.lang.get('pages.products.donation_amount');
|
|
113
120
|
this.selectDonationAmount = salla.lang.getWithDefault('pages.products.select_donation_amount', 'تحديد مبلغ التبرع');
|
|
114
121
|
this.selectAmount = salla.lang.getWithDefault('pages.products.select_amount', 'اختر المبلغ');
|
|
@@ -117,6 +124,7 @@ const SallaProductOptions$1 = /*@__PURE__*/ proxyCustomElement(class SallaProduc
|
|
|
117
124
|
this.canDisabled = undefined;
|
|
118
125
|
this.selectedSkus = undefined;
|
|
119
126
|
this.selectedOutSkus = undefined;
|
|
127
|
+
this.availableDigitalCardValues = [];
|
|
120
128
|
this.productId = salla.config.get('page.id');
|
|
121
129
|
this.options = undefined;
|
|
122
130
|
this.canDisabled = !salla.config.get('store.settings.product.notify_options_availability');
|
|
@@ -146,7 +154,7 @@ const SallaProductOptions$1 = /*@__PURE__*/ proxyCustomElement(class SallaProduc
|
|
|
146
154
|
setOptionsData(optionsData) {
|
|
147
155
|
var _a, _b;
|
|
148
156
|
this.optionsData = optionsData;
|
|
149
|
-
|
|
157
|
+
const that = this;
|
|
150
158
|
(_b = (_a = this.optionsData[0]) === null || _a === void 0 ? void 0 : _a.details) === null || _b === void 0 ? void 0 : _b.forEach(function (detail) {
|
|
151
159
|
Object.entries(detail.skus_availability || {})
|
|
152
160
|
.filter(sku => !sku[1])
|
|
@@ -157,10 +165,12 @@ const SallaProductOptions$1 = /*@__PURE__*/ proxyCustomElement(class SallaProduc
|
|
|
157
165
|
* Get the id's of the selected options.
|
|
158
166
|
* */
|
|
159
167
|
async getSelectedOptionsData() {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
formData.forEach(
|
|
163
|
-
|
|
168
|
+
const selectedOptions = {};
|
|
169
|
+
const formData = this.host.getElementSallaData();
|
|
170
|
+
formData.forEach((value, key) => {
|
|
171
|
+
if (key.startsWith('options[')) {
|
|
172
|
+
(selectedOptions[key.replace('options[', '').replace(']', '')] = value);
|
|
173
|
+
}
|
|
164
174
|
});
|
|
165
175
|
return selectedOptions;
|
|
166
176
|
}
|
|
@@ -168,7 +178,7 @@ const SallaProductOptions$1 = /*@__PURE__*/ proxyCustomElement(class SallaProduc
|
|
|
168
178
|
* Report options form validity.
|
|
169
179
|
* */
|
|
170
180
|
async reportValidity() {
|
|
171
|
-
|
|
181
|
+
const requiredElements = this.host.querySelectorAll('[required]');
|
|
172
182
|
let pass = true;
|
|
173
183
|
for (let i = 0; i < requiredElements.length; i++) {
|
|
174
184
|
//if there is only one invalid option, return false
|
|
@@ -206,24 +216,27 @@ const SallaProductOptions$1 = /*@__PURE__*/ proxyCustomElement(class SallaProduc
|
|
|
206
216
|
closestProductOption.classList.add('s-product-options-option-error');
|
|
207
217
|
}
|
|
208
218
|
changedHandler(event, option) {
|
|
209
|
-
|
|
219
|
+
const data = { event: event, option: option, detail: null };
|
|
210
220
|
if (option.details) {
|
|
211
|
-
|
|
221
|
+
const detail = option.details.find((detail) => {
|
|
212
222
|
return Number(detail.id) === Number(event.target.value);
|
|
213
223
|
});
|
|
214
224
|
data.detail = detail;
|
|
215
225
|
}
|
|
216
|
-
|
|
226
|
+
if (option.type === 'country') {
|
|
227
|
+
this.handleCountryOptionChange(event, data.detail);
|
|
228
|
+
}
|
|
229
|
+
const optionElement = event.target.closest('.s-product-options-option');
|
|
217
230
|
if (event.target.value
|
|
218
|
-
|| ((option.type
|
|
219
|
-
|| (option.type
|
|
231
|
+
|| ((option.type === DisplayType.FILE || option.type === DisplayType.IMAGE) && event.type === 'added')
|
|
232
|
+
|| (option.type === DisplayType.MAP && event.type === 'selected' && (event.target.lat && event.target.lng))) {
|
|
220
233
|
setTimeout(() => {
|
|
221
234
|
optionElement.classList.remove('s-product-options-option-error');
|
|
222
235
|
}, 200);
|
|
223
236
|
}
|
|
224
237
|
const index = this.selectedOptions.findIndex(option => option.option_id === data.option.id);
|
|
225
238
|
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 }));
|
|
226
|
-
if (option.type
|
|
239
|
+
if (option.type === DisplayType.DONATION) {
|
|
227
240
|
salla.event.emit('product-options::donation-changed', {
|
|
228
241
|
id: this.productId,
|
|
229
242
|
price: event.target.value
|
|
@@ -252,7 +265,7 @@ const SallaProductOptions$1 = /*@__PURE__*/ proxyCustomElement(class SallaProduc
|
|
|
252
265
|
}
|
|
253
266
|
getLatLng(value, type) {
|
|
254
267
|
return value
|
|
255
|
-
? value.split(',')[type
|
|
268
|
+
? value.split(',')[type === 'lat' ? 0 : 1]
|
|
256
269
|
: '';
|
|
257
270
|
}
|
|
258
271
|
getDisplayForType(option) {
|
|
@@ -268,6 +281,12 @@ const SallaProductOptions$1 = /*@__PURE__*/ proxyCustomElement(class SallaProduc
|
|
|
268
281
|
if (option.type === DisplayType.SINGLE_OPTION) {
|
|
269
282
|
return this.singleOption(option);
|
|
270
283
|
}
|
|
284
|
+
if (option.type === DisplayType.DIGITAL_CARD_VALUE) {
|
|
285
|
+
return this.digitalCardValuesOption(option);
|
|
286
|
+
}
|
|
287
|
+
if (option.type === DisplayType.COUNTRY) {
|
|
288
|
+
return this.countryOption(option);
|
|
289
|
+
}
|
|
271
290
|
if (option.type === DisplayType.BOOKING && salla.url.is_page("cart")) {
|
|
272
291
|
return h("salla-booking-field", { onInvalidInput: (e) => this.invalidHandler(e, option), option: option, productId: option.value });
|
|
273
292
|
}
|
|
@@ -279,8 +298,43 @@ const SallaProductOptions$1 = /*@__PURE__*/ proxyCustomElement(class SallaProduc
|
|
|
279
298
|
? { "data-show-when": `options[${option.visibility_condition.option}] ${option.visibility_condition.operator} ${option.visibility_condition.value}` }
|
|
280
299
|
: {};
|
|
281
300
|
}
|
|
301
|
+
getAvailableDigitalCardSKUs(detail) {
|
|
302
|
+
const digitalCardOption = this.optionsData.find(({ type }) => type === 'digital-code-value');
|
|
303
|
+
if (!digitalCardOption)
|
|
304
|
+
throw new Error('product-options:: No digital card options found');
|
|
305
|
+
const outofStockSKUs = Object.keys(detail.skus_availability).filter(key => detail.skus_availability[key] === false);
|
|
306
|
+
this.availableDigitalCardValues = digitalCardOption.details.filter((op) => {
|
|
307
|
+
return !Object.keys(op.skus_availability).filter(SKU_key => outofStockSKUs.includes(SKU_key)).length;
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
handleCountryOptionChange(event, detail) {
|
|
311
|
+
event.stopImmediatePropagation();
|
|
312
|
+
this.ignoreDefaultCardValue = true;
|
|
313
|
+
const currentCardValue = this.host.querySelector("input[data-code-value]:checked");
|
|
314
|
+
if (currentCardValue)
|
|
315
|
+
currentCardValue.checked = false;
|
|
316
|
+
const digitalCardOption = this.optionsData.find(({ type }) => type === 'digital-code-value');
|
|
317
|
+
if (!digitalCardOption)
|
|
318
|
+
throw new Error('product-options:: No digital card options found');
|
|
319
|
+
this.getAvailableDigitalCardSKUs(detail);
|
|
320
|
+
}
|
|
321
|
+
getSelectedDigitalCardOptions(option) {
|
|
322
|
+
const selectedOption = option.details.find(detail => detail.is_selected);
|
|
323
|
+
const defaultOption = option.details.find(detail => !!detail.is_default) || option.details[0]; /*option.details[0] only applys for counrty options*/
|
|
324
|
+
if (!['digital-code-value', 'country'].includes(option.type))
|
|
325
|
+
return;
|
|
326
|
+
return selectedOption || defaultOption;
|
|
327
|
+
}
|
|
282
328
|
//we need the cart Id for productOption Image
|
|
283
329
|
componentWillLoad() {
|
|
330
|
+
const shouldSelectDefaultOption = this.optionsData.filter(({ type }) => ["country", "digital-card-value"].includes(type)).length > 0 && salla.url.is_page('cart');
|
|
331
|
+
if (shouldSelectDefaultOption) {
|
|
332
|
+
const countryOption = this.optionsData.find(option => option.type === 'country');
|
|
333
|
+
const defaultSelection = countryOption && this.getSelectedDigitalCardOptions(countryOption);
|
|
334
|
+
if (defaultSelection) {
|
|
335
|
+
this.getAvailableDigitalCardSKUs(defaultSelection);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
284
338
|
this.outOfStockText = salla.lang.get('pages.products.out_of_stock');
|
|
285
339
|
return salla.onReady(() => {
|
|
286
340
|
const needsCartId = (!salla.storage.get('cart.id') && this.optionsData.some(option => ['file', 'image'].includes(option.type)));
|
|
@@ -289,19 +343,19 @@ const SallaProductOptions$1 = /*@__PURE__*/ proxyCustomElement(class SallaProduc
|
|
|
289
343
|
}
|
|
290
344
|
render() {
|
|
291
345
|
var _a;
|
|
292
|
-
if (((_a = this.optionsData) === null || _a === void 0 ? void 0 : _a.length)
|
|
346
|
+
if (((_a = this.optionsData) === null || _a === void 0 ? void 0 : _a.length) === 0) {
|
|
293
347
|
return;
|
|
294
348
|
}
|
|
295
|
-
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
|
|
349
|
+
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' ?
|
|
296
350
|
this.splitterOption()
|
|
297
|
-
: 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:
|
|
351
|
+
: 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))))))));
|
|
298
352
|
}
|
|
299
353
|
componentDidLoad() {
|
|
300
354
|
var _a, _b;
|
|
301
|
-
if (((_a = this.optionsData) === null || _a === void 0 ? void 0 : _a.length)
|
|
355
|
+
if (((_a = this.optionsData) === null || _a === void 0 ? void 0 : _a.length) === 0 && !this.optionsData.some(option => option.type === DisplayType.DONATION)) {
|
|
302
356
|
return;
|
|
303
357
|
}
|
|
304
|
-
|
|
358
|
+
const selectedDonationOption = (_b = this.optionsData.find(option => option.type === DisplayType.DONATION)) === null || _b === void 0 ? void 0 : _b.details.find(detail => detail.is_selected);
|
|
305
359
|
if (!selectedDonationOption) {
|
|
306
360
|
return;
|
|
307
361
|
}
|
|
@@ -317,13 +371,13 @@ const SallaProductOptions$1 = /*@__PURE__*/ proxyCustomElement(class SallaProduc
|
|
|
317
371
|
var _a, _b;
|
|
318
372
|
return h("div", { class: "s-product-options-donation-wrapper" }, ((_a = option.donation) === null || _a === void 0 ? void 0 : _a.can_donate) ? [
|
|
319
373
|
option.donation ?
|
|
320
|
-
h("div", { class: "s-product-options-donation-progress" }, h("salla-progress-bar", { donation: option.donation }))
|
|
374
|
+
h("div", { key: option.id, class: "s-product-options-donation-progress" }, h("salla-progress-bar", { donation: option.donation }))
|
|
321
375
|
: '',
|
|
322
376
|
option.details.length ?
|
|
323
|
-
[h("h4",
|
|
324
|
-
h("div", { class: "s-product-options-donation-options-item" }, h("input", { id:
|
|
377
|
+
[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) ?
|
|
378
|
+
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, " ")))
|
|
325
379
|
: '')] : '',
|
|
326
|
-
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
|
|
380
|
+
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
|
|
327
381
|
&& option.details.some(detail => detail.is_selected)
|
|
328
382
|
? option.details.find(detail => detail.is_selected).additional_price
|
|
329
383
|
: option.value,
|
|
@@ -333,7 +387,8 @@ const SallaProductOptions$1 = /*@__PURE__*/ proxyCustomElement(class SallaProduc
|
|
|
333
387
|
this.getExpireDonationMessage(option));
|
|
334
388
|
}
|
|
335
389
|
fileUploader(option, additions = null) {
|
|
336
|
-
|
|
390
|
+
var _a;
|
|
391
|
+
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')))
|
|
337
392
|
? CameraIcon
|
|
338
393
|
: 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'))));
|
|
339
394
|
}
|
|
@@ -343,7 +398,7 @@ const SallaProductOptions$1 = /*@__PURE__*/ proxyCustomElement(class SallaProduc
|
|
|
343
398
|
}
|
|
344
399
|
//@ts-ignore
|
|
345
400
|
fileOption(option) {
|
|
346
|
-
|
|
401
|
+
const types = option.details.map(detail => this.fileTypes[detail.name]).filter(Boolean);
|
|
347
402
|
return (types === null || types === void 0 ? void 0 : types.length)
|
|
348
403
|
? this.fileUploader(option, { accept: types.join(',') })
|
|
349
404
|
: 'File types not selected.';
|
|
@@ -394,7 +449,7 @@ const SallaProductOptions$1 = /*@__PURE__*/ proxyCustomElement(class SallaProduc
|
|
|
394
449
|
* ============= Advanced options =============
|
|
395
450
|
*/
|
|
396
451
|
getOptionDetailName(detail, outOfStock = true, optionType) {
|
|
397
|
-
if (optionType && optionType
|
|
452
|
+
if (optionType && optionType === DisplayType.COLOR) {
|
|
398
453
|
return detail.name
|
|
399
454
|
+ ((outOfStock && this.isOptionDetailOut(detail)) ? ` <br/> <p> ${this.outOfStockText} </p>` : '')
|
|
400
455
|
+ (detail.additional_price ? ` <p> (${salla.money(detail.additional_price)}) </p>` : '');
|
|
@@ -408,15 +463,15 @@ const SallaProductOptions$1 = /*@__PURE__*/ proxyCustomElement(class SallaProduc
|
|
|
408
463
|
if (detail.is_out || !detail.skus_availability || !((_a = this.selectedSkus) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
409
464
|
return detail.is_out;
|
|
410
465
|
}
|
|
411
|
-
|
|
466
|
+
const isDetailSelected = this.selectedOptions.filter(option => option.id === detail.id).length;
|
|
412
467
|
//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
|
|
413
|
-
if (isDetailSelected && this.selectedOptions.length
|
|
468
|
+
if (isDetailSelected && this.selectedOptions.length === 1) {
|
|
414
469
|
return false;
|
|
415
470
|
}
|
|
416
471
|
//if current details has sku in the possible outSkus it's out for sure
|
|
417
472
|
if (isDetailSelected) {
|
|
418
473
|
//here we will get the possible outSkus for current selected options
|
|
419
|
-
|
|
474
|
+
const outSelectableSkus = this.selectedSkus.filter(sku => this.outSkus.includes(sku));
|
|
420
475
|
return Object.keys(detail.skus_availability).some(sku => outSelectableSkus.includes(Number(sku)));
|
|
421
476
|
}
|
|
422
477
|
return this.selectedOptions.some(option => option.is_out && option.option_id !== detail.option_id);
|
|
@@ -424,30 +479,46 @@ const SallaProductOptions$1 = /*@__PURE__*/ proxyCustomElement(class SallaProduc
|
|
|
424
479
|
singleOption(option) {
|
|
425
480
|
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 :
|
|
426
481
|
option.details.map((detail) => {
|
|
427
|
-
return h("option", { value: detail.id, disabled: this.canDisabled && this.isOptionDetailOut(detail), selected: detail.is_selected }, this.getOptionDetailName(detail));
|
|
482
|
+
return h("option", { key: detail.id, value: detail.id, disabled: this.canDisabled && this.isOptionDetailOut(detail), selected: detail.is_selected }, this.getOptionDetailName(detail));
|
|
428
483
|
})));
|
|
429
484
|
}
|
|
430
485
|
multipleOptions(option) {
|
|
431
|
-
|
|
486
|
+
const is_required = option.required && !option.details.some(detail => detail.is_selected) && !option.visibility_condition;
|
|
432
487
|
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) => {
|
|
433
|
-
return h("div",
|
|
488
|
+
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)));
|
|
434
489
|
}));
|
|
435
490
|
}
|
|
436
491
|
//@ts-ignore
|
|
437
492
|
colorOption(option) {
|
|
438
|
-
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) })))));
|
|
493
|
+
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) })))));
|
|
439
494
|
}
|
|
440
495
|
//@ts-ignore
|
|
441
496
|
thumbnailOption(option) {
|
|
442
497
|
return h("div", { class: "s-product-options-thumbnails-wrapper" }, option.details.map((detail) => {
|
|
443
|
-
return h("div",
|
|
498
|
+
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) ?
|
|
444
499
|
[
|
|
445
|
-
h("small", { class: "s-product-options-thumbnails-stock-badge" }, this.outOfStockText),
|
|
446
|
-
this.canDisabled ? h("div", { class: "s-product-options-thumbnails-badge-overlay" }) : '',
|
|
500
|
+
h("small", { key: detail.id, class: "s-product-options-thumbnails-stock-badge" }, this.outOfStockText),
|
|
501
|
+
this.canDisabled ? h("div", { key: detail.id, class: "s-product-options-thumbnails-badge-overlay" }) : '',
|
|
447
502
|
]
|
|
448
503
|
: ''), h("p", null, this.getOptionDetailName(detail, false), " "));
|
|
449
504
|
}));
|
|
450
505
|
}
|
|
506
|
+
// Digital card options
|
|
507
|
+
digitalCardValuesOption(option) {
|
|
508
|
+
return h("div", { class: "s-product-options-digital-card-wrapper" }, this.availableDigitalCardValues.length > 0 ? this.availableDigitalCardValues.map((detail) => {
|
|
509
|
+
var _a, _b, _c;
|
|
510
|
+
const id = String(detail.id);
|
|
511
|
+
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 :
|
|
512
|
+
_c.symbol));
|
|
513
|
+
})
|
|
514
|
+
: h("div", { class: "s-product-options-digital-card-out-of-stock" }));
|
|
515
|
+
}
|
|
516
|
+
countryOption(option) {
|
|
517
|
+
return h("div", { class: "s-product-options-digital-card-wrapper" }, option.details.map((detail) => {
|
|
518
|
+
var _a;
|
|
519
|
+
return (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 } }, 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)));
|
|
520
|
+
}));
|
|
521
|
+
}
|
|
451
522
|
get host() { return this; }
|
|
452
523
|
static get style() { return sallaProductOptionsCss; }
|
|
453
524
|
}, [0, "salla-product-options", {
|
|
@@ -463,6 +534,7 @@ const SallaProductOptions$1 = /*@__PURE__*/ proxyCustomElement(class SallaProduc
|
|
|
463
534
|
"canDisabled": [32],
|
|
464
535
|
"selectedSkus": [32],
|
|
465
536
|
"selectedOutSkus": [32],
|
|
537
|
+
"availableDigitalCardValues": [32],
|
|
466
538
|
"getSelectedOptionsData": [64],
|
|
467
539
|
"reportValidity": [64],
|
|
468
540
|
"hasOutOfStockOption": [64],
|