@@ -51,6 +51,7 @@ export class CheckoutComponent implements OnInit {
5151 showError : boolean = false ;
5252 providerId :any = null ;
5353 loadingItems :boolean = false ;
54+ orderNote : string = '' ;
5455
5556 constructor (
5657 private localStorage : LocalStorageService ,
@@ -66,15 +67,16 @@ export class CheckoutComponent implements OnInit {
6667 private route : ActivatedRoute ) {
6768 // Bind the method to preserve context
6869 this . orderProduct = this . orderProduct . bind ( this ) ;
69- this . eventMessage . messages$ . subscribe ( ev => {
70+ this . eventMessage . messages$ . subscribe ( async ev => {
7071 if ( ev . type === 'BillAccChanged' ) {
7172 this . getBilling ( ) ;
7273 }
7374 if ( ev . value == true ) {
7475 this . addBill = false ;
7576 }
7677 if ( ev . type === 'ChangedSession' ) {
77- this . initCheckoutData ( ) ;
78+ console . log ( 'changing session...' )
79+ await this . initCheckoutData ( ) ;
7880 }
7981 if ( ev . type === 'AddedCartItem' ) {
8082 this . loadingItems = true ;
@@ -198,11 +200,11 @@ export class CheckoutComponent implements OnInit {
198200
199201 console . log ( 'Productos creados:' , products ) ;
200202
201- const productOrder = this . createProductOrder ( products ) ;
202- console . log ( '--- order ---' ) ;
203- console . log ( productOrder ) ;
204-
205203 try {
204+ const productOrder = this . createProductOrder ( products ) ;
205+ console . log ( '--- order ---' ) ;
206+ console . log ( productOrder ) ;
207+
206208 const response = await firstValueFrom ( this . orderService . postProductOrder ( productOrder ) ) ;
207209 const redirectUrl = response . headers . get ( 'X-Redirect-URL' ) ;
208210
@@ -254,22 +256,35 @@ export class CheckoutComponent implements OnInit {
254256 }
255257
256258 private createProductOrder ( products : any [ ] ) {
257- return {
258- productOrderItem : products ,
259- relatedParty : [
260- {
261- id : this . relatedParty ,
262- href : this . relatedParty ,
263- role : 'Customer'
264- }
265- ] ,
266- priority : '4' ,
267- billingAccount : {
268- id : this . selectedBillingAddress . id ,
269- href : this . selectedBillingAddress . id
270- } ,
271- notificationContact : this . selectedBillingAddress . email
272- } ;
259+
260+ let po :any = {
261+ productOrderItem : products ,
262+ relatedParty : [
263+ {
264+ id : this . relatedParty ,
265+ href : this . relatedParty ,
266+ role : 'Customer'
267+ }
268+ ] ,
269+ priority : '4' ,
270+ billingAccount : {
271+ id : this . selectedBillingAddress . id ,
272+ href : this . selectedBillingAddress . id
273+ } ,
274+ notificationContact : this . selectedBillingAddress . email
275+ } ;
276+
277+ if ( this . orderNote != '' ) {
278+ const newNote = {
279+ text : this . orderNote ,
280+ id : `urn:ngsi-ld:note:${ uuidv4 ( ) } ` ,
281+ author : this . relatedParty ,
282+ date : new Date ( ) . toISOString ( )
283+ } ;
284+ po [ 'note' ] = [ newNote ]
285+ }
286+
287+ return po
273288 }
274289
275290 private async emptyShoppingCart ( ) {
@@ -348,7 +363,7 @@ export class CheckoutComponent implements OnInit {
348363 }
349364 }
350365
351- initCheckoutData ( ) {
366+ async initCheckoutData ( ) {
352367 this . providerId = this . route . snapshot . paramMap . get ( 'id' ) ;
353368 let aux = this . localStorage . getObject ( 'login_items' ) as LoginInfo ;
354369 if ( aux ) {
@@ -365,7 +380,8 @@ export class CheckoutComponent implements OnInit {
365380 console . log ( '--- Login Info ---' )
366381 console . log ( aux )
367382
368- this . cartService . getShoppingCart ( ) . then ( async data => {
383+ let data = await this . cartService . getShoppingCart ( ) ;
384+ //this.cartService.getShoppingCart().then(async data => {
369385 console . log ( '---CARRITO API---' )
370386 console . log ( data )
371387 this . items = data ;
@@ -377,12 +393,12 @@ export class CheckoutComponent implements OnInit {
377393 this . cdr . detectChanges ( ) ;
378394 this . getTotalPrice ( ) ;
379395 console . log ( '------------------' )
380- } )
396+ // })
381397 console . log ( '--- ITEMS ---' )
382398 console . log ( this . items )
383399
384400 this . loading_baddrs = true ;
385- this . getBilling ( ) ;
401+ await this . getBilling ( ) ;
386402 }
387403
388404 async getProviderInfo ( ) {
@@ -405,10 +421,12 @@ export class CheckoutComponent implements OnInit {
405421 }
406422
407423
408- getBilling ( ) {
424+ async getBilling ( ) {
425+ this . selectedBillingAddress = null ;
409426 let isBillSelected = false ;
410427 this . billingAddresses = [ ] ;
411- this . account . getBillingAccount ( ) . then ( data => {
428+ let data = await this . account . getBillingAccount ( ) ;
429+ //this.account.getBillingAccount().then(data => {
412430 for ( let i = 0 ; i < data . length ; i ++ ) {
413431 isBillSelected = false ;
414432 let email = ''
@@ -455,17 +473,21 @@ export class CheckoutComponent implements OnInit {
455473 this . billingAddresses . push ( baddr )
456474 if ( isBillSelected ) {
457475 this . selectedBillingAddress = baddr
476+ this . cdr . detectChanges ( ) ;
458477 }
459478 }
460479 console . log ( 'billing account...' )
461480 console . log ( this . billingAddresses )
481+
462482 this . loading_baddrs = false ;
463483 if ( this . billingAddresses . length > 0 ) {
464484 this . preferred = false ;
465485 } else {
466486 this . preferred = true ;
467487 }
468- } )
488+ //})
489+ this . validBillAddr = ! ! this . selectedBillingAddress ?. id ;
490+ this . cdr . detectChanges ( ) ;
469491 }
470492
471493 async onSelected ( baddr : billingAccountCart ) {
0 commit comments