File tree 3 files changed +15
-18
lines changed
templates/checkout/_partials
3 files changed +15
-18
lines changed Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ export const cart = {
42
42
displayPromo : '.display-promo' ,
43
43
promoCode : '#promo-code' ,
44
44
deleteLinkAction : 'delete-from-cart' ,
45
+ removeVoucherAction : 'remove-voucher' ,
45
46
productQuantity : '.cart__items .js-quantity-button' ,
46
47
productItem : '.cart__item' ,
47
48
removeFromCartLink : '.remove-from-cart' ,
Original file line number Diff line number Diff line change @@ -14,26 +14,22 @@ export default () => {
14
14
15
15
if ( cartSummary ) {
16
16
cartSummary . addEventListener ( 'click' , ( event : Event ) => {
17
- const target = event . target as HTMLElement ;
18
-
19
- // Check if the clicked element is a voucher code or inside one
20
- const voucher = target . closest ( Theme . selectors . cart . discountCode ) ;
21
-
22
- if ( ! voucher || ! isHTMLElement ( voucher ) ) return ;
23
-
24
- event . stopPropagation ( ) ;
17
+ const eventTarget = event . target as HTMLElement ;
18
+ const voucherTarget = eventTarget . closest ( Theme . selectors . cart . discountCode ) ;
25
19
26
- const discountInput = document . querySelector < HTMLInputElement > ( Theme . selectors . cart . discountName ) ;
27
- const promoCode = document . querySelector ( Theme . selectors . cart . promoCode ) ;
20
+ if ( voucherTarget && isHTMLElement ( voucherTarget ) ) {
21
+ const discountInput = document . querySelector < HTMLInputElement > ( Theme . selectors . cart . discountName ) ;
22
+ const promoCode = document . querySelector ( Theme . selectors . cart . promoCode ) ;
28
23
29
- if ( promoCode && discountInput ) {
30
- const formCollapser = new Collapse ( promoCode , {
31
- toggle : false ,
32
- } ) ;
24
+ if ( promoCode && discountInput ) {
25
+ const formCollapser = new Collapse ( promoCode , {
26
+ toggle : false ,
27
+ } ) ;
33
28
34
- discountInput . value = voucher . innerText ;
35
- // Show promo code field
36
- formCollapser . show ( ) ;
29
+ discountInput . value = voucherTarget . innerText ;
30
+ // Show promo code field
31
+ formCollapser . show ( ) ;
32
+ }
37
33
}
38
34
} ) ;
39
35
}
Original file line number Diff line number Diff line change 16
16
<span class =" cart-voucher__name col" >{ $voucher .name} </span >
17
17
<span class =" fw-bold" >{ $voucher .reduction_formatted} </span >
18
18
{ if isset($voucher .code) && $voucher .code !== ' ' }
19
- <form action =" { $urls .pages.cart} ?action=show" data-link -action =" remove-voucher" class =" d-flex" method =" post" >
19
+ <form action =" { $urls .pages.cart} ?action=show" data-form -action =" remove-voucher" class =" d-flex" method =" post" >
20
20
<input type =" hidden" name =" token" value =" { $static_token } " >
21
21
<input type =" hidden" name =" deleteDiscount" value =" { $voucher .id_cart_rule} " >
22
22
<button type =" submit" class =" btn btn-link ms-2" ><span ><i class =" material-icons" title =" { l s= ' Remove Voucher' d= ' Shop.Theme.Checkout' } " > ; </i ></span ></button >
You can’t perform that action at this time.
0 commit comments