feat: implement product attribute selector component and integrate into product detail page
This commit is contained in:
@@ -69,6 +69,7 @@
|
||||
type="button"
|
||||
class="product-detail__quantity-button"
|
||||
aria-label="Aumentar cantidad"
|
||||
[disabled]="quantity() >= (selectedVariant()?.stock ?? 1)"
|
||||
(click)="increaseQuantity()"
|
||||
>
|
||||
+
|
||||
@@ -80,11 +81,12 @@
|
||||
class="product-detail__cta"
|
||||
variant="secondary"
|
||||
type="button"
|
||||
[disabled]="!selectedVariant()"
|
||||
>
|
||||
Agregar al carrito
|
||||
</app-button>
|
||||
|
||||
<app-button class="product-detail__cta" type="button">
|
||||
<app-button class="product-detail__cta" type="button" [disabled]="!selectedVariant()">
|
||||
Comprar
|
||||
</app-button>
|
||||
</div>
|
||||
|
||||
@@ -154,10 +154,14 @@ export class ProductDetailPageComponent implements OnInit, OnDestroy {
|
||||
|
||||
protected onVariantChange(variant: ProductVariantMap | null): void {
|
||||
this.selectedVariant.set(variant);
|
||||
if (variant && this.quantity() > variant.stock) {
|
||||
this.quantity.set(Math.max(1, variant.stock));
|
||||
}
|
||||
}
|
||||
|
||||
protected increaseQuantity(): void {
|
||||
this.quantity.update((current) => current + 1);
|
||||
const currentStock = this.selectedVariant()?.stock ?? 1;
|
||||
this.quantity.update((current) => current < currentStock ? current + 1 : current);
|
||||
}
|
||||
|
||||
protected decreaseQuantity(): void {
|
||||
|
||||
Reference in New Issue
Block a user