|
1 | 1 | export const products = {
|
2 |
| - |
| 2 | + |
3 | 3 | // Update page when variant selection changes
|
4 | 4 | handleProductFormChange (
|
5 | 5 | enableUrlParameters: boolean,
|
@@ -37,6 +37,40 @@ export const products = {
|
37 | 37 |
|
38 | 38 | },
|
39 | 39 |
|
| 40 | + // If using combined listing this loads and sets title, description and images switching between products |
| 41 | + async handleCombinedListing ( |
| 42 | + productURL: string, |
| 43 | + sectionId: string |
| 44 | + ) { |
| 45 | + |
| 46 | + // load product section with Section Render API |
| 47 | + try { |
| 48 | + const response = await fetch( |
| 49 | + `${productURL}?section_id=${sectionId}` |
| 50 | + ); |
| 51 | + |
| 52 | + // If response is not OK, throw an error |
| 53 | + if (!response.ok) { |
| 54 | + throw new Error(`HTTP error! status: ${response.status}`); |
| 55 | + } |
| 56 | + // Catpure data from fetch |
| 57 | + const responseHtml = await response.text(); |
| 58 | + const html = new DOMParser().parseFromString(responseHtml, 'text/html'); |
| 59 | + |
| 60 | + // inject new html |
| 61 | + const oldSection = document.querySelector('.js-product') |
| 62 | + if(oldSection) { |
| 63 | + const newSection = html.querySelector('.js-product'); |
| 64 | + oldSection.parentNode!.insertBefore(newSection!, oldSection); |
| 65 | + oldSection.remove(); |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + catch (error) { |
| 70 | + console.error(error); |
| 71 | + } |
| 72 | + }, |
| 73 | + |
40 | 74 | // Find options that are not available based on selected options
|
41 | 75 | setUnavailableOptions() {
|
42 | 76 |
|
@@ -291,9 +325,6 @@ export const products = {
|
291 | 325 | (optionsSize === 1 && this.option1) ||
|
292 | 326 | (optionsSize === 2 && this.option1 && this.option2) ||
|
293 | 327 | (optionsSize === 3 && this.option1 && this.option2 && this.option3);
|
294 |
| - if(optionsSize === 1) { |
295 |
| - this.all_options_selected = true; |
296 |
| - } |
297 | 328 | },
|
298 | 329 |
|
299 | 330 | // Update order of product gallery images
|
|
0 commit comments