Skip to content

Commit 07455e0

Browse files
committed
Handle add to cart of simple configurable products
Introduce possibility to handle adding to cart of configurable products on setups when swatches module is not enabled
1 parent e97626a commit 07455e0

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

lib/generate/collector/checkout.js

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,37 @@ const checkout = async (
3939

4040
// Select option for every swatch if there are any.
4141
await page.evaluate(() => {
42-
Array.from(
43-
document.querySelectorAll(
44-
'.product-options-wrapper .swatch-attribute'
45-
)
46-
).forEach((swatch) => {
42+
const swatches = document.querySelectorAll(
43+
'.product-options-wrapper .swatch-attribute'
44+
);
45+
Array.from(swatches).forEach((swatch) => {
4746
const swatchOption = swatch.querySelector(
4847
'.swatch-option:not([disabled])'
4948
);
5049
swatch.querySelector('.swatch-input').value =
5150
swatchOption.getAttribute('option-id') ||
5251
swatchOption.getAttribute('data-option-id');
5352
});
53+
54+
if (swatches.length) {
55+
return;
56+
}
57+
58+
Array.from(
59+
document.querySelectorAll(
60+
'.product-options-wrapper .super-attribute-select'
61+
)
62+
).forEach((select) => {
63+
select.value = Array.from(select.options).reduce(
64+
(selectedValue, option) => {
65+
return (
66+
selectedValue ||
67+
(option.value ? option.value : selectedValue)
68+
);
69+
},
70+
null
71+
);
72+
});
5473
});
5574

5675
await Promise.all([

0 commit comments

Comments
 (0)