From 202205c03857d26ae61f3d7fa3bfea58925f6520 Mon Sep 17 00:00:00 2001 From: ncoronel Date: Thu, 2 Jul 2026 09:01:30 -0300 Subject: [PATCH] feat: integrate quantity selector component into cart and product detail pages for enhanced functionality --- .../product-detail-page.component.html | 5 +--- .../product-detail-page.component.ts | 7 ------ .../cart-item/cart-item.component.html | 14 +++++++---- .../cart-item/cart-item.component.scss | 13 +--------- .../cart-item/cart-item.component.ts | 25 ++++++++++++++++++- .../quantity-selector.component.html | 2 +- .../quantity-selector.component.scss | 25 +++++++++++++++++++ .../quantity-selector.component.ts | 12 ++++----- 8 files changed, 66 insertions(+), 37 deletions(-) diff --git a/src/app/features/store/pages/product-detail-page/product-detail-page.component.html b/src/app/features/store/pages/product-detail-page/product-detail-page.component.html index f934867..cadc2f2 100644 --- a/src/app/features/store/pages/product-detail-page/product-detail-page.component.html +++ b/src/app/features/store/pages/product-detail-page/product-detail-page.component.html @@ -54,11 +54,8 @@
diff --git a/src/app/features/store/pages/product-detail-page/product-detail-page.component.ts b/src/app/features/store/pages/product-detail-page/product-detail-page.component.ts index 43c22eb..08eec66 100644 --- a/src/app/features/store/pages/product-detail-page/product-detail-page.component.ts +++ b/src/app/features/store/pages/product-detail-page/product-detail-page.component.ts @@ -215,14 +215,7 @@ export class ProductDetailPageComponent implements OnInit, OnDestroy { } } - protected increaseQuantity(): void { - const currentStock = this.selectedVariant()?.stock ?? 1; - this.quantity.update((current) => current < currentStock ? current + 1 : current); - } - protected decreaseQuantity(): void { - this.quantity.update((current) => Math.max(1, current - 1)); - } protected addToCart(): void { const variant = this.selectedVariant(); diff --git a/src/app/shared/components/cart-item/cart-item.component.html b/src/app/shared/components/cart-item/cart-item.component.html index d4c8722..0bb1480 100644 --- a/src/app/shared/components/cart-item/cart-item.component.html +++ b/src/app/shared/components/cart-item/cart-item.component.html @@ -33,11 +33,15 @@ }
- diff --git a/src/app/shared/components/cart-item/cart-item.component.scss b/src/app/shared/components/cart-item/cart-item.component.scss index a13197a..7553a99 100644 --- a/src/app/shared/components/cart-item/cart-item.component.scss +++ b/src/app/shared/components/cart-item/cart-item.component.scss @@ -92,19 +92,8 @@ gap: 0.125rem; } -.cart-item-qty-btn, -.cart-item-qty-value { - width: 18px; - height: 18px; - border-color: #cfcfcf !important; - color: #666666; - font-size: 10px; - line-height: 1; -} -.cart-item-qty-btn { - padding: 0; -} + .cart-item-remove-btn { width: 18px; diff --git a/src/app/shared/components/cart-item/cart-item.component.ts b/src/app/shared/components/cart-item/cart-item.component.ts index aa1134e..68465cb 100644 --- a/src/app/shared/components/cart-item/cart-item.component.ts +++ b/src/app/shared/components/cart-item/cart-item.component.ts @@ -1,4 +1,5 @@ -import { ChangeDetectionStrategy, Component, computed, input } from '@angular/core'; +import { ChangeDetectionStrategy, Component, computed, input, output } from '@angular/core'; +import { QuantitySelectorComponent } from '../quantity-selector/quantity-selector.component'; export interface CartItemAttribute { label: string; @@ -8,6 +9,7 @@ export interface CartItemAttribute { @Component({ selector: 'app-cart-item', standalone: true, + imports: [QuantitySelectorComponent], templateUrl: './cart-item.component.html', styleUrl: './cart-item.component.scss', changeDetection: ChangeDetectionStrategy.OnPush @@ -21,6 +23,27 @@ export class CartItemComponent { readonly attributes = input([]); readonly quantity = input(1); + readonly quantityChange = output(); + readonly remove = output(); + readonly increase = output(); + readonly decrease = output(); + + protected onQuantityChange(newQuantity: number): void { + this.quantityChange.emit(newQuantity); + } + + protected onRemove(): void { + this.remove.emit(); + } + + protected onIncrease(): void { + this.increase.emit(); + } + + protected onDecrease(): void { + this.decrease.emit(); + } + protected readonly formattedOriginalPrice = computed(() => { const price = this.originalPrice(); return price === null ? null : this.formatCurrency(price); diff --git a/src/app/shared/components/quantity-selector/quantity-selector.component.html b/src/app/shared/components/quantity-selector/quantity-selector.component.html index c991d01..a9614a7 100644 --- a/src/app/shared/components/quantity-selector/quantity-selector.component.html +++ b/src/app/shared/components/quantity-selector/quantity-selector.component.html @@ -1,4 +1,4 @@ -
+