@@ -121,6 +121,11 @@ export default class NetlifyCommerce {
121
121
} else {
122
122
this . line_items [ sku ] = Object . assign ( product , { path, meta, quantity} ) ;
123
123
}
124
+ if ( item . addons && product . addons ) {
125
+ this . line_items [ sku ] . addons = product . addons . filter ( ( addon ) => item . addons . indexOf ( addon . sku ) !== - 1 ) ;
126
+ } else {
127
+ delete this . line_items [ sku ] . addons ;
128
+ }
124
129
return this . loadSettings ( ) . then ( ( ) => {
125
130
this . persistCart ( ) ;
126
131
return this . getCart ( ) ;
@@ -146,8 +151,24 @@ export default class NetlifyCommerce {
146
151
const item = cart . items [ key ] = Object . assign ( { } , this . line_items [ key ] , {
147
152
price : getPrice ( this . line_items [ key ] . prices , this . currency , this . user )
148
153
} ) ;
154
+ if ( this . line_items [ key ] . addons ) {
155
+ item . addons = [ ] ;
156
+ this . line_items [ key ] . addons . forEach ( ( addon ) => {
157
+ item . addons . push ( Object . assign ( { } , addon , {
158
+ price : getPrice ( addon . prices , this . currency , this . user )
159
+ } ) ) ;
160
+ } ) ;
161
+ }
149
162
item . tax = getTax ( item , this . settings && this . settings . taxes , this . billing_country ) ;
150
- cart . subtotal . cents += parseFloat ( item . price . amount * item . quantity * 100 ) ;
163
+ cart . subtotal . cents += parseFloat ( item . price . amount ) * item . quantity * 100 ;
164
+ if ( item . addons ) {
165
+ item . addonPrice = {
166
+ currency : this . currency ,
167
+ cents : item . addons . reduce ( ( sum , addon ) => sum + parseFloat ( addon . price . amount ) * 100 , 0 )
168
+ } ;
169
+ item . addonPrice . amount = ( item . addonPrice . cents / 100 ) . toFixed ( 2 ) ;
170
+ cart . subtotal . cents += item . addonPrice . cents * item . quantity ;
171
+ }
151
172
cart . taxes . cents += parseFloat ( item . tax . amount * 100 ) ;
152
173
}
153
174
cart . subtotal . amount = centsToAmount ( cart . subtotal . cents ) ;
0 commit comments