Skip to content

Commit 992f6d7

Browse files
committed
Multiple add to compare and add to wishlist
1 parent 03295b6 commit 992f6d7

2 files changed

Lines changed: 21 additions & 13 deletions

File tree

view/frontend/templates/script/component/category/add-to-compare.phtml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,17 @@ use Magento\Framework\View\Element\Template;
99
?>
1010
<script>
1111
document.addEventListener('alpine:init', () => {
12-
const forms = document.querySelectorAll('[data-js-component="LumaAddToCompare"]');
13-
if (!forms) {
12+
const elements = [...document.querySelectorAll('[data-js-component="LumaAddToCompare"]')];
13+
if (!elements) {
1414
return;
1515
}
1616

17-
console.log('add to compare');
17+
elements.forEach(element => {
18+
element.addEventListener('click', (e) => {
19+
e.preventDefault();
20+
21+
LokiDataPost(element);
22+
});
23+
})
1824
});
1925
</script>

view/frontend/templates/script/component/category/add-to-wishlist.phtml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,23 @@ use Magento\Framework\View\Element\Template;
88
?>
99
<script>
1010
document.addEventListener('alpine:init', () => {
11-
const element = document.querySelector('[data-js-component="LumaAddToWishlist"]');
12-
if (!element) {
11+
const elements = [...document.querySelectorAll('[data-js-component="LumaAddToWishlist"]')];
12+
if (!elements.length > 0) {
1313
return;
1414
}
1515

16-
element.addEventListener('click', (e) => {
17-
e.preventDefault();
16+
elements.forEach((element) => {
17+
element.addEventListener('click', (e) => {
18+
e.preventDefault();
1819

19-
const customerSection = Alpine.store('LokiLocalStorage').get('customer');
20-
if (!customerSection.fullname) {
21-
Alpine.store('LokiMessageStore').addNoticeMessage('<?= __('You need to login to use the wishlist') ?>');
22-
return;
23-
}
20+
const customerSection = Alpine.store('LokiLocalStorage').get('customer');
21+
if (!customerSection.fullname) {
22+
Alpine.store('LokiMessageStore').addNoticeMessage('<?= __('You need to login to use the wishlist') ?>');
23+
return;
24+
}
2425

25-
LokiDataPost(element);
26+
LokiDataPost(element);
27+
});
2628
})
2729
});
2830
</script>

0 commit comments

Comments
 (0)