@salla.sa/twilight-components 2.13.94 → 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-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-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-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/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
|
@@ -15,6 +15,8 @@ var DisplayType;
|
|
|
15
15
|
DisplayType["MULTIPLE_OPTIONS"] = "multiple-options";
|
|
16
16
|
DisplayType["NUMBER"] = "number";
|
|
17
17
|
DisplayType["SINGLE_OPTION"] = "single-option";
|
|
18
|
+
DisplayType["DIGITAL_CARD_VALUE"] = "digital-code-value";
|
|
19
|
+
DisplayType["COUNTRY"] = "country";
|
|
18
20
|
DisplayType["SPLITTER"] = "splitter";
|
|
19
21
|
DisplayType["TEXT"] = "text";
|
|
20
22
|
DisplayType["TEXTAREA"] = "textarea";
|
|
@@ -54,8 +56,13 @@ const SallaProductOptions = class {
|
|
|
54
56
|
txt: 'text/plain',
|
|
55
57
|
};
|
|
56
58
|
this.outSkus = [];
|
|
59
|
+
/**
|
|
60
|
+
* Avoid selection of previous default or selected card value option
|
|
61
|
+
* when switching between digital card country options for the 1st time
|
|
62
|
+
*/
|
|
63
|
+
this.ignoreDefaultCardValue = false;
|
|
57
64
|
this.handleDonationOptions = (event, detail, type) => {
|
|
58
|
-
if (detail
|
|
65
|
+
if (detail === 'custom' && type === 'input') {
|
|
59
66
|
salla.helpers.inputDigitsOnly(event.target);
|
|
60
67
|
salla.event.emit('product-options::donation-changed', {
|
|
61
68
|
id: this.productId,
|
|
@@ -74,7 +81,7 @@ const SallaProductOptions = class {
|
|
|
74
81
|
else {
|
|
75
82
|
this.donationInput.value = event.target.value;
|
|
76
83
|
}
|
|
77
|
-
if (detail
|
|
84
|
+
if (detail === 'custom') {
|
|
78
85
|
return;
|
|
79
86
|
}
|
|
80
87
|
salla.event.emit('product-options::donation-changed', {
|
|
@@ -93,11 +100,11 @@ const SallaProductOptions = class {
|
|
|
93
100
|
if (!option.donation) {
|
|
94
101
|
return;
|
|
95
102
|
}
|
|
96
|
-
|
|
103
|
+
const completed = option.donation.target_amount <= option.donation.collected_amount;
|
|
97
104
|
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) : ''));
|
|
98
105
|
};
|
|
99
106
|
this.optionsData = undefined;
|
|
100
|
-
this.outOfStockText =
|
|
107
|
+
this.outOfStockText = "";
|
|
101
108
|
this.donationAmount = salla.lang.get('pages.products.donation_amount');
|
|
102
109
|
this.selectDonationAmount = salla.lang.getWithDefault('pages.products.select_donation_amount', 'تحديد مبلغ التبرع');
|
|
103
110
|
this.selectAmount = salla.lang.getWithDefault('pages.products.select_amount', 'اختر المبلغ');
|
|
@@ -106,6 +113,7 @@ const SallaProductOptions = class {
|
|
|
106
113
|
this.canDisabled = undefined;
|
|
107
114
|
this.selectedSkus = undefined;
|
|
108
115
|
this.selectedOutSkus = undefined;
|
|
116
|
+
this.availableDigitalCardValues = [];
|
|
109
117
|
this.productId = salla.config.get('page.id');
|
|
110
118
|
this.options = undefined;
|
|
111
119
|
this.canDisabled = !salla.config.get('store.settings.product.notify_options_availability');
|
|
@@ -135,7 +143,7 @@ const SallaProductOptions = class {
|
|
|
135
143
|
setOptionsData(optionsData) {
|
|
136
144
|
var _a, _b;
|
|
137
145
|
this.optionsData = optionsData;
|
|
138
|
-
|
|
146
|
+
const that = this;
|
|
139
147
|
(_b = (_a = this.optionsData[0]) === null || _a === void 0 ? void 0 : _a.details) === null || _b === void 0 ? void 0 : _b.forEach(function (detail) {
|
|
140
148
|
Object.entries(detail.skus_availability || {})
|
|
141
149
|
.filter(sku => !sku[1])
|
|
@@ -146,10 +154,12 @@ const SallaProductOptions = class {
|
|
|
146
154
|
* Get the id's of the selected options.
|
|
147
155
|
* */
|
|
148
156
|
async getSelectedOptionsData() {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
formData.forEach(
|
|
152
|
-
|
|
157
|
+
const selectedOptions = {};
|
|
158
|
+
const formData = this.host.getElementSallaData();
|
|
159
|
+
formData.forEach((value, key) => {
|
|
160
|
+
if (key.startsWith('options[')) {
|
|
161
|
+
(selectedOptions[key.replace('options[', '').replace(']', '')] = value);
|
|
162
|
+
}
|
|
153
163
|
});
|
|
154
164
|
return selectedOptions;
|
|
155
165
|
}
|
|
@@ -157,7 +167,7 @@ const SallaProductOptions = class {
|
|
|
157
167
|
* Report options form validity.
|
|
158
168
|
* */
|
|
159
169
|
async reportValidity() {
|
|
160
|
-
|
|
170
|
+
const requiredElements = this.host.querySelectorAll('[required]');
|
|
161
171
|
let pass = true;
|
|
162
172
|
for (let i = 0; i < requiredElements.length; i++) {
|
|
163
173
|
//if there is only one invalid option, return false
|
|
@@ -195,24 +205,27 @@ const SallaProductOptions = class {
|
|
|
195
205
|
closestProductOption.classList.add('s-product-options-option-error');
|
|
196
206
|
}
|
|
197
207
|
changedHandler(event, option) {
|
|
198
|
-
|
|
208
|
+
const data = { event: event, option: option, detail: null };
|
|
199
209
|
if (option.details) {
|
|
200
|
-
|
|
210
|
+
const detail = option.details.find((detail) => {
|
|
201
211
|
return Number(detail.id) === Number(event.target.value);
|
|
202
212
|
});
|
|
203
213
|
data.detail = detail;
|
|
204
214
|
}
|
|
205
|
-
|
|
215
|
+
if (option.type === 'country') {
|
|
216
|
+
this.handleCountryOptionChange(event, data.detail);
|
|
217
|
+
}
|
|
218
|
+
const optionElement = event.target.closest('.s-product-options-option');
|
|
206
219
|
if (event.target.value
|
|
207
|
-
|| ((option.type
|
|
208
|
-
|| (option.type
|
|
220
|
+
|| ((option.type === DisplayType.FILE || option.type === DisplayType.IMAGE) && event.type === 'added')
|
|
221
|
+
|| (option.type === DisplayType.MAP && event.type === 'selected' && (event.target.lat && event.target.lng))) {
|
|
209
222
|
setTimeout(() => {
|
|
210
223
|
optionElement.classList.remove('s-product-options-option-error');
|
|
211
224
|
}, 200);
|
|
212
225
|
}
|
|
213
226
|
const index = this.selectedOptions.findIndex(option => option.option_id === data.option.id);
|
|
214
227
|
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 }));
|
|
215
|
-
if (option.type
|
|
228
|
+
if (option.type === DisplayType.DONATION) {
|
|
216
229
|
salla.event.emit('product-options::donation-changed', {
|
|
217
230
|
id: this.productId,
|
|
218
231
|
price: event.target.value
|
|
@@ -241,7 +254,7 @@ const SallaProductOptions = class {
|
|
|
241
254
|
}
|
|
242
255
|
getLatLng(value, type) {
|
|
243
256
|
return value
|
|
244
|
-
? value.split(',')[type
|
|
257
|
+
? value.split(',')[type === 'lat' ? 0 : 1]
|
|
245
258
|
: '';
|
|
246
259
|
}
|
|
247
260
|
getDisplayForType(option) {
|
|
@@ -257,6 +270,12 @@ const SallaProductOptions = class {
|
|
|
257
270
|
if (option.type === DisplayType.SINGLE_OPTION) {
|
|
258
271
|
return this.singleOption(option);
|
|
259
272
|
}
|
|
273
|
+
if (option.type === DisplayType.DIGITAL_CARD_VALUE) {
|
|
274
|
+
return this.digitalCardValuesOption(option);
|
|
275
|
+
}
|
|
276
|
+
if (option.type === DisplayType.COUNTRY) {
|
|
277
|
+
return this.countryOption(option);
|
|
278
|
+
}
|
|
260
279
|
if (option.type === DisplayType.BOOKING && salla.url.is_page("cart")) {
|
|
261
280
|
return h("salla-booking-field", { onInvalidInput: (e) => this.invalidHandler(e, option), option: option, productId: option.value });
|
|
262
281
|
}
|
|
@@ -268,8 +287,43 @@ const SallaProductOptions = class {
|
|
|
268
287
|
? { "data-show-when": `options[${option.visibility_condition.option}] ${option.visibility_condition.operator} ${option.visibility_condition.value}` }
|
|
269
288
|
: {};
|
|
270
289
|
}
|
|
290
|
+
getAvailableDigitalCardSKUs(detail) {
|
|
291
|
+
const digitalCardOption = this.optionsData.find(({ type }) => type === 'digital-code-value');
|
|
292
|
+
if (!digitalCardOption)
|
|
293
|
+
throw new Error('product-options:: No digital card options found');
|
|
294
|
+
const outofStockSKUs = Object.keys(detail.skus_availability).filter(key => detail.skus_availability[key] === false);
|
|
295
|
+
this.availableDigitalCardValues = digitalCardOption.details.filter((op) => {
|
|
296
|
+
return !Object.keys(op.skus_availability).filter(SKU_key => outofStockSKUs.includes(SKU_key)).length;
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
handleCountryOptionChange(event, detail) {
|
|
300
|
+
event.stopImmediatePropagation();
|
|
301
|
+
this.ignoreDefaultCardValue = true;
|
|
302
|
+
const currentCardValue = this.host.querySelector("input[data-code-value]:checked");
|
|
303
|
+
if (currentCardValue)
|
|
304
|
+
currentCardValue.checked = false;
|
|
305
|
+
const digitalCardOption = this.optionsData.find(({ type }) => type === 'digital-code-value');
|
|
306
|
+
if (!digitalCardOption)
|
|
307
|
+
throw new Error('product-options:: No digital card options found');
|
|
308
|
+
this.getAvailableDigitalCardSKUs(detail);
|
|
309
|
+
}
|
|
310
|
+
getSelectedDigitalCardOptions(option) {
|
|
311
|
+
const selectedOption = option.details.find(detail => detail.is_selected);
|
|
312
|
+
const defaultOption = option.details.find(detail => !!detail.is_default) || option.details[0]; /*option.details[0] only applys for counrty options*/
|
|
313
|
+
if (!['digital-code-value', 'country'].includes(option.type))
|
|
314
|
+
return;
|
|
315
|
+
return selectedOption || defaultOption;
|
|
316
|
+
}
|
|
271
317
|
//we need the cart Id for productOption Image
|
|
272
318
|
componentWillLoad() {
|
|
319
|
+
const shouldSelectDefaultOption = this.optionsData.filter(({ type }) => ["country", "digital-card-value"].includes(type)).length > 0 && salla.url.is_page('cart');
|
|
320
|
+
if (shouldSelectDefaultOption) {
|
|
321
|
+
const countryOption = this.optionsData.find(option => option.type === 'country');
|
|
322
|
+
const defaultSelection = countryOption && this.getSelectedDigitalCardOptions(countryOption);
|
|
323
|
+
if (defaultSelection) {
|
|
324
|
+
this.getAvailableDigitalCardSKUs(defaultSelection);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
273
327
|
this.outOfStockText = salla.lang.get('pages.products.out_of_stock');
|
|
274
328
|
return salla.onReady(() => {
|
|
275
329
|
const needsCartId = (!salla.storage.get('cart.id') && this.optionsData.some(option => ['file', 'image'].includes(option.type)));
|
|
@@ -278,19 +332,19 @@ const SallaProductOptions = class {
|
|
|
278
332
|
}
|
|
279
333
|
render() {
|
|
280
334
|
var _a;
|
|
281
|
-
if (((_a = this.optionsData) === null || _a === void 0 ? void 0 : _a.length)
|
|
335
|
+
if (((_a = this.optionsData) === null || _a === void 0 ? void 0 : _a.length) === 0) {
|
|
282
336
|
return;
|
|
283
337
|
}
|
|
284
|
-
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
|
|
338
|
+
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' ?
|
|
285
339
|
this.splitterOption()
|
|
286
|
-
: 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:
|
|
340
|
+
: 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))))))));
|
|
287
341
|
}
|
|
288
342
|
componentDidLoad() {
|
|
289
343
|
var _a, _b;
|
|
290
|
-
if (((_a = this.optionsData) === null || _a === void 0 ? void 0 : _a.length)
|
|
344
|
+
if (((_a = this.optionsData) === null || _a === void 0 ? void 0 : _a.length) === 0 && !this.optionsData.some(option => option.type === DisplayType.DONATION)) {
|
|
291
345
|
return;
|
|
292
346
|
}
|
|
293
|
-
|
|
347
|
+
const selectedDonationOption = (_b = this.optionsData.find(option => option.type === DisplayType.DONATION)) === null || _b === void 0 ? void 0 : _b.details.find(detail => detail.is_selected);
|
|
294
348
|
if (!selectedDonationOption) {
|
|
295
349
|
return;
|
|
296
350
|
}
|
|
@@ -306,13 +360,13 @@ const SallaProductOptions = class {
|
|
|
306
360
|
var _a, _b;
|
|
307
361
|
return h("div", { class: "s-product-options-donation-wrapper" }, ((_a = option.donation) === null || _a === void 0 ? void 0 : _a.can_donate) ? [
|
|
308
362
|
option.donation ?
|
|
309
|
-
h("div", { class: "s-product-options-donation-progress" }, h("salla-progress-bar", { donation: option.donation }))
|
|
363
|
+
h("div", { key: option.id, class: "s-product-options-donation-progress" }, h("salla-progress-bar", { donation: option.donation }))
|
|
310
364
|
: '',
|
|
311
365
|
option.details.length ?
|
|
312
|
-
[h("h4",
|
|
313
|
-
h("div", { class: "s-product-options-donation-options-item" }, h("input", { id:
|
|
366
|
+
[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) ?
|
|
367
|
+
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, " ")))
|
|
314
368
|
: '')] : '',
|
|
315
|
-
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
|
|
369
|
+
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
|
|
316
370
|
&& option.details.some(detail => detail.is_selected)
|
|
317
371
|
? option.details.find(detail => detail.is_selected).additional_price
|
|
318
372
|
: option.value,
|
|
@@ -322,7 +376,8 @@ const SallaProductOptions = class {
|
|
|
322
376
|
this.getExpireDonationMessage(option));
|
|
323
377
|
}
|
|
324
378
|
fileUploader(option, additions = null) {
|
|
325
|
-
|
|
379
|
+
var _a;
|
|
380
|
+
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')))
|
|
326
381
|
? CameraIcon
|
|
327
382
|
: 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'))));
|
|
328
383
|
}
|
|
@@ -332,7 +387,7 @@ const SallaProductOptions = class {
|
|
|
332
387
|
}
|
|
333
388
|
//@ts-ignore
|
|
334
389
|
fileOption(option) {
|
|
335
|
-
|
|
390
|
+
const types = option.details.map(detail => this.fileTypes[detail.name]).filter(Boolean);
|
|
336
391
|
return (types === null || types === void 0 ? void 0 : types.length)
|
|
337
392
|
? this.fileUploader(option, { accept: types.join(',') })
|
|
338
393
|
: 'File types not selected.';
|
|
@@ -383,7 +438,7 @@ const SallaProductOptions = class {
|
|
|
383
438
|
* ============= Advanced options =============
|
|
384
439
|
*/
|
|
385
440
|
getOptionDetailName(detail, outOfStock = true, optionType) {
|
|
386
|
-
if (optionType && optionType
|
|
441
|
+
if (optionType && optionType === DisplayType.COLOR) {
|
|
387
442
|
return detail.name
|
|
388
443
|
+ ((outOfStock && this.isOptionDetailOut(detail)) ? ` <br/> <p> ${this.outOfStockText} </p>` : '')
|
|
389
444
|
+ (detail.additional_price ? ` <p> (${salla.money(detail.additional_price)}) </p>` : '');
|
|
@@ -397,15 +452,15 @@ const SallaProductOptions = class {
|
|
|
397
452
|
if (detail.is_out || !detail.skus_availability || !((_a = this.selectedSkus) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
398
453
|
return detail.is_out;
|
|
399
454
|
}
|
|
400
|
-
|
|
455
|
+
const isDetailSelected = this.selectedOptions.filter(option => option.id === detail.id).length;
|
|
401
456
|
//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
|
|
402
|
-
if (isDetailSelected && this.selectedOptions.length
|
|
457
|
+
if (isDetailSelected && this.selectedOptions.length === 1) {
|
|
403
458
|
return false;
|
|
404
459
|
}
|
|
405
460
|
//if current details has sku in the possible outSkus it's out for sure
|
|
406
461
|
if (isDetailSelected) {
|
|
407
462
|
//here we will get the possible outSkus for current selected options
|
|
408
|
-
|
|
463
|
+
const outSelectableSkus = this.selectedSkus.filter(sku => this.outSkus.includes(sku));
|
|
409
464
|
return Object.keys(detail.skus_availability).some(sku => outSelectableSkus.includes(Number(sku)));
|
|
410
465
|
}
|
|
411
466
|
return this.selectedOptions.some(option => option.is_out && option.option_id !== detail.option_id);
|
|
@@ -413,30 +468,46 @@ const SallaProductOptions = class {
|
|
|
413
468
|
singleOption(option) {
|
|
414
469
|
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 :
|
|
415
470
|
option.details.map((detail) => {
|
|
416
|
-
return h("option", { value: detail.id, disabled: this.canDisabled && this.isOptionDetailOut(detail), selected: detail.is_selected }, this.getOptionDetailName(detail));
|
|
471
|
+
return h("option", { key: detail.id, value: detail.id, disabled: this.canDisabled && this.isOptionDetailOut(detail), selected: detail.is_selected }, this.getOptionDetailName(detail));
|
|
417
472
|
})));
|
|
418
473
|
}
|
|
419
474
|
multipleOptions(option) {
|
|
420
|
-
|
|
475
|
+
const is_required = option.required && !option.details.some(detail => detail.is_selected) && !option.visibility_condition;
|
|
421
476
|
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) => {
|
|
422
|
-
return h("div",
|
|
477
|
+
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)));
|
|
423
478
|
}));
|
|
424
479
|
}
|
|
425
480
|
//@ts-ignore
|
|
426
481
|
colorOption(option) {
|
|
427
|
-
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) })))));
|
|
482
|
+
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) })))));
|
|
428
483
|
}
|
|
429
484
|
//@ts-ignore
|
|
430
485
|
thumbnailOption(option) {
|
|
431
486
|
return h("div", { class: "s-product-options-thumbnails-wrapper" }, option.details.map((detail) => {
|
|
432
|
-
return h("div",
|
|
487
|
+
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) ?
|
|
433
488
|
[
|
|
434
|
-
h("small", { class: "s-product-options-thumbnails-stock-badge" }, this.outOfStockText),
|
|
435
|
-
this.canDisabled ? h("div", { class: "s-product-options-thumbnails-badge-overlay" }) : '',
|
|
489
|
+
h("small", { key: detail.id, class: "s-product-options-thumbnails-stock-badge" }, this.outOfStockText),
|
|
490
|
+
this.canDisabled ? h("div", { key: detail.id, class: "s-product-options-thumbnails-badge-overlay" }) : '',
|
|
436
491
|
]
|
|
437
492
|
: ''), h("p", null, this.getOptionDetailName(detail, false), " "));
|
|
438
493
|
}));
|
|
439
494
|
}
|
|
495
|
+
// Digital card options
|
|
496
|
+
digitalCardValuesOption(option) {
|
|
497
|
+
return h("div", { class: "s-product-options-digital-card-wrapper" }, this.availableDigitalCardValues.length > 0 ? this.availableDigitalCardValues.map((detail) => {
|
|
498
|
+
var _a, _b, _c;
|
|
499
|
+
const id = String(detail.id);
|
|
500
|
+
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 :
|
|
501
|
+
_c.symbol));
|
|
502
|
+
})
|
|
503
|
+
: h("div", { class: "s-product-options-digital-card-out-of-stock" }, this.outOfStockText));
|
|
504
|
+
}
|
|
505
|
+
countryOption(option) {
|
|
506
|
+
return h("div", { class: "s-product-options-digital-card-wrapper" }, option.details.map((detail) => {
|
|
507
|
+
var _a;
|
|
508
|
+
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)));
|
|
509
|
+
}));
|
|
510
|
+
}
|
|
440
511
|
get host() { return getElement(this); }
|
|
441
512
|
};
|
|
442
513
|
SallaProductOptions.style = sallaProductOptionsCss;
|