@@ -27,43 +27,55 @@ export class UccCartModalElement extends UccModalElement
27
27
private _observerContext = ( ) => {
28
28
this . _context . config . subscribe ( ( config : CartConfig ) => {
29
29
if ( config ) {
30
+
30
31
this . setTitle ( config . locales ! [ config . lang ] . cart_title ) ;
31
32
this . setCloseButtonLabel ( config . locales ! [ config . lang ] . close_cart ) ;
32
-
33
+
34
+ this . _host . querySelector < HTMLElement > ( '.ucc-cart-total--subtotal .ucc-cart-total-label' ) ! . textContent = config . locales ! [ config . lang ] . subtotal ;
33
35
this . _host . querySelector < HTMLElement > ( '.ucc-cart-total--taxes .ucc-cart-total-label' ) ! . textContent = config . locales ! [ config . lang ] . taxes ;
34
- this . _host . querySelector < HTMLElement > ( '.ucc-cart-total--shipping .ucc-cart-total-label' ) ! . textContent = config . locales ! [ config . lang ] . shipping ;
35
- this . _host . querySelector < HTMLElement > ( '.ucc-cart-total--shipping .ucc-cart-total-value' ) ! . textContent = config . locales ! [ config . lang ] . shipping_message ;
36
+ this . _host . querySelector < HTMLElement > ( '.ucc-cart-message' ) ! . textContent = config . locales ! [ config . lang ] . shipping_and_discounts_message ;
36
37
this . _host . querySelector < HTMLElement > ( '.ucc-cart-total--total .ucc-cart-total-label' ) ! . textContent = config . locales ! [ config . lang ] . total ;
37
38
this . _host . querySelector < HTMLElement > ( '.ucc-cart-checkout' ) ! . textContent = config . locales ! [ config . lang ] . checkout ;
38
39
this . _host . querySelector < HTMLElement > ( '.ucc-cart-checkout' ) ! . setAttribute ( 'href' , config . checkoutUrl ! ) ;
39
40
40
- const cartItemRemoveBtns = this . _host . querySelectorAll ( '.ucc-cart-item__remove' ) ;
41
- cartItemRemoveBtns . forEach ( ( btn ) => {
42
- btn . setAttribute ( 'title' , config . locales ! [ config . lang ] . remove ) ;
43
- } ) ;
44
-
45
41
const cartEmptyMsg = this . _host . querySelector < HTMLElement > ( '.ucc-cart-empty__message' ) ;
46
42
if ( cartEmptyMsg ) {
47
43
cartEmptyMsg . textContent = config . locales ! [ config . lang ] . cart_empty ;
48
44
}
45
+
46
+ if ( config . showPricesIncludingTax ) {
47
+ this . _host . querySelector < HTMLElement > ( '.ucc-cart-totals' ) ! . classList . add ( 'ucc-cart-totals--inc-tax' ) ;
48
+ } else {
49
+ this . _host . querySelector < HTMLElement > ( '.ucc-cart-totals' ) ! . classList . remove ( 'ucc-cart-totals--inc-tax' ) ;
50
+ }
51
+
52
+ this . _renderCart ( ) ;
49
53
}
50
54
} ) ;
51
- this . _context . cart . subscribe ( ( cart : Cart ) => {
52
-
53
- const config = this . _context . config . get ( ) ! ;
54
-
55
- if ( cart && cart . items . length > 0 ) {
56
- this . _host . querySelector ( '.ucc-cart-items' ) ! . innerHTML = cart . items . map ( ( item ) => {
57
- const propsToDisplay = Object . keys ( item . properties ?? { } ) . filter ( ( x ) => ( config . properties ?? [ ] ) . map ( y => y . toLowerCase ( ) ) . includes ( x . toLowerCase ( ) ) ) ;
58
- return `
55
+ this . _context . cart . subscribe ( ( ) => {
56
+ this . _renderCart ( ) ;
57
+ } ) ;
58
+ }
59
+
60
+ private _renderCart ( )
61
+ {
62
+ const config = this . _context . config . get ( ) ;
63
+ const cart = this . _context . cart . get ( ) ;
64
+
65
+ if ( ! config || ! cart ) return ;
66
+
67
+ if ( cart && cart . items . length > 0 ) {
68
+ this . _host . querySelector ( '.ucc-cart-items' ) ! . innerHTML = cart . items . map ( ( item ) => {
69
+ const propsToDisplay = Object . keys ( item . properties ?? { } ) . filter ( ( x ) => ( config . properties ?? [ ] ) . map ( y => y . toLowerCase ( ) ) . includes ( x . toLowerCase ( ) ) ) ;
70
+ return `
59
71
<div class="ucc-cart-item" data-id="${ item . id } ">
60
72
${ item . imageUrl ? `
61
73
<figure class="ucc-cart-item__image">
62
74
<img src="${ item . imageUrl } " alt="${ item . name } ">
63
75
</figure>` : '' }
64
76
<div class="ucc-cart-item__body">
65
77
<div class="ucc-cart-item__content ucc-split">
66
- <div class="ucc-split__left">
78
+ <div class="ucc-split__left ucc-split__item--fill ">
67
79
<h3 class="ucc-cart-item__title">${ item . name } </h3>
68
80
${ item . attributes ? `
69
81
<div class="ucc-cart-item__attributes">
@@ -85,6 +97,22 @@ export class UccCartModalElement extends UccModalElement
85
97
` ) . join ( '' ) }
86
98
</div>
87
99
` : '' }
100
+ ${ item . items && item . items . length ? `
101
+ <div class="ucc-cart-item__bundle">
102
+ <div class="ucc-cart-item__bundle-item ucc-cart-item__bundle-item--base">
103
+ <span class="ucc-cart-item__bundle-item-name">${ config ?. locales ! [ config . lang ] . base_price ?? 'Base price' } </span>
104
+ <span class="ucc-cart-item__bundle-item-quantity"></span>
105
+ <span class="ucc-cart-item__bundle-item-quantity">${ config . showPricesIncludingTax ? item . basePrice . withTax : item . basePrice . withoutTax } </span>
106
+ </div>
107
+ ${ item . items . map ( ( bundleItem ) => `
108
+ <div class="ucc-cart-item__bundle-item">
109
+ <span class="ucc-cart-item__bundle-item-name">${ bundleItem . name } </span>
110
+ <span class="ucc-cart-item__bundle-item-quantity">x${ bundleItem . quantity } </span>
111
+ <span class="ucc-cart-item__bundle-item-quantity">${ config . showPricesIncludingTax ? bundleItem . total . withTax : bundleItem . total . withoutTax } </span>
112
+ </div>
113
+ ` ) . join ( '' ) }
114
+ </div>
115
+ ` : '' }
88
116
</div>
89
117
<div class="ucc-split__right">
90
118
<button class="ucc-cart-item__remove" title="${ config ?. locales ! [ config . lang ] . remove ?? 'Remove' } "><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-trash-2"><path d="M3 6h18"/><path d="M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"/><path d="M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"/><line x1="10" x2="10" y1="11" y2="17"/><line x1="14" x2="14" y1="11" y2="17"/></svg></button>
@@ -95,30 +123,32 @@ export class UccCartModalElement extends UccModalElement
95
123
<input type="number" value="${ item . quantity } " min="1" class="ucc-cart-item__quantity">
96
124
</div>
97
125
<div class="ucc-split__right">
98
- <span class="ucc-cart-item__price">${ item . total . withTax } </span>
126
+ <span class="ucc-cart-item__price">${ config . showPricesIncludingTax ? item . total . withTax : item . total . withoutTax } </span>
99
127
</div>
100
128
</div>
101
129
</div>
102
130
</div>
103
131
`
104
- } ) . join ( '' ) ;
105
- this . _host . querySelector < HTMLElement > ( '.ucc-cart-totals' ) ! . style . display = '' ;
106
- this . _host . querySelector < HTMLElement > ( '.ucc-cart-total--taxes .ucc-cart-total-value' ) ! . textContent = cart . subtotal . tax ;
107
- this . _host . querySelector < HTMLElement > ( '.ucc-cart-total--total .ucc-cart-total-value' ) ! . textContent = cart . subtotal . withTax ;
108
- this . _host . querySelector < HTMLElement > ( '.ucc-cart-checkout' ) ! . classList . remove ( 'ucc-cart-checkout--disabled' ) ;
109
- } else {
110
- this . _host . querySelector < HTMLElement > ( '.ucc-cart-items' ) ! . innerHTML = `
132
+ } ) . join ( '' ) ;
133
+ this . _host . querySelector < HTMLElement > ( '.ucc-cart-totals' ) ! . style . display = '' ;
134
+ this . _host . querySelector < HTMLElement > ( '.ucc-cart-message' ) ! . style . display = '' ;
135
+ this . _host . querySelector < HTMLElement > ( '.ucc-cart-total--subtotal .ucc-cart-total-value' ) ! . textContent = cart . subtotal . withoutTax ;
136
+ this . _host . querySelector < HTMLElement > ( '.ucc-cart-total--taxes .ucc-cart-total-value' ) ! . textContent = cart . subtotal . tax ;
137
+ this . _host . querySelector < HTMLElement > ( '.ucc-cart-total--total .ucc-cart-total-value' ) ! . textContent = cart . subtotal . withTax ;
138
+ this . _host . querySelector < HTMLElement > ( '.ucc-cart-checkout' ) ! . classList . remove ( 'ucc-cart-checkout--disabled' ) ;
139
+ } else {
140
+ this . _host . querySelector < HTMLElement > ( '.ucc-cart-items' ) ! . innerHTML = `
111
141
<div class="ucc-cart-empty">
112
142
<div>
113
143
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-shopping-cart"><circle cx="8" cy="21" r="1"/><circle cx="19" cy="21" r="1"/><path d="M2.05 2.05h2l2.66 12.42a2 2 0 0 0 2 1.58h9.78a2 2 0 0 0 1.95-1.57l1.65-7.43H5.12"/></svg>
114
144
<div class="ucc-cart-empty__message">${ config ?. locales ! [ config . lang ] . cart_empty ?? 'Your cart is empty' } </div>
115
145
</div>
116
146
</div>
117
147
` ;
118
- this . _host . querySelector < HTMLElement > ( '.ucc-cart-totals' ) ! . style . display = 'none' ;
119
- this . _host . querySelector < HTMLElement > ( '.ucc-cart-checkout ' ) ! . classList . add ( 'ucc-cart-checkout--disabled' ) ;
120
- }
121
- } ) ;
148
+ this . _host . querySelector < HTMLElement > ( '.ucc-cart-totals' ) ! . style . display = 'none' ;
149
+ this . _host . querySelector < HTMLElement > ( '.ucc-cart-message ' ) ! . style . display = 'none' ;
150
+ this . _host . querySelector < HTMLElement > ( '.ucc-cart-checkout' ) ! . classList . add ( 'ucc-cart-checkout--disabled' ) ;
151
+ }
122
152
}
123
153
124
154
private _addCartItemEventListener = ( event :string , selector :string , handler :Function ) => {
@@ -136,11 +166,11 @@ export class UccCartModalElement extends UccModalElement
136
166
` )
137
167
this . setFooter ( `
138
168
<div class="ucc-cart-totals">
139
- <div class="ucc-cart-totals__item ucc-cart-total ucc-cart-total--taxes ucc-split">
169
+ <div class="ucc-cart-totals__item ucc-cart-total ucc-cart-total--subtotal ucc-split">
140
170
<span class="ucc-cart-total-label ucc-split__left"></span>
141
171
<span class="ucc-cart-total-value ucc-split__right"></span>
142
172
</div>
143
- <div class="ucc-cart-totals__item ucc-cart-total ucc-cart-total--shipping ucc-split">
173
+ <div class="ucc-cart-totals__item ucc-cart-total ucc-cart-total--taxes ucc-split">
144
174
<span class="ucc-cart-total-label ucc-split__left"></span>
145
175
<span class="ucc-cart-total-value ucc-split__right"></span>
146
176
</div>
@@ -149,6 +179,7 @@ export class UccCartModalElement extends UccModalElement
149
179
<span class="ucc-cart-total-value ucc-split__right"></span>
150
180
</div>
151
181
</div>
182
+ <div class="ucc-cart-message">Calculate shipping and apply discounts during checkout</div>
152
183
<a class="ucc-cart-checkout" href="#"></a>
153
184
` )
154
185
0 commit comments