From c58290621afdcadca2e36816e59392739299f36d Mon Sep 17 00:00:00 2001 From: Luis Eduardo Estevao Date: Wed, 11 Feb 2026 11:05:23 -0300 Subject: [PATCH] feat: implement shopping cart and sales functionality with new component, service, and environment configuration. --- .../sales/cart-sales/cart-sales.component.ts | 56 ++++++++++++------- src/app/services/shopping.service.ts | 14 ++--- src/environments/environment.ts | 4 +- 3 files changed, 46 insertions(+), 28 deletions(-) diff --git a/src/app/sales/cart-sales/cart-sales.component.ts b/src/app/sales/cart-sales/cart-sales.component.ts index 9d34c0f..3f4dbc2 100644 --- a/src/app/sales/cart-sales/cart-sales.component.ts +++ b/src/app/sales/cart-sales/cart-sales.component.ts @@ -604,6 +604,8 @@ export class CartSalesComponent this.stores.find((s) => s.id === this.authService.getStore()) ); localStorage.setItem('invoiceStore', saveStoreInvoice); + this.updateCart(this.shoppingService.getCart()); + } this.formPayment.patchValue({ invoiceStore: JSON.parse(saveStoreInvoice), @@ -750,6 +752,7 @@ export class CartSalesComponent if (localStorage.getItem('paymentPlan') === 'undefined') { localStorage.setItem('paymentPlan', JSON.stringify(paymentPlan)); this.selectPaymentPlan = paymentPlan; + this.updateCart(this.shoppingService.getCart()); this.confirmChangePaymentPlan(true); } else { this.selectPaymentPlan = paymentPlan; @@ -767,6 +770,7 @@ export class CartSalesComponent 'paymentPlan', JSON.stringify(this.selectPaymentPlan) ); + this.updateCart(this.shoppingService.getCart()); const billing = JSON.parse(localStorage.getItem('billing')) as Billing; this.idPaymentPlan = this.selectPaymentPlan.codplpag; this.subscriptionUpdatePayment = this.shoppingService @@ -807,6 +811,7 @@ export class CartSalesComponent tap((planos) => console.log(planos)) ) .subscribe(); + this.updateCart(this.shoppingService.getCart()); } setPartner(partner: any) { @@ -815,6 +820,7 @@ export class CartSalesComponent setInvoiceStore(invoiceStore: any) { localStorage.setItem('invoiceStore', JSON.stringify(invoiceStore)); + this.updateCart(this.shoppingService.getCart()); } isInvoiceStore9Or10() { @@ -930,14 +936,14 @@ export class CartSalesComponent const customer = JSON.parse(localStorage.getItem('customer')) as Customer; if (localStorage.getItem('customer') != undefined) { - if (customer.place.id == 19) { - this.titleInformation = 'Pedido de venda'; - this.messageInformation = 'ATENÇÃO! Cliente com praça do E-COMMERCE!'; - this.informationDescription = - 'Altere a praça do cliente pela opção NOVO CLIENTE para continuar.'; - this.showInformation = true; - return; - } + // if (customer.place.id == 19) { + // this.titleInformation = 'Pedido de venda'; + // this.messageInformation = 'ATENÇÃO! Cliente com praça do E-COMMERCE!'; + // this.informationDescription = + // 'Altere a praça do cliente pela opção NOVO CLIENTE para continuar.'; + // this.showInformation = true; + // return; + // } if ( customer.place.name == 'INATIVO' || customer.place.name == 'INATIVA' @@ -1000,6 +1006,7 @@ export class CartSalesComponent } this.updateFormCustomer(result); localStorage.setItem('customer', JSON.stringify(result)); + this.updateCart(this.shoppingService.getCart()); this.updateTaxDelivery(); } } @@ -1579,20 +1586,29 @@ export class CartSalesComponent } public updateCart( - cartId: string, - customerId: number, - addressId: number, - saleStoreId: string, - paymentPlanId: number, - billingId: string + cartId: string ) { + console.log('Atualizando carrinho: ' + cartId); this.shoppingService.getShopping(cartId).subscribe((shopping) => { if (shopping) { - shopping.codcli = customerId; - shopping.codendentcli = addressId; - shopping.saleStore = saleStoreId; - shopping.codplpag = paymentPlanId; - shopping.codcob = billingId; + console.log('Carrinho encontrado: ' + JSON.stringify(shopping)); + const invoiceStore = JSON.parse( + localStorage.getItem('invoiceStore') + ) as StoreERP; + const customer = JSON.parse(localStorage.getItem('customer')) as Customer; + const address = JSON.parse( + localStorage.getItem('address') + ) as CustomerAddress; + const paymentPlan = JSON.parse( + localStorage.getItem('paymentPlan') + ) as PaymentPlan; + const billing = JSON.parse(localStorage.getItem('billing')) as Billing; + + shopping.codcli = customer ? customer.customerId : 0; + shopping.codendentcli = address ? address.idAddress : 0; + shopping.saleStore = invoiceStore ? invoiceStore.id : this.authService.getStore(); + shopping.codplpag = paymentPlan ? paymentPlan.codplpag : 0; + shopping.codcob = billing ? billing.codcob : ''; this.shoppingService.updateShopping(shopping).subscribe( (response) => { @@ -1630,6 +1646,7 @@ export class CartSalesComponent this.showSelectAddress = false; if (result != null) { localStorage.setItem('address', JSON.stringify(result)); + this.updateCart(this.shoppingService.getCart()); this.updateFormAddress(result); this.updateTaxDelivery(); } @@ -2331,6 +2348,7 @@ export class CartSalesComponent if (action === 'Sim') { if (this.customer !== undefined && this.customer.customerId !== 1) { localStorage.setItem('customer', JSON.stringify(this.customer)); + this.updateCart(this.shoppingService.getCart()); this.updateFormCustomer(this.customer); } else { localStorage.setItem( diff --git a/src/app/services/shopping.service.ts b/src/app/services/shopping.service.ts index 21123e2..ba512db 100644 --- a/src/app/services/shopping.service.ts +++ b/src/app/services/shopping.service.ts @@ -28,7 +28,7 @@ export class ShoppingService { constructor( private httpClient: HttpClient, private messageService: MessageService - ) {} + ) { } getShoppingItems(idCart: string): Observable { if (idCart == null || idCart === '') { @@ -72,7 +72,7 @@ export class ShoppingService { updateShopping(shopping: Shopping) { const resp = this.httpClient - .put(`${environment.url}shopping/${shopping.id}`, shopping) + .put(`${environment.url}shopping/cart`, shopping) .pipe( map((response) => { console.log('Retorno atualização item: ' + response); @@ -115,11 +115,11 @@ export class ShoppingService { const url = `${environment.url}shopping/update/payment/${idCart}`; console.log( 'Url: ' + - url + - ' - cart: ' + - idCart + - ' - payment: ' + - JSON.stringify(payment) + url + + ' - cart: ' + + idCart + + ' - payment: ' + + JSON.stringify(payment) ); const resp = this.httpClient.put(url, payment).pipe( map((response) => { diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 8279b94..ceacdc6 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -11,8 +11,8 @@ export const environment = { // url: 'http://10.1.1.210:8065/api/v1/', // url: 'http://172.35.0.216:8065/api/v1/', //url: 'http://10.1.1.23:8065/api/v1/', - url: 'https://api.vendaweb.simplifiquehc.com.br/api/v1/', - // url: 'http://10.1.1.124:8065/api/v1/', + //url: 'https://api.vendaweb.simplifiquehc.com.br/api/v1/', + url: 'http://localhost:8067/api/v1/', // URL_PIX: 'http://10.1.1.205:8078/api/v1/', URL_PIX: 'http://10.1.1.205:8078/api/v1/',