feat: implement direct purchase functionality and enhance product buy events

This commit is contained in:
2026-07-27 16:25:38 -03:00
parent 902f65d8d0
commit f063bac527
9 changed files with 140 additions and 12 deletions

View File

@@ -13,7 +13,7 @@
[description]="item.descripcion ?? ''"
[price]="price(item)"
[variants]="variantsFor(item)"
(buy)="buy.emit(item)"
(buy)="emitRowBuy(item, $event)"
(addToCart)="emitRowCart(item, $event)"
/>
}
@@ -22,7 +22,7 @@
[title]="item.nombre"
[description]="item.descripcion ?? ''"
[price]="price(item)"
(buy)="buy.emit(item)"
(buy)="emitColumnBuy(item, $event)"
(addToCart)="emitColumnCart(item, $event)"
/>
}
@@ -32,7 +32,7 @@
[title]="item.nombre"
[originalPrice]="price(item)"
[imagePriority]="loadImages() && index < 4"
(buy)="buy.emit(item)"
(buy)="emitProductDetailBuy(item)"
/>
}
}

View File

@@ -37,6 +37,13 @@ export interface ProductListCartEvent {
variant?: number | null;
}
export interface ProductListBuyEvent {
product: ProductListItem;
quantity: number;
variant?: number | null;
directPurchase: boolean;
}
@Component({
selector: 'app-product-list',
imports: [
@@ -61,7 +68,7 @@ export class ProductListComponent {
readonly loading = input(false);
readonly loadImages = input(true);
readonly buy = output<ProductListItem>();
readonly buy = output<ProductListBuyEvent>();
readonly addToCart = output<ProductListCartEvent>();
readonly pageChange = output<number>();
@@ -119,4 +126,24 @@ export class ProductListComponent {
protected emitColumnCart(product: ProductListItem, event: { quantity: number }): void {
this.addToCart.emit({ product, quantity: event.quantity });
}
protected emitRowBuy(
product: ProductListItem,
event: { quantity: number; variant: unknown },
): void {
this.buy.emit({
product,
quantity: event.quantity,
variant: typeof event.variant === 'number' ? event.variant : null,
directPurchase: true,
});
}
protected emitColumnBuy(product: ProductListItem, event: { quantity: number }): void {
this.buy.emit({ product, quantity: event.quantity, variant: null, directPurchase: true });
}
protected emitProductDetailBuy(product: ProductListItem): void {
this.buy.emit({ product, quantity: 1, variant: null, directPurchase: false });
}
}

View File

@@ -19,7 +19,7 @@
{{ formattedPrice() }}
</span>
<div class="product-row-card__btn-wrapper">
<app-button variant="primary" (click)="buy.emit()">
<app-button variant="primary" (click)="onBuy()">
Comprar
</app-button>
</div>

View File

@@ -28,7 +28,7 @@ export class ProductRowCardComponent {
readonly selectedVariant = model<any>(null);
// Interactive events
readonly buy = output<void>();
readonly buy = output<{ quantity: number; variant: any }>();
readonly addToCart = output<{ quantity: number; variant: any }>();
constructor() {
@@ -57,6 +57,13 @@ export class ProductRowCardComponent {
});
}
protected onBuy(): void {
this.buy.emit({
quantity: this.quantity(),
variant: this.selectedVariant(),
});
}
/**
* Helper method to format currency numbers to Argentine Pesos style "$ XX.XXX".
*/

View File

@@ -14,7 +14,7 @@
</div>
<div class="product-vertical-with-cart-card__actions">
<app-button variant="primary" (click)="buy.emit()">Comprar</app-button>
<app-button variant="primary" (click)="onBuy()">Comprar</app-button>
<app-button variant="secondary" (click)="onAddToCart()"> Agregar al carrito </app-button>
</div>
</div>

View File

@@ -17,7 +17,7 @@ export class ProductVerticalWithCartCardComponent {
readonly quantity = model<number>(1);
readonly buy = output<void>();
readonly buy = output<{ quantity: number }>();
readonly addToCart = output<{ quantity: number }>();
protected readonly formattedPrice = computed(() => this.formatCurrency(this.price()));
@@ -26,6 +26,10 @@ export class ProductVerticalWithCartCardComponent {
this.addToCart.emit({ quantity: this.quantity() });
}
protected onBuy(): void {
this.buy.emit({ quantity: this.quantity() });
}
private formatCurrency(value: number): string {
const rounded = Math.round(value);
const parts = rounded.toString().split('.');