feat: implement shopping cart module with order management and discount components
All checks were successful
Build (develop) / Promote (main) / build-and-push-deploy (push) Successful in 6m18s

This commit is contained in:
Luis Eduardo Estevao
2026-04-19 17:53:03 -03:00
parent 4f5e2e5944
commit bbb5d68af1
8 changed files with 182 additions and 172 deletions

View File

@@ -278,7 +278,7 @@ export class CartSalesComponent
) { }
ngOnChanges(changes: SimpleChanges): void {
this.loadShopping();
//this.loadShopping();
}
ngAfterViewInit(): void { }
@@ -326,18 +326,9 @@ export class CartSalesComponent
}
}
loadShopping() {
this.shoppingSubscription = this.shopping$.subscribe((data) => {
this.shopping = data;
if (this.shopping !== null) {
this.totalWeight = data.totpeso;
this.loadFormOrder();
}
});
}
getTaxValue() {
const taxDelivery = JSON.parse(localStorage.getItem('taxDelivery'));
if (!this.formResumeOrder) return 0;
const taxValue = Number.parseFloat(
this.formResumeOrder.get('taxValue').value
);
@@ -345,18 +336,24 @@ export class CartSalesComponent
return taxDelivery != null ? taxDelivery.taxValue : taxValue;
}
loadFormOrder() {
this.subscriptionShopping = this.shopping$.subscribe((data) => {
const taxDelivery = JSON.parse(localStorage.getItem('taxDelivery'));
this.formResumeOrder = this.fb.group({
taxValue: [
taxDelivery.taxValue > 0 ? taxDelivery.taxValue.toFixed(2) : '0',
],
discount: [data.vldesconto > 0 ? data.vldesconto.toFixed(2) : '0,00'],
carrierId: [taxDelivery.carrierId],
deliveryTaxId: [taxDelivery.deliveryTaxId],
loadFormOrder(data?: Shopping) {
if (!data && this.shopping) {
data = this.shopping;
}
if (!data) return;
const taxDelivery = JSON.parse(localStorage.getItem('taxDelivery'));
if (this.formResumeOrder) {
this.formResumeOrder.patchValue({
taxValue:
taxDelivery != null && taxDelivery.taxValue > 0
? taxDelivery.taxValue.toFixed(2)
: '0',
discount: data.vldesconto > 0 ? data.vldesconto.toFixed(2) : '0,00',
carrierId: taxDelivery != null ? taxDelivery.carrierId : 0,
deliveryTaxId: taxDelivery != null ? taxDelivery.deliveryTaxId : 0,
});
});
}
}
ngOnInit(): void {
@@ -449,6 +446,7 @@ export class CartSalesComponent
taxValue: new FormControl(this.cartData.taxValue.toFixed(2), []),
discount: new FormControl(this.cartData.discountValue.toFixed(2), []),
carrierId: new FormControl(this.cartData.carrierId, []),
deliveryTaxId: new FormControl(0, []),
});
this.formPayment = this.fb.group({
invoiceStore: new FormControl(null),
@@ -499,7 +497,7 @@ export class CartSalesComponent
this.shopping = data;
if (this.shopping !== null) {
this.totalWeight = data.totpeso;
this.loadFormOrder();
this.loadFormOrder(data);
}
});
@@ -1432,10 +1430,10 @@ export class CartSalesComponent
let carrierId = 0;
if (taxValue >= 0) {
deliveryTaxId = Number.parseFloat(
this.formResumeOrder.get('deliveryTaxId').value
this.formResumeOrder.get('deliveryTaxId') ? this.formResumeOrder.get('deliveryTaxId').value : 0
);
carrierId = Number.parseFloat(
this.formResumeOrder.get('carrierId').value
this.formResumeOrder.get('carrierId') ? this.formResumeOrder.get('carrierId').value : 0
);
}
const order: OrderDeliveryTax = {
@@ -1446,7 +1444,6 @@ export class CartSalesComponent
};
localStorage.setItem('taxDelivery', JSON.stringify(order));
this.loadFormOrder();
this.loadShopping();
/* this.store.dispatch(new UpdateDeliveryTaxAction(order));
this.updating$.subscribe((update) => {
@@ -2146,10 +2143,10 @@ export class CartSalesComponent
);
let percentOrder = (discountValue / orderValue) * 100;
console.log('Percentual do pedido: ' + percentOrder);
if (this.percentSeller < percentOrder) {
this.openedAuthUser = true;
return;
}
// if (this.percentSeller < percentOrder) {
// this.openedAuthUser = true;
// return;
// }
if (discountValue <= 0.01) {
percentOrder = 0;
}
@@ -2159,8 +2156,9 @@ export class CartSalesComponent
idUserAuth: this.authService.getUser(),
};
this.store.dispatch(new ApplyDiscountOrderAction(order));
this.store.dispatch(new LoadShoppingAction(this.shoppingService.getCart()));
// this.store.dispatch(new LoadShoppingAction(this.shoppingService.getCart())); // Reloader moved to Effect
this.loadFormOrder();
this.calculateTaxDelivery(true);
}
applyDiscountOrder() {
@@ -2249,6 +2247,7 @@ export class CartSalesComponent
this.showInformation = true;
return;
}
this.loadFormOrder();
}
calcDiscountOrderValue() {
@@ -2591,6 +2590,7 @@ export class CartSalesComponent
priorityDelivery: priorityDelivery,
};
console.log('dataDeliveryTax', JSON.stringify(dataDeliveryTax));
this.shoppingService.calculateDeliveryTax(dataDeliveryTax).subscribe(
(result) => {
this.dataDeliveryTax = result;