Compare commits
7 Commits
caa1fddcc1
...
e21c5e9e9f
| Author | SHA1 | Date | |
|---|---|---|---|
| e21c5e9e9f | |||
| f7a8b42892 | |||
| 9f8e42c30b | |||
| d45199a0ef | |||
| c1da31711f | |||
| cf61611d76 | |||
| 2c4d22f0b9 |
BIN
public/images/ticket-selector-entrada-pasarela.png
Normal file
BIN
public/images/ticket-selector-entrada-pasarela.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 333 KiB |
@@ -1,4 +1,7 @@
|
|||||||
<footer class="store-layout__footer mt-auto text-light">
|
<footer
|
||||||
|
class="store-layout__footer mt-auto text-light"
|
||||||
|
[style.background-image]="backgroundImageUrl ? 'url(' + backgroundImageUrl + ')' : null"
|
||||||
|
>
|
||||||
<div class="container-xl px-3 px-md-4 py-4 py-md-5 store-layout__footer-content">
|
<div class="container-xl px-3 px-md-4 py-4 py-md-5 store-layout__footer-content">
|
||||||
<div class="row g-4 store-layout__footer-grid">
|
<div class="row g-4 store-layout__footer-grid">
|
||||||
<div class="col-12 store-layout__brand-column">
|
<div class="col-12 store-layout__brand-column">
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
.store-layout__footer {
|
.store-layout__footer {
|
||||||
background-color: var(--tenant-footer-bg);
|
background-color: var(--tenant-footer-bg);
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
background-position: center;
|
||||||
|
background-size: cover;
|
||||||
}
|
}
|
||||||
|
|
||||||
.store-layout__mobile-divider {
|
.store-layout__mobile-divider {
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ export class StoreFooterComponent {
|
|||||||
@Input({ required: true }) footerSections: StoreFooterSection[] = [];
|
@Input({ required: true }) footerSections: StoreFooterSection[] = [];
|
||||||
@Input({ required: true }) socialMedia: SocialMedia[] = [];
|
@Input({ required: true }) socialMedia: SocialMedia[] = [];
|
||||||
@Input() logoUrl: string | null = null;
|
@Input() logoUrl: string | null = null;
|
||||||
|
@Input() backgroundImageUrl: string | null = null;
|
||||||
@Input() storeName: string | null = null;
|
@Input() storeName: string | null = null;
|
||||||
readonly logoutClick = output<void>();
|
readonly logoutClick = output<void>();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
<header class="store-layout__header">
|
<header
|
||||||
|
class="store-layout__header"
|
||||||
|
[style.background-image]="backgroundImageUrl() ? 'url(' + backgroundImageUrl() + ')' : null"
|
||||||
|
>
|
||||||
<div class="store-layout__header-main">
|
<div class="store-layout__header-main">
|
||||||
<div class="container-xl px-3 px-md-4 py-3 py-lg-4">
|
<div class="container-xl px-3 px-md-4 py-3 py-lg-4">
|
||||||
<div class="row align-items-center gy-3 gy-md-0">
|
<div class="row align-items-center gy-3 gy-md-0">
|
||||||
@@ -74,12 +77,14 @@
|
|||||||
</app-button>
|
</app-button>
|
||||||
}
|
}
|
||||||
|
|
||||||
<app-cart-icon
|
@if (displayCart()) {
|
||||||
[quantity]="cartQuantity()"
|
<app-cart-icon
|
||||||
ariaLabel="Carrito de compras"
|
[quantity]="cartQuantity()"
|
||||||
title="Carrito"
|
ariaLabel="Carrito de compras"
|
||||||
(click)="cartClick.emit()"
|
title="Carrito"
|
||||||
/>
|
(click)="cartClick.emit()"
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
|
||||||
<div class="store-layout__user-menu d-none d-md-inline-flex position-relative">
|
<div class="store-layout__user-menu d-none d-md-inline-flex position-relative">
|
||||||
<app-icon-button
|
<app-icon-button
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
.store-layout__header {
|
.store-layout__header {
|
||||||
color: #ffffff;
|
color: #ffffff;
|
||||||
background-color: var(--tenant-header-bg);
|
background-color: var(--tenant-header-bg);
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
background-position: center;
|
||||||
|
background-size: cover;
|
||||||
}
|
}
|
||||||
|
|
||||||
.store-layout__header-main {
|
.store-layout__header-main {
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ export class StoreHeaderComponent {
|
|||||||
private readonly router = inject(Router);
|
private readonly router = inject(Router);
|
||||||
|
|
||||||
readonly logoUrl = input<string | null>(null);
|
readonly logoUrl = input<string | null>(null);
|
||||||
|
readonly backgroundImageUrl = input<string | null>(null);
|
||||||
readonly cartQuantity = input<number>(0);
|
readonly cartQuantity = input<number>(0);
|
||||||
readonly user = input<AuthUser | null>(null);
|
readonly user = input<AuthUser | null>(null);
|
||||||
readonly isAuthenticated = input<boolean>(false);
|
readonly isAuthenticated = input<boolean>(false);
|
||||||
@@ -37,6 +38,7 @@ export class StoreHeaderComponent {
|
|||||||
readonly categories = input<readonly Category[]>([]);
|
readonly categories = input<readonly Category[]>([]);
|
||||||
readonly displayCategories = input(true);
|
readonly displayCategories = input(true);
|
||||||
readonly displaySeachBar = input(true);
|
readonly displaySeachBar = input(true);
|
||||||
|
readonly displayCart = input(true);
|
||||||
readonly cartClick = output<void>();
|
readonly cartClick = output<void>();
|
||||||
readonly ticketsClick = output<void>();
|
readonly ticketsClick = output<void>();
|
||||||
readonly loginClick = output<void>();
|
readonly loginClick = output<void>();
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
ngSkipHydration
|
ngSkipHydration
|
||||||
[cartQuantity]="cartQuantity()"
|
[cartQuantity]="cartQuantity()"
|
||||||
[logoUrl]="tenant()?.header_logo ?? null"
|
[logoUrl]="tenant()?.header_logo ?? null"
|
||||||
|
[backgroundImageUrl]="tenant()?.header_bg_image ?? null"
|
||||||
[user]="user()"
|
[user]="user()"
|
||||||
[isAuthenticated]="isAuthenticated()"
|
[isAuthenticated]="isAuthenticated()"
|
||||||
[accountNavigationMenus]="accountNavigationMenus()"
|
[accountNavigationMenus]="accountNavigationMenus()"
|
||||||
@@ -10,6 +11,7 @@
|
|||||||
[categories]="tenant()?.categories ?? []"
|
[categories]="tenant()?.categories ?? []"
|
||||||
[displayCategories]="tenant()?.display_categories ?? true"
|
[displayCategories]="tenant()?.display_categories ?? true"
|
||||||
[displaySeachBar]="tenant()?.display_seach_bar ?? true"
|
[displaySeachBar]="tenant()?.display_seach_bar ?? true"
|
||||||
|
[displayCart]="displayCart()"
|
||||||
(cartClick)="isCartOpen.set(!isCartOpen())"
|
(cartClick)="isCartOpen.set(!isCartOpen())"
|
||||||
(ticketsClick)="onTicketsClick()"
|
(ticketsClick)="onTicketsClick()"
|
||||||
(loginClick)="onLoginClick()"
|
(loginClick)="onLoginClick()"
|
||||||
@@ -18,7 +20,7 @@
|
|||||||
(categorySelect)="onCategorySelect($event)"
|
(categorySelect)="onCategorySelect($event)"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
@if (isCartOpen()) {
|
@if (displayCart() && isCartOpen()) {
|
||||||
<div class="store-layout__cart-overlay" (click)="isCartOpen.set(false)"></div>
|
<div class="store-layout__cart-overlay" (click)="isCartOpen.set(false)"></div>
|
||||||
<div class="store-layout__cart-dropdown card border-0 shadow-lg">
|
<div class="store-layout__cart-dropdown card border-0 shadow-lg">
|
||||||
<app-cart
|
<app-cart
|
||||||
@@ -58,6 +60,7 @@
|
|||||||
[footerSections]="footerSections()"
|
[footerSections]="footerSections()"
|
||||||
[socialMedia]="tenant()?.social_media ?? []"
|
[socialMedia]="tenant()?.social_media ?? []"
|
||||||
[logoUrl]="tenant()?.footer_logo ?? null"
|
[logoUrl]="tenant()?.footer_logo ?? null"
|
||||||
|
[backgroundImageUrl]="tenant()?.footer_bg_image ?? null"
|
||||||
[storeName]="tenant()?.nombre ?? null"
|
[storeName]="tenant()?.nombre ?? null"
|
||||||
(logoutClick)="onLogoutClick()"
|
(logoutClick)="onLogoutClick()"
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ const tenant: Tenant = {
|
|||||||
footer_bg_color: '#313131',
|
footer_bg_color: '#313131',
|
||||||
header_logo: 'https://example.com/header.png',
|
header_logo: 'https://example.com/header.png',
|
||||||
footer_logo: 'https://example.com/footer.png',
|
footer_logo: 'https://example.com/footer.png',
|
||||||
|
header_bg_image: 'https://example.com/header-background.png',
|
||||||
|
footer_bg_image: 'https://example.com/footer-background.png',
|
||||||
categories: [],
|
categories: [],
|
||||||
menues: [
|
menues: [
|
||||||
{
|
{
|
||||||
@@ -210,6 +212,7 @@ describe('StoreLayoutComponent', () => {
|
|||||||
categories: [{ id: 1, nombre: 'Remeras', subcategories: [] }],
|
categories: [{ id: 1, nombre: 'Remeras', subcategories: [] }],
|
||||||
display_categories: false,
|
display_categories: false,
|
||||||
display_seach_bar: false,
|
display_seach_bar: false,
|
||||||
|
display_cart: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const fixture = TestBed.createComponent(StoreLayoutComponent);
|
const fixture = TestBed.createComponent(StoreLayoutComponent);
|
||||||
@@ -219,6 +222,13 @@ describe('StoreLayoutComponent', () => {
|
|||||||
|
|
||||||
expect(compiled.querySelector('#store-search-input')).toBeNull();
|
expect(compiled.querySelector('#store-search-input')).toBeNull();
|
||||||
expect(compiled.querySelector('.store-layout__category-trigger')).toBeNull();
|
expect(compiled.querySelector('.store-layout__category-trigger')).toBeNull();
|
||||||
|
expect(compiled.querySelector('app-cart-icon')).toBeNull();
|
||||||
|
|
||||||
|
(fixture.componentInstance as any).isCartOpen.set(true);
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
expect(compiled.querySelector('app-cart')).toBeNull();
|
||||||
|
expect(compiled.querySelector('.store-layout__cart-overlay')).toBeNull();
|
||||||
|
|
||||||
const header = fixture.debugElement.query(By.directive(StoreHeaderComponent));
|
const header = fixture.debugElement.query(By.directive(StoreHeaderComponent));
|
||||||
(header.componentInstance as any).toggleMobileMenu();
|
(header.componentInstance as any).toggleMobileMenu();
|
||||||
@@ -245,6 +255,12 @@ describe('StoreLayoutComponent', () => {
|
|||||||
`app-store-footer img.store-layout__brand-logo[src="${tenant.footer_logo}"]`,
|
`app-store-footer img.store-layout__brand-logo[src="${tenant.footer_logo}"]`,
|
||||||
),
|
),
|
||||||
).not.toBeNull();
|
).not.toBeNull();
|
||||||
|
expect(
|
||||||
|
(compiled.querySelector('.store-layout__header') as HTMLElement).style.backgroundImage,
|
||||||
|
).toContain(tenant.header_bg_image!);
|
||||||
|
expect(
|
||||||
|
(compiled.querySelector('.store-layout__footer') as HTMLElement).style.backgroundImage,
|
||||||
|
).toContain(tenant.footer_bg_image!);
|
||||||
expect(compiled.querySelector('.fa-cart-shopping')).not.toBeNull();
|
expect(compiled.querySelector('.fa-cart-shopping')).not.toBeNull();
|
||||||
expect(compiled.querySelector('.fa-circle-user')).not.toBeNull();
|
expect(compiled.querySelector('.fa-circle-user')).not.toBeNull();
|
||||||
expect(compiled.querySelector('.fa-instagram')).not.toBeNull();
|
expect(compiled.querySelector('.fa-instagram')).not.toBeNull();
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ export class StoreLayoutComponent implements OnInit {
|
|||||||
|
|
||||||
protected readonly isCartOpen = signal(false);
|
protected readonly isCartOpen = signal(false);
|
||||||
protected readonly isCreatingPurchase = signal(false);
|
protected readonly isCreatingPurchase = signal(false);
|
||||||
|
protected readonly displayCart = computed(() => this.tenant()?.display_cart ?? true);
|
||||||
|
|
||||||
protected readonly cartSubtotal = computed(() => {
|
protected readonly cartSubtotal = computed(() => {
|
||||||
const cart = this.cartService.cart();
|
const cart = this.cartService.cart();
|
||||||
@@ -69,10 +70,7 @@ export class StoreLayoutComponent implements OnInit {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const variants = (item.product?.variants ?? []).map((variant) => ({
|
const variants = item.product?.variants ?? [];
|
||||||
value: variant.id,
|
|
||||||
values: variant.values,
|
|
||||||
}));
|
|
||||||
const selectedVariant = item.product?.variants?.find(
|
const selectedVariant = item.product?.variants?.find(
|
||||||
(variant) => variant.id === item.variant_id,
|
(variant) => variant.id === item.variant_id,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -48,6 +48,16 @@ export interface ProductAttribute {
|
|||||||
|
|
||||||
export type InventoryPolicy = 'tracked' | 'unlimited';
|
export type InventoryPolicy = 'tracked' | 'unlimited';
|
||||||
|
|
||||||
|
export interface CatalogVariantOption {
|
||||||
|
value: string;
|
||||||
|
label: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type CatalogVariantValue =
|
||||||
|
| string
|
||||||
|
| CatalogVariantOption
|
||||||
|
| Array<string | CatalogVariantOption>;
|
||||||
|
|
||||||
export interface CatalogItemVariant {
|
export interface CatalogItemVariant {
|
||||||
id: number;
|
id: number;
|
||||||
descripcion?: string | null;
|
descripcion?: string | null;
|
||||||
@@ -91,15 +101,19 @@ export interface CatalogItemDetail {
|
|||||||
images?: string[];
|
images?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export type CatalogProductLayout = 'row' | 'column_with_image' | 'column_with_cart';
|
export type CatalogProductLayout =
|
||||||
export type CatalogGroupLayout = 'paginated' | 'simple' | 'simple_vertical' | 'carousel';
|
| 'row'
|
||||||
|
| 'column_with_image'
|
||||||
|
| 'column_with_cart'
|
||||||
|
| 'ticket_selector';
|
||||||
|
export type CatalogGroupLayout = 'paginated' | 'simple' | 'simple_vertical' | 'carousel' | 'single';
|
||||||
|
|
||||||
export interface CatalogFeaturedItemVariant {
|
export interface CatalogFeaturedItemVariant {
|
||||||
id: number;
|
id: number;
|
||||||
descripcion?: string | null;
|
descripcion?: string | null;
|
||||||
precio?: string;
|
precio?: string;
|
||||||
stock_tecnico: number | null;
|
stock_tecnico: number | null;
|
||||||
values: Record<string, string | string[]>;
|
values: Record<string, CatalogVariantValue>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CatalogFeaturedItem {
|
export interface CatalogFeaturedItem {
|
||||||
|
|||||||
41
src/app/core/services/checkout.service.spec.ts
Normal file
41
src/app/core/services/checkout.service.spec.ts
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import { provideHttpClient } from '@angular/common/http';
|
||||||
|
import { HttpTestingController, provideHttpClientTesting } from '@angular/common/http/testing';
|
||||||
|
import { TestBed } from '@angular/core/testing';
|
||||||
|
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
||||||
|
|
||||||
|
import { environment } from '../../../environments/environment';
|
||||||
|
import { CheckoutService } from './checkout.service';
|
||||||
|
|
||||||
|
describe('CheckoutService', () => {
|
||||||
|
let service: CheckoutService;
|
||||||
|
let httpMock: HttpTestingController;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
providers: [CheckoutService, provideHttpClient(), provideHttpClientTesting()],
|
||||||
|
});
|
||||||
|
|
||||||
|
service = TestBed.inject(CheckoutService);
|
||||||
|
httpMock = TestBed.inject(HttpTestingController);
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => httpMock.verify());
|
||||||
|
|
||||||
|
it('starts one direct checkout with all selected variants', async () => {
|
||||||
|
const payload = {
|
||||||
|
direct_items: [
|
||||||
|
{ catalog_item_id: 10, variant_id: 101, cantidad: 1 },
|
||||||
|
{ catalog_item_id: 10, variant_id: 102, cantidad: 1 },
|
||||||
|
],
|
||||||
|
};
|
||||||
|
const purchasePromise = service.startCheckout('desfile', payload);
|
||||||
|
const request = httpMock.expectOne(`${environment.url}tenants/desfile/compras/start-checkout`);
|
||||||
|
|
||||||
|
expect(request.request.method).toBe('POST');
|
||||||
|
expect(request.request.body).toEqual(payload);
|
||||||
|
|
||||||
|
request.flush({ data: { id: 55 } });
|
||||||
|
|
||||||
|
await expect(purchasePromise).resolves.toMatchObject({ id: 55 });
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -11,16 +11,44 @@ export interface UpdatePurchaseCustomerPayload {
|
|||||||
email: string;
|
email: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface DirectCheckoutItem {
|
||||||
|
catalog_item_id: number;
|
||||||
|
variant_id: number | null;
|
||||||
|
cantidad: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface UnavailableCheckoutItem {
|
||||||
|
index: number;
|
||||||
|
catalog_item_id: number;
|
||||||
|
variant_id: number | null;
|
||||||
|
requested_quantity: number;
|
||||||
|
available_quantity: number;
|
||||||
|
message: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface InsufficientStockResponse {
|
||||||
|
code: 'purchase.insufficient_stock';
|
||||||
|
message: string;
|
||||||
|
errors: Record<string, string[]>;
|
||||||
|
unavailable_items: UnavailableCheckoutItem[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isInsufficientStockResponse(value: unknown): value is InsufficientStockResponse {
|
||||||
|
if (typeof value !== 'object' || value === null) return false;
|
||||||
|
|
||||||
|
const response = value as Partial<InsufficientStockResponse>;
|
||||||
|
|
||||||
|
return (
|
||||||
|
response.code === 'purchase.insufficient_stock' && Array.isArray(response.unavailable_items)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export type StartCheckoutPayload =
|
export type StartCheckoutPayload =
|
||||||
| {
|
| {
|
||||||
cart_id: number;
|
cart_id: number;
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
direct_item: {
|
direct_items: DirectCheckoutItem[];
|
||||||
catalog_item_id: number;
|
|
||||||
variant_id: number | null;
|
|
||||||
cantidad: number;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface PurchaseStatusResponse {
|
export interface PurchaseStatusResponse {
|
||||||
@@ -181,10 +209,7 @@ export class CheckoutService extends BaseApiService {
|
|||||||
return purchase;
|
return purchase;
|
||||||
}
|
}
|
||||||
|
|
||||||
async completePurchase(
|
async completePurchase(tenantCode: string, purchaseId: number): Promise<PurchaseStatusResponse> {
|
||||||
tenantCode: string,
|
|
||||||
purchaseId: number,
|
|
||||||
): Promise<PurchaseStatusResponse> {
|
|
||||||
const response = await firstValueFrom(
|
const response = await firstValueFrom(
|
||||||
this.http.post<{ data?: PurchaseStatusResponse } | PurchaseStatusResponse>(
|
this.http.post<{ data?: PurchaseStatusResponse } | PurchaseStatusResponse>(
|
||||||
`${environment.url}tenants/${tenantCode}/compras/${purchaseId}/complete`,
|
`${environment.url}tenants/${tenantCode}/compras/${purchaseId}/complete`,
|
||||||
@@ -222,10 +247,7 @@ export class CheckoutService extends BaseApiService {
|
|||||||
return { status: purchase.status ?? null };
|
return { status: purchase.status ?? null };
|
||||||
}
|
}
|
||||||
|
|
||||||
async cancelPurchase(
|
async cancelPurchase(tenantCode: string, purchaseId: number): Promise<PurchaseStatusResponse> {
|
||||||
tenantCode: string,
|
|
||||||
purchaseId: number,
|
|
||||||
): Promise<PurchaseStatusResponse> {
|
|
||||||
const response = await firstValueFrom(
|
const response = await firstValueFrom(
|
||||||
this.http.post<{ data?: PurchaseStatusResponse } | PurchaseStatusResponse>(
|
this.http.post<{ data?: PurchaseStatusResponse } | PurchaseStatusResponse>(
|
||||||
`${environment.url}tenants/${tenantCode}/compras/${purchaseId}/cancel`,
|
`${environment.url}tenants/${tenantCode}/compras/${purchaseId}/cancel`,
|
||||||
@@ -249,9 +271,7 @@ export class CheckoutService extends BaseApiService {
|
|||||||
if (status) {
|
if (status) {
|
||||||
url += `?status=${status}`;
|
url += `?status=${status}`;
|
||||||
}
|
}
|
||||||
const response = await firstValueFrom(
|
const response = await firstValueFrom(this.http.get<{ data: PurchaseSummaryResponse[] }>(url));
|
||||||
this.http.get<{ data: PurchaseSummaryResponse[] }>(url),
|
|
||||||
);
|
|
||||||
if (!response) {
|
if (!response) {
|
||||||
throw new Error('Error al obtener las compras.');
|
throw new Error('Error al obtener las compras.');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,6 +104,8 @@ export interface Tenant {
|
|||||||
footer_bg_color: string;
|
footer_bg_color: string;
|
||||||
header_logo: string;
|
header_logo: string;
|
||||||
footer_logo: string;
|
footer_logo: string;
|
||||||
|
header_bg_image?: string | null;
|
||||||
|
footer_bg_image?: string | null;
|
||||||
website_type_code?: string | null;
|
website_type_code?: string | null;
|
||||||
website_type?: WebsiteType | null;
|
website_type?: WebsiteType | null;
|
||||||
event_date_text?: string | null;
|
event_date_text?: string | null;
|
||||||
@@ -111,11 +113,12 @@ export interface Tenant {
|
|||||||
event?: TenantEvent | null;
|
event?: TenantEvent | null;
|
||||||
selected_bank_account_id?: number | null;
|
selected_bank_account_id?: number | null;
|
||||||
selected_bank_account?: BankAccount | null;
|
selected_bank_account?: BankAccount | null;
|
||||||
search_product_layout?: 'row' | 'column_with_image' | 'column_with_cart';
|
search_product_layout?: 'row' | 'column_with_image' | 'column_with_cart' | 'ticket_selector';
|
||||||
search_group_layout?: 'paginated' | 'simple' | 'simple_vertical' | 'carousel';
|
search_group_layout?: 'paginated' | 'simple' | 'simple_vertical' | 'carousel' | 'single';
|
||||||
search_items_per_page?: number;
|
search_items_per_page?: number;
|
||||||
display_categories?: boolean;
|
display_categories?: boolean;
|
||||||
display_seach_bar?: boolean;
|
display_seach_bar?: boolean;
|
||||||
|
display_cart?: boolean;
|
||||||
social_media?: SocialMedia[];
|
social_media?: SocialMedia[];
|
||||||
menues?: Menu[];
|
menues?: Menu[];
|
||||||
categories: Category[];
|
categories: Category[];
|
||||||
|
|||||||
@@ -754,6 +754,29 @@
|
|||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<section
|
||||||
|
class="component-demo component-demo--ticket-selector card shadow-sm mt-4"
|
||||||
|
data-testid="ticket-selector-demo"
|
||||||
|
>
|
||||||
|
<div class="card-body">
|
||||||
|
<span class="eyebrow">Reusable Component</span>
|
||||||
|
<h2 class="mb-2">Selector de entradas (Ticket Selector Layout)</h2>
|
||||||
|
<p class="text-muted mb-4">
|
||||||
|
Demo de selección encadenada por tipo, sector, fila y asiento. Las combinaciones sin stock
|
||||||
|
no aparecen como disponibles.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<app-product-ticket-selector
|
||||||
|
[title]="testTicketSelectorProduct.title"
|
||||||
|
[description]="testTicketSelectorProduct.description"
|
||||||
|
[price]="testTicketSelectorProduct.price"
|
||||||
|
[imageUrl]="testTicketSelectorProduct.imageUrl"
|
||||||
|
[variants]="testTicketSelectorProduct.variants"
|
||||||
|
(buy)="onTicketBuy($event)"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
<app-store-section title="PRODUCTOS" class="component-demo store-section-demo mt-5">
|
<app-store-section title="PRODUCTOS" class="component-demo store-section-demo mt-5">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@for (product of testProducts; track product.title) {
|
@for (product of testProducts; track product.title) {
|
||||||
|
|||||||
@@ -15,6 +15,10 @@
|
|||||||
border: 0;
|
border: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.component-demo--ticket-selector {
|
||||||
|
width: min(100%, 76rem);
|
||||||
|
}
|
||||||
|
|
||||||
.store-section-demo {
|
.store-section-demo {
|
||||||
width: min(100%, 64rem);
|
width: min(100%, 64rem);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { InputComponent } from '../../../../shared/components/input/input.compon
|
|||||||
import { PaginatorComponent } from '../../../../shared/components/paginator/paginator.component';
|
import { PaginatorComponent } from '../../../../shared/components/paginator/paginator.component';
|
||||||
import { ProductColumnWithImageComponent } from '../../../../shared/components/product-column-with-image/product-column-with-image.component';
|
import { ProductColumnWithImageComponent } from '../../../../shared/components/product-column-with-image/product-column-with-image.component';
|
||||||
import { ProductRowCardComponent } from '../../../../shared/components/product-row-card/product-row-card.component';
|
import { ProductRowCardComponent } from '../../../../shared/components/product-row-card/product-row-card.component';
|
||||||
|
import { ProductTicketSelectorComponent } from '../../../../shared/components/product-ticket-selector/product-ticket-selector.component';
|
||||||
import { ProductVerticalWithCartCardComponent } from '../../../../shared/components/product-vertical-with-cart-card/product-vertical-with-cart-card.component';
|
import { ProductVerticalWithCartCardComponent } from '../../../../shared/components/product-vertical-with-cart-card/product-vertical-with-cart-card.component';
|
||||||
import { StoreSectionComponent } from '../../../../shared/components/store-section/store-section.component';
|
import { StoreSectionComponent } from '../../../../shared/components/store-section/store-section.component';
|
||||||
import { ModalService } from '../../../../core/services/modal.service';
|
import { ModalService } from '../../../../core/services/modal.service';
|
||||||
@@ -32,6 +33,11 @@ interface CarouselProductMock {
|
|||||||
imageUrl: string;
|
imageUrl: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ticketOption = (value: string, label: string = value): { value: string; label: string } => ({
|
||||||
|
value,
|
||||||
|
label,
|
||||||
|
});
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-reutilizables-test-page',
|
selector: 'app-reutilizables-test-page',
|
||||||
imports: [
|
imports: [
|
||||||
@@ -41,6 +47,7 @@ interface CarouselProductMock {
|
|||||||
PaginatorComponent,
|
PaginatorComponent,
|
||||||
ProductColumnWithImageComponent,
|
ProductColumnWithImageComponent,
|
||||||
ProductRowCardComponent,
|
ProductRowCardComponent,
|
||||||
|
ProductTicketSelectorComponent,
|
||||||
ProductVerticalWithCartCardComponent,
|
ProductVerticalWithCartCardComponent,
|
||||||
StoreSectionComponent,
|
StoreSectionComponent,
|
||||||
IconButtonComponent,
|
IconButtonComponent,
|
||||||
@@ -204,9 +211,9 @@ export class ReutilizablesTestPageComponent {
|
|||||||
'Acceso total al predio. No incluye acceso a estacionamiento. Niños menores de 5 años ingresan gratis.',
|
'Acceso total al predio. No incluye acceso a estacionamiento. Niños menores de 5 años ingresan gratis.',
|
||||||
price: 10000,
|
price: 10000,
|
||||||
variants: [
|
variants: [
|
||||||
{ value: '10-oct-manana', values: { fecha: '10 de Octubre', turno: 'Mañana' } },
|
{ id: '10-oct-manana', values: { fecha: '10 de Octubre', turno: 'Mañana' } },
|
||||||
{ value: '10-oct-tarde', values: { fecha: '10 de Octubre', turno: 'Tarde' } },
|
{ id: '10-oct-tarde', values: { fecha: '10 de Octubre', turno: 'Tarde' } },
|
||||||
{ value: '11-oct-tarde', values: { fecha: '11 de Octubre', turno: 'Tarde' } },
|
{ id: '11-oct-tarde', values: { fecha: '11 de Octubre', turno: 'Tarde' } },
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -216,6 +223,125 @@ export class ReutilizablesTestPageComponent {
|
|||||||
price: 11500,
|
price: 11500,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
protected readonly testTicketSelectorProduct = {
|
||||||
|
title: 'ENTRADAS DESFILE PURA TENDENCIA',
|
||||||
|
description: '',
|
||||||
|
price: 40000,
|
||||||
|
imageUrl: '/images/ticket-selector-entrada-pasarela.png',
|
||||||
|
variants: [
|
||||||
|
{
|
||||||
|
id: 1001,
|
||||||
|
precio: 250000,
|
||||||
|
stock_tecnico: 1,
|
||||||
|
values: {
|
||||||
|
tipo: ticketOption('vip_lunch', 'VIP + Lunch'),
|
||||||
|
sector: ticketOption('a', 'Sector A'),
|
||||||
|
fila: ticketOption('1', 'Fila 1'),
|
||||||
|
asiento: ticketOption('1', 'Asiento 1'),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 1002,
|
||||||
|
precio: 250000,
|
||||||
|
stock_tecnico: 1,
|
||||||
|
values: {
|
||||||
|
tipo: ticketOption('vip_lunch', 'VIP + Lunch'),
|
||||||
|
sector: ticketOption('a', 'Sector A'),
|
||||||
|
fila: ticketOption('1', 'Fila 1'),
|
||||||
|
asiento: ticketOption('2', 'Asiento 2'),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 1003,
|
||||||
|
precio: 250000,
|
||||||
|
stock_tecnico: 1,
|
||||||
|
values: {
|
||||||
|
tipo: ticketOption('vip_lunch', 'VIP + Lunch'),
|
||||||
|
sector: ticketOption('c', 'Sector C'),
|
||||||
|
fila: ticketOption('1', 'Fila 1'),
|
||||||
|
asiento: ticketOption('1', 'Asiento 1'),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 1004,
|
||||||
|
precio: 200000,
|
||||||
|
stock_tecnico: 1,
|
||||||
|
values: {
|
||||||
|
tipo: ticketOption('vip_lunch', 'VIP + Lunch'),
|
||||||
|
sector: ticketOption('a', 'Sector A'),
|
||||||
|
fila: ticketOption('2', 'Fila 2'),
|
||||||
|
asiento: ticketOption('1', 'Asiento 1'),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 1005,
|
||||||
|
precio: 200000,
|
||||||
|
stock_tecnico: 0,
|
||||||
|
values: {
|
||||||
|
tipo: ticketOption('vip_lunch', 'VIP + Lunch'),
|
||||||
|
sector: ticketOption('a', 'Sector A'),
|
||||||
|
fila: ticketOption('2', 'Fila 2'),
|
||||||
|
asiento: ticketOption('2', 'Asiento 2'),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 1006,
|
||||||
|
precio: 100000,
|
||||||
|
stock_tecnico: 1,
|
||||||
|
values: {
|
||||||
|
tipo: ticketOption('general', 'General'),
|
||||||
|
sector: ticketOption('b', 'Sector B'),
|
||||||
|
fila: ticketOption('3', 'Fila 3'),
|
||||||
|
asiento: ticketOption('1', 'Asiento 1'),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 1007,
|
||||||
|
precio: 100000,
|
||||||
|
stock_tecnico: 1,
|
||||||
|
values: {
|
||||||
|
tipo: ticketOption('general', 'General'),
|
||||||
|
sector: ticketOption('b', 'Sector B'),
|
||||||
|
fila: ticketOption('3', 'Fila 3'),
|
||||||
|
asiento: ticketOption('2', 'Asiento 2'),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 1008,
|
||||||
|
precio: 90000,
|
||||||
|
stock_tecnico: 1,
|
||||||
|
values: {
|
||||||
|
tipo: ticketOption('general', 'General'),
|
||||||
|
sector: ticketOption('d', 'Sector D'),
|
||||||
|
fila: ticketOption('3', 'Fila 3'),
|
||||||
|
asiento: ticketOption('1', 'Asiento 1'),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 1009,
|
||||||
|
precio: 65000,
|
||||||
|
stock_tecnico: 1,
|
||||||
|
values: {
|
||||||
|
tipo: ticketOption('general', 'General'),
|
||||||
|
sector: ticketOption('d', 'Sector D'),
|
||||||
|
fila: ticketOption('4', 'Fila 4'),
|
||||||
|
asiento: ticketOption('1', 'Asiento 1'),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 1010,
|
||||||
|
precio: 40000,
|
||||||
|
stock_tecnico: 1,
|
||||||
|
values: {
|
||||||
|
tipo: ticketOption('general', 'General'),
|
||||||
|
sector: ticketOption('d', 'Sector D'),
|
||||||
|
fila: ticketOption('5', 'Fila 5'),
|
||||||
|
asiento: ticketOption('1', 'Asiento 1'),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
protected readonly cartMockItems: CartItemMock[] = [
|
protected readonly cartMockItems: CartItemMock[] = [
|
||||||
{
|
{
|
||||||
imageUrl: null,
|
imageUrl: null,
|
||||||
@@ -272,6 +398,12 @@ export class ReutilizablesTestPageComponent {
|
|||||||
alert(`Comprando: ${productTitle}`);
|
alert(`Comprando: ${productTitle}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected onTicketBuy(variantIds: number[]): void {
|
||||||
|
this.toastService.success(
|
||||||
|
`Compra iniciada para ${variantIds.length} entrada/s: ${variantIds.join(', ')}.`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
protected onFileChange(file: File | null): void {
|
protected onFileChange(file: File | null): void {
|
||||||
this.fileName = file?.name ?? '';
|
this.fileName = file?.name ?? '';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -127,11 +127,13 @@ export class CategoryItemsPageComponent {
|
|||||||
this.creatingDirectPurchase.set(true);
|
this.creatingDirectPurchase.set(true);
|
||||||
try {
|
try {
|
||||||
const purchase = await this.injector.get(CheckoutService).startCheckout(tenant.codigo, {
|
const purchase = await this.injector.get(CheckoutService).startCheckout(tenant.codigo, {
|
||||||
direct_item: {
|
direct_items: [
|
||||||
catalog_item_id: event.product.id,
|
{
|
||||||
variant_id: event.variant ?? null,
|
catalog_item_id: event.product.id,
|
||||||
cantidad: event.quantity,
|
variant_id: event.variant ?? null,
|
||||||
},
|
cantidad: event.quantity,
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
await this.router.navigate(['/checkout'], { queryParams: { purchase: purchase.id } });
|
await this.router.navigate(['/checkout'], { queryParams: { purchase: purchase.id } });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -480,11 +480,13 @@ describe('ProductDetailPageComponent', () => {
|
|||||||
await Promise.resolve();
|
await Promise.resolve();
|
||||||
|
|
||||||
expect(checkoutServiceStub.startCheckout).toHaveBeenCalledWith('tenant-test', {
|
expect(checkoutServiceStub.startCheckout).toHaveBeenCalledWith('tenant-test', {
|
||||||
direct_item: {
|
direct_items: [
|
||||||
catalog_item_id: 1,
|
{
|
||||||
variant_id: null,
|
catalog_item_id: 1,
|
||||||
cantidad: 1,
|
variant_id: null,
|
||||||
},
|
cantidad: 1,
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
expect(routerStub.navigate).toHaveBeenCalledWith(['/checkout'], {
|
expect(routerStub.navigate).toHaveBeenCalledWith(['/checkout'], {
|
||||||
queryParams: { purchase: 44 },
|
queryParams: { purchase: 44 },
|
||||||
|
|||||||
@@ -317,11 +317,13 @@ export class ProductDetailPageComponent implements OnInit, OnDestroy {
|
|||||||
this.creatingDirectPurchase.set(true);
|
this.creatingDirectPurchase.set(true);
|
||||||
try {
|
try {
|
||||||
const purchase = await this.checkoutService.startCheckout(tenant.codigo, {
|
const purchase = await this.checkoutService.startCheckout(tenant.codigo, {
|
||||||
direct_item: {
|
direct_items: [
|
||||||
catalog_item_id: currentProduct.id,
|
{
|
||||||
variant_id: variant?.id ?? null,
|
catalog_item_id: currentProduct.id,
|
||||||
cantidad: this.quantity(),
|
variant_id: variant?.id ?? null,
|
||||||
},
|
cantidad: this.quantity(),
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
await this.router.navigate(['/checkout'], {
|
await this.router.navigate(['/checkout'], {
|
||||||
|
|||||||
@@ -159,11 +159,13 @@ export class SearchPageComponent {
|
|||||||
this.creatingDirectPurchase.set(true);
|
this.creatingDirectPurchase.set(true);
|
||||||
try {
|
try {
|
||||||
const purchase = await this.injector.get(CheckoutService).startCheckout(tenant.codigo, {
|
const purchase = await this.injector.get(CheckoutService).startCheckout(tenant.codigo, {
|
||||||
direct_item: {
|
direct_items: [
|
||||||
catalog_item_id: event.product.id,
|
{
|
||||||
variant_id: event.variant ?? null,
|
catalog_item_id: event.product.id,
|
||||||
cantidad: event.quantity,
|
variant_id: event.variant ?? null,
|
||||||
},
|
cantidad: event.quantity,
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
await this.router.navigate(['/checkout'], { queryParams: { purchase: purchase.id } });
|
await this.router.navigate(['/checkout'], { queryParams: { purchase: purchase.id } });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
[items]="group.items"
|
[items]="group.items"
|
||||||
[loading]="isGroupLoading(group.id)"
|
[loading]="isGroupLoading(group.id)"
|
||||||
[loadImages]="!hasMainCarouselImages() || mainCarouselReady()"
|
[loadImages]="!hasMainCarouselImages() || mainCarouselReady()"
|
||||||
|
[unavailableVariantIds]="unavailableVariantIds()"
|
||||||
(buy)="onBuyProduct($event)"
|
(buy)="onBuyProduct($event)"
|
||||||
(addToCart)="onAddToCart($event)"
|
(addToCart)="onAddToCart($event)"
|
||||||
(pageChange)="onPageChange(group.id, $event)"
|
(pageChange)="onPageChange(group.id, $event)"
|
||||||
|
|||||||
@@ -18,7 +18,10 @@ import { CatalogFeaturedGroup } from '../../../../core/services/catalog/catalog.
|
|||||||
import { CatalogService } from '../../../../core/services/catalog/catalog.service';
|
import { CatalogService } from '../../../../core/services/catalog/catalog.service';
|
||||||
import { TenantService } from '../../../../core/services/tenant.service';
|
import { TenantService } from '../../../../core/services/tenant.service';
|
||||||
import { ToastService } from '../../../../core/services/toast.service';
|
import { ToastService } from '../../../../core/services/toast.service';
|
||||||
import { CheckoutService } from '../../../../core/services/checkout.service';
|
import {
|
||||||
|
CheckoutService,
|
||||||
|
isInsufficientStockResponse,
|
||||||
|
} from '../../../../core/services/checkout.service';
|
||||||
import {
|
import {
|
||||||
ProductListComponent,
|
ProductListComponent,
|
||||||
ProductListCartEvent,
|
ProductListCartEvent,
|
||||||
@@ -60,6 +63,7 @@ export class StoreHomePageComponent implements OnInit, OnDestroy {
|
|||||||
protected readonly error = signal<string | null>(null);
|
protected readonly error = signal<string | null>(null);
|
||||||
protected readonly mainCarouselReady = signal(false);
|
protected readonly mainCarouselReady = signal(false);
|
||||||
protected readonly creatingDirectPurchase = signal(false);
|
protected readonly creatingDirectPurchase = signal(false);
|
||||||
|
protected readonly unavailableVariantIds = signal<ReadonlySet<number>>(new Set<number>());
|
||||||
protected readonly mainCarouselImages = computed(() => this.tenant()?.extras?.carousel ?? []);
|
protected readonly mainCarouselImages = computed(() => this.tenant()?.extras?.carousel ?? []);
|
||||||
protected readonly heroConfig = computed(() => this.tenant()?.extras?.heroConfig ?? null);
|
protected readonly heroConfig = computed(() => this.tenant()?.extras?.heroConfig ?? null);
|
||||||
protected readonly additionalInfo = computed(
|
protected readonly additionalInfo = computed(
|
||||||
@@ -178,16 +182,39 @@ export class StoreHomePageComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
this.creatingDirectPurchase.set(true);
|
this.creatingDirectPurchase.set(true);
|
||||||
try {
|
try {
|
||||||
const purchase = await this.injector.get(CheckoutService).startCheckout(tenant.codigo, {
|
const checkoutService = this.injector.get(CheckoutService);
|
||||||
direct_item: {
|
const variantIds = event.variantIds ?? [];
|
||||||
catalog_item_id: event.product.id,
|
const directItems =
|
||||||
variant_id: event.variant ?? null,
|
variantIds.length > 0
|
||||||
cantidad: event.quantity,
|
? variantIds.map((variantId) => ({
|
||||||
},
|
catalog_item_id: event.product.id,
|
||||||
|
variant_id: variantId,
|
||||||
|
cantidad: 1,
|
||||||
|
}))
|
||||||
|
: [
|
||||||
|
{
|
||||||
|
catalog_item_id: event.product.id,
|
||||||
|
variant_id: event.variant ?? null,
|
||||||
|
cantidad: event.quantity,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
const purchase = await checkoutService.startCheckout(tenant.codigo, {
|
||||||
|
direct_items: directItems,
|
||||||
});
|
});
|
||||||
await this.router.navigate(['/checkout'], { queryParams: { purchase: purchase.id } });
|
await this.router.navigate(['/checkout'], { queryParams: { purchase: purchase.id } });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to create direct purchase:', error);
|
console.error('Failed to create direct purchase:', error);
|
||||||
|
|
||||||
|
if (error instanceof HttpErrorResponse && isInsufficientStockResponse(error.error)) {
|
||||||
|
const unavailableIds = error.error.unavailable_items
|
||||||
|
.map((item) => item.variant_id)
|
||||||
|
.filter((variantId): variantId is number => variantId !== null);
|
||||||
|
|
||||||
|
this.unavailableVariantIds.update((current) => new Set([...current, ...unavailableIds]));
|
||||||
|
this.toastService.danger(error.error.message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.toastService.danger('No se pudo iniciar la compra directa.');
|
this.toastService.danger('No se pudo iniciar la compra directa.');
|
||||||
} finally {
|
} finally {
|
||||||
this.creatingDirectPurchase.set(false);
|
this.creatingDirectPurchase.set(false);
|
||||||
|
|||||||
@@ -449,8 +449,8 @@ describe('CartComponent', () => {
|
|||||||
quantity: 2,
|
quantity: 2,
|
||||||
variantId: 20,
|
variantId: 20,
|
||||||
variants: [
|
variants: [
|
||||||
{ value: 20, values: { servicio: 'Almuerzo' } },
|
{ id: 20, values: { servicio: 'Almuerzo' } },
|
||||||
{ value: 21, values: { servicio: 'Cena' } },
|
{ id: 21, values: { servicio: 'Cena' } },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -53,6 +53,14 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
::ng-deep .hero-title h1 {
|
||||||
|
margin: 0;
|
||||||
|
color: inherit;
|
||||||
|
font-size: inherit;
|
||||||
|
font-weight: 700;
|
||||||
|
line-height: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
::ng-deep .hero-description,
|
::ng-deep .hero-description,
|
||||||
.hero-description {
|
.hero-description {
|
||||||
color: #666666;
|
color: #666666;
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
[title]="item.nombre"
|
[title]="item.nombre"
|
||||||
[description]="item.descripcion ?? ''"
|
[description]="item.descripcion ?? ''"
|
||||||
[price]="price(item)"
|
[price]="price(item)"
|
||||||
[variants]="variantsFor(item)"
|
[variants]="item.variants ?? []"
|
||||||
(buy)="emitRowBuy(item, $event)"
|
(buy)="emitRowBuy(item, $event)"
|
||||||
(addToCart)="emitRowCart(item, $event)"
|
(addToCart)="emitRowCart(item, $event)"
|
||||||
/>
|
/>
|
||||||
@@ -27,6 +27,18 @@
|
|||||||
(addToCart)="emitColumnCart(item, $event)"
|
(addToCart)="emitColumnCart(item, $event)"
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
|
@case ('ticket_selector') {
|
||||||
|
<app-product-ticket-selector
|
||||||
|
[title]="item.nombre"
|
||||||
|
[description]="item.descripcion ?? ''"
|
||||||
|
[price]="price(item)"
|
||||||
|
[imageUrl]="loadImages() ? (item.image ?? null) : null"
|
||||||
|
[variants]="item.variants ?? []"
|
||||||
|
[unavailableVariantIds]="unavailableVariantIds()"
|
||||||
|
[disabled]="loading()"
|
||||||
|
(buy)="emitTicketBuy(item, $event)"
|
||||||
|
/>
|
||||||
|
}
|
||||||
@default {
|
@default {
|
||||||
<app-product-column-with-image
|
<app-product-column-with-image
|
||||||
[imageUrl]="loadImages() ? (item.image ?? null) : null"
|
[imageUrl]="loadImages() ? (item.image ?? null) : null"
|
||||||
@@ -54,8 +66,11 @@
|
|||||||
class="product-list"
|
class="product-list"
|
||||||
[class.product-list--row]="effectiveLayout() === 'row'"
|
[class.product-list--row]="effectiveLayout() === 'row'"
|
||||||
[class.product-list--column]="effectiveLayout() !== 'row'"
|
[class.product-list--column]="effectiveLayout() !== 'row'"
|
||||||
[class.product-list--adaptive]="groupLayout() !== 'simple_vertical'"
|
[class.product-list--adaptive]="
|
||||||
|
groupLayout() !== 'simple_vertical' && groupLayout() !== 'single'
|
||||||
|
"
|
||||||
[class.product-list--simple-vertical]="groupLayout() === 'simple_vertical'"
|
[class.product-list--simple-vertical]="groupLayout() === 'simple_vertical'"
|
||||||
|
[class.product-list--single]="groupLayout() === 'single'"
|
||||||
>
|
>
|
||||||
@for (item of itemData(); track item.id; let index = $index) {
|
@for (item of itemData(); track item.id; let index = $index) {
|
||||||
<ng-container
|
<ng-container
|
||||||
|
|||||||
@@ -27,6 +27,10 @@
|
|||||||
grid-template-columns: minmax(0, 1fr);
|
grid-template-columns: minmax(0, 1fr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&--single {
|
||||||
|
grid-template-columns: minmax(0, 1fr);
|
||||||
|
}
|
||||||
|
|
||||||
&__item {
|
&__item {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
|
|||||||
@@ -8,11 +8,14 @@ import {
|
|||||||
CatalogGroupLayout,
|
CatalogGroupLayout,
|
||||||
} from '../../../core/services/catalog/catalog.interface';
|
} from '../../../core/services/catalog/catalog.interface';
|
||||||
import { ProductListComponent, ProductListItem, ProductListLayout } from './product-list.component';
|
import { ProductListComponent, ProductListItem, ProductListLayout } from './product-list.component';
|
||||||
|
import { ProductTicketSelectorComponent } from '../product-ticket-selector/product-ticket-selector.component';
|
||||||
|
import { By } from '@angular/platform-browser';
|
||||||
|
|
||||||
describe('ProductListComponent', () => {
|
describe('ProductListComponent', () => {
|
||||||
const items: ProductListItem[] = [
|
const items: ProductListItem[] = [
|
||||||
{
|
{
|
||||||
id: 1,
|
id: 1,
|
||||||
|
type: 'product',
|
||||||
nombre: 'Producto uno',
|
nombre: 'Producto uno',
|
||||||
descripcion: 'Primera descripcion',
|
descripcion: 'Primera descripcion',
|
||||||
precio: '100.00',
|
precio: '100.00',
|
||||||
@@ -21,6 +24,7 @@ describe('ProductListComponent', () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 2,
|
id: 2,
|
||||||
|
type: 'product',
|
||||||
nombre: 'Producto dos',
|
nombre: 'Producto dos',
|
||||||
descripcion: 'Segunda descripcion',
|
descripcion: 'Segunda descripcion',
|
||||||
precio: 200,
|
precio: 200,
|
||||||
@@ -216,6 +220,81 @@ describe('ProductListComponent', () => {
|
|||||||
expect(element.querySelectorAll('app-product-column-with-image')).toHaveLength(2);
|
expect(element.querySelectorAll('app-product-column-with-image')).toHaveLength(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('renders a single ticket selector and emits its selected variant', async () => {
|
||||||
|
const ticket: ProductListItem = {
|
||||||
|
...items[0],
|
||||||
|
variants: [
|
||||||
|
{
|
||||||
|
id: 401,
|
||||||
|
precio: '10000.00',
|
||||||
|
stock_tecnico: 1,
|
||||||
|
values: {
|
||||||
|
tipo: { value: 'vip', label: 'VIP' },
|
||||||
|
sector: { value: 'a', label: 'Sector A' },
|
||||||
|
fila: { value: '3', label: 'Fila 3' },
|
||||||
|
asiento: { value: '12', label: 'Asiento 12' },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 402,
|
||||||
|
precio: '12000.00',
|
||||||
|
stock_tecnico: 1,
|
||||||
|
values: {
|
||||||
|
tipo: { value: 'vip', label: 'VIP' },
|
||||||
|
sector: { value: 'a', label: 'Sector A' },
|
||||||
|
fila: { value: '3', label: 'Fila 3' },
|
||||||
|
asiento: { value: '13', label: 'Asiento 13' },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
const fixture = await render('ticket_selector', [ticket], 'single');
|
||||||
|
const buySpy = vi.fn();
|
||||||
|
fixture.componentInstance.buy.subscribe(buySpy);
|
||||||
|
await fixture.whenStable();
|
||||||
|
fixture.detectChanges();
|
||||||
|
const element = fixture.nativeElement as HTMLElement;
|
||||||
|
|
||||||
|
expect(element.querySelector('.product-list--single')).not.toBeNull();
|
||||||
|
expect(element.querySelectorAll('app-product-ticket-selector')).toHaveLength(1);
|
||||||
|
expect(element.querySelectorAll('.variant-selector__select')).toHaveLength(4);
|
||||||
|
|
||||||
|
(element.querySelector('.ticket-selector__add-row-button') as HTMLButtonElement).click();
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
expect(element.querySelectorAll('.ticket-selector__row')).toHaveLength(2);
|
||||||
|
expect(element.querySelectorAll('.variant-selector__select')).toHaveLength(8);
|
||||||
|
|
||||||
|
(element.querySelector('.ticket-selector__actions .btn-primary') as HTMLButtonElement).click();
|
||||||
|
|
||||||
|
expect(buySpy).toHaveBeenCalledWith({
|
||||||
|
product: ticket,
|
||||||
|
quantity: 2,
|
||||||
|
variant: 401,
|
||||||
|
variantIds: [401, 402],
|
||||||
|
directPurchase: true,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('removes unavailable variants from the ticket selector', async () => {
|
||||||
|
const ticket: ProductListItem = {
|
||||||
|
...items[0],
|
||||||
|
variants: [
|
||||||
|
{ id: 401, stock_tecnico: 1, values: { asiento: { value: '1', label: '1' } } },
|
||||||
|
{ id: 402, stock_tecnico: 1, values: { asiento: { value: '2', label: '2' } } },
|
||||||
|
],
|
||||||
|
};
|
||||||
|
const fixture = await render('ticket_selector', [ticket], 'single');
|
||||||
|
fixture.componentRef.setInput('unavailableVariantIds', new Set([401]));
|
||||||
|
await fixture.whenStable();
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
const selector = fixture.debugElement.query(By.directive(ProductTicketSelectorComponent))
|
||||||
|
.componentInstance as ProductTicketSelectorComponent;
|
||||||
|
|
||||||
|
expect(selector['selectableVariants']().map((variant) => variant.id)).toEqual([402]);
|
||||||
|
});
|
||||||
|
|
||||||
it('renders carousel groups with the reusable carousel', async () => {
|
it('renders carousel groups with the reusable carousel', async () => {
|
||||||
const fixture = await render('column_with_image', items, 'carousel');
|
const fixture = await render('column_with_image', items, 'carousel');
|
||||||
const element = fixture.nativeElement as HTMLElement;
|
const element = fixture.nativeElement as HTMLElement;
|
||||||
|
|||||||
@@ -21,11 +21,9 @@ import {
|
|||||||
import { CarouselComponent } from '../carousel/carousel.component';
|
import { CarouselComponent } from '../carousel/carousel.component';
|
||||||
import { PaginatorComponent } from '../paginator/paginator.component';
|
import { PaginatorComponent } from '../paginator/paginator.component';
|
||||||
import { ProductColumnWithImageComponent } from '../product-column-with-image/product-column-with-image.component';
|
import { ProductColumnWithImageComponent } from '../product-column-with-image/product-column-with-image.component';
|
||||||
import {
|
import { ProductRowCardComponent } from '../product-row-card/product-row-card.component';
|
||||||
ProductRowCardComponent,
|
|
||||||
Variant as RowVariant,
|
|
||||||
} from '../product-row-card/product-row-card.component';
|
|
||||||
import { ProductVerticalWithCartCardComponent } from '../product-vertical-with-cart-card/product-vertical-with-cart-card.component';
|
import { ProductVerticalWithCartCardComponent } from '../product-vertical-with-cart-card/product-vertical-with-cart-card.component';
|
||||||
|
import { ProductTicketSelectorComponent } from '../product-ticket-selector/product-ticket-selector.component';
|
||||||
|
|
||||||
export type ProductListLayout = CatalogProductLayout;
|
export type ProductListLayout = CatalogProductLayout;
|
||||||
export type ProductListVariant = CatalogFeaturedItemVariant;
|
export type ProductListVariant = CatalogFeaturedItemVariant;
|
||||||
@@ -41,6 +39,7 @@ export interface ProductListBuyEvent {
|
|||||||
product: ProductListItem;
|
product: ProductListItem;
|
||||||
quantity: number;
|
quantity: number;
|
||||||
variant?: number | null;
|
variant?: number | null;
|
||||||
|
variantIds?: number[];
|
||||||
directPurchase: boolean;
|
directPurchase: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,6 +52,7 @@ export interface ProductListBuyEvent {
|
|||||||
PaginatorComponent,
|
PaginatorComponent,
|
||||||
ProductRowCardComponent,
|
ProductRowCardComponent,
|
||||||
ProductVerticalWithCartCardComponent,
|
ProductVerticalWithCartCardComponent,
|
||||||
|
ProductTicketSelectorComponent,
|
||||||
],
|
],
|
||||||
templateUrl: './product-list.component.html',
|
templateUrl: './product-list.component.html',
|
||||||
styleUrl: './product-list.component.scss',
|
styleUrl: './product-list.component.scss',
|
||||||
@@ -67,6 +67,7 @@ export class ProductListComponent {
|
|||||||
readonly items = input.required<CatalogFeaturedItems>();
|
readonly items = input.required<CatalogFeaturedItems>();
|
||||||
readonly loading = input(false);
|
readonly loading = input(false);
|
||||||
readonly loadImages = input(true);
|
readonly loadImages = input(true);
|
||||||
|
readonly unavailableVariantIds = input<ReadonlySet<number>>(new Set<number>());
|
||||||
|
|
||||||
readonly buy = output<ProductListBuyEvent>();
|
readonly buy = output<ProductListBuyEvent>();
|
||||||
readonly addToCart = output<ProductListCartEvent>();
|
readonly addToCart = output<ProductListCartEvent>();
|
||||||
@@ -105,15 +106,6 @@ export class ProductListComponent {
|
|||||||
return Number.isFinite(price) ? price : 0;
|
return Number.isFinite(price) ? price : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected variantsFor(item: ProductListItem): RowVariant[] {
|
|
||||||
return (item.variants ?? []).map((variant) => ({
|
|
||||||
value: variant.id,
|
|
||||||
descripcion: variant.descripcion,
|
|
||||||
precio: variant.precio,
|
|
||||||
values: variant.values,
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected emitRowCart(
|
protected emitRowCart(
|
||||||
product: ProductListItem,
|
product: ProductListItem,
|
||||||
event: { quantity: number; variant: unknown },
|
event: { quantity: number; variant: unknown },
|
||||||
@@ -159,4 +151,14 @@ export class ProductListComponent {
|
|||||||
protected emitProductDetailBuy(product: ProductListItem): void {
|
protected emitProductDetailBuy(product: ProductListItem): void {
|
||||||
this.buy.emit({ product, quantity: 1, variant: null, directPurchase: false });
|
this.buy.emit({ product, quantity: 1, variant: null, directPurchase: false });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected emitTicketBuy(product: ProductListItem, variantIds: number[]): void {
|
||||||
|
this.buy.emit({
|
||||||
|
product,
|
||||||
|
quantity: variantIds.length,
|
||||||
|
variant: variantIds[0] ?? null,
|
||||||
|
variantIds,
|
||||||
|
directPurchase: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ export interface Variant extends VariantSelectorVariant {
|
|||||||
label?: string;
|
label?: string;
|
||||||
descripcion?: string | null;
|
descripcion?: string | null;
|
||||||
precio?: string | number;
|
precio?: string | number;
|
||||||
|
stock_tecnico?: number | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@@ -36,7 +37,7 @@ export class ProductRowCardComponent {
|
|||||||
readonly addToCart = output<{ quantity: number; variant: unknown }>();
|
readonly addToCart = output<{ quantity: number; variant: unknown }>();
|
||||||
|
|
||||||
protected readonly selectedVariantData = computed(() =>
|
protected readonly selectedVariantData = computed(() =>
|
||||||
this.variants().find((variant) => Object.is(variant.value, this.selectedVariant())),
|
this.variants().find((variant) => Object.is(variant.id, this.selectedVariant())),
|
||||||
);
|
);
|
||||||
protected readonly effectiveDescription = computed(
|
protected readonly effectiveDescription = computed(
|
||||||
() => this.selectedVariantData()?.descripcion ?? this.description(),
|
() => this.selectedVariantData()?.descripcion ?? this.description(),
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
<article class="ticket-selector">
|
||||||
|
<header class="ticket-selector__header">
|
||||||
|
<div>
|
||||||
|
<h3 class="ticket-selector__title">{{ title() }}</h3>
|
||||||
|
@if (description()) {
|
||||||
|
<p class="ticket-selector__description">{{ description() }}</p>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
<span class="ticket-selector__price text-primary">
|
||||||
|
@if (priceRange().hasRange) {
|
||||||
|
de <strong>{{ priceRange().minimum }}</strong> a
|
||||||
|
<strong>{{ priceRange().maximum }}</strong>
|
||||||
|
} @else {
|
||||||
|
<strong>{{ priceRange().minimum }}</strong>
|
||||||
|
}
|
||||||
|
</span>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div class="ticket-selector__selection">
|
||||||
|
<span class="ticket-selector__label">Seleccioná Entrada/s:</span>
|
||||||
|
|
||||||
|
<div class="ticket-selector__rows">
|
||||||
|
@for (row of rows(); track row.id) {
|
||||||
|
<div class="ticket-selector__row">
|
||||||
|
<app-variant-selector
|
||||||
|
class="ticket-selector__fields"
|
||||||
|
[variants]="variantsForRow(row.id)"
|
||||||
|
[disabled]="disabled()"
|
||||||
|
[selectedVariant]="row.variantId"
|
||||||
|
(selectedVariantChange)="updateRow(row.id, $event)"
|
||||||
|
/>
|
||||||
|
<app-icon-button
|
||||||
|
variant="trash"
|
||||||
|
ariaLabel="Eliminar entrada"
|
||||||
|
[disabled]="disabled()"
|
||||||
|
(clicked)="removeRow(row.id)"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<app-button
|
||||||
|
hostClass="ticket-selector__add-row"
|
||||||
|
buttonClass="ticket-selector__add-row-button"
|
||||||
|
variant="secondary"
|
||||||
|
[disabled]="disabled() || !canAddRow()"
|
||||||
|
(click)="addRow()"
|
||||||
|
>
|
||||||
|
+ Agregar entrada
|
||||||
|
</app-button>
|
||||||
|
|
||||||
|
@if (selectableVariants().length === 0) {
|
||||||
|
<p class="ticket-selector__empty">No hay entradas disponibles.</p>
|
||||||
|
}
|
||||||
|
|
||||||
|
<div class="ticket-selector__actions row g-0 justify-content-end">
|
||||||
|
<div class="col-12 col-md-3">
|
||||||
|
<app-button
|
||||||
|
variant="primary"
|
||||||
|
[disabled]="disabled() || !hasSelection()"
|
||||||
|
(click)="onBuy()"
|
||||||
|
>
|
||||||
|
Comprar
|
||||||
|
</app-button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@if (imageUrl(); as image) {
|
||||||
|
<img class="ticket-selector__map" [src]="image" [alt]="'Plano de ubicaciones de ' + title()" />
|
||||||
|
}
|
||||||
|
</article>
|
||||||
@@ -0,0 +1,122 @@
|
|||||||
|
:host {
|
||||||
|
display: block;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ticket-selector {
|
||||||
|
width: 100%;
|
||||||
|
|
||||||
|
&__header {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-start;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 1rem;
|
||||||
|
padding-bottom: 1.25rem;
|
||||||
|
border-bottom: 1px solid var(--border-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
&__title {
|
||||||
|
margin: 0;
|
||||||
|
color: #666;
|
||||||
|
font-size: 22px;
|
||||||
|
font-weight: 700;
|
||||||
|
letter-spacing: 0.4px;
|
||||||
|
text-transform: uppercase;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__description {
|
||||||
|
margin: 0.35rem 0 0;
|
||||||
|
color: #777;
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__price {
|
||||||
|
flex: 0 0 auto;
|
||||||
|
font-size: 25px;
|
||||||
|
font-weight: 400;
|
||||||
|
|
||||||
|
strong {
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&__selection {
|
||||||
|
padding-top: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__label {
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 0.5rem;
|
||||||
|
color: #555;
|
||||||
|
font-size: 15px;
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__rows {
|
||||||
|
display: grid;
|
||||||
|
gap: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__row {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: minmax(0, 1fr) auto;
|
||||||
|
align-items: end;
|
||||||
|
gap: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__fields {
|
||||||
|
min-width: 0;
|
||||||
|
|
||||||
|
::ng-deep .variant-selector {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(4, minmax(120px, 1fr));
|
||||||
|
gap: 0.5rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&__add-row {
|
||||||
|
display: block;
|
||||||
|
width: 100%;
|
||||||
|
margin-top: 0.5rem;
|
||||||
|
|
||||||
|
::ng-deep .ticket-selector__add-row-button {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&__empty {
|
||||||
|
margin: 0;
|
||||||
|
color: #777;
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__actions {
|
||||||
|
margin-top: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__map {
|
||||||
|
display: block;
|
||||||
|
width: min(100%, 720px);
|
||||||
|
max-height: 680px;
|
||||||
|
margin: 3rem auto 0;
|
||||||
|
object-fit: contain;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 767.98px) {
|
||||||
|
.ticket-selector {
|
||||||
|
&__header {
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__fields {
|
||||||
|
::ng-deep .variant-selector {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&__map {
|
||||||
|
margin-top: 2rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,142 @@
|
|||||||
|
import {
|
||||||
|
ChangeDetectionStrategy,
|
||||||
|
Component,
|
||||||
|
computed,
|
||||||
|
effect,
|
||||||
|
input,
|
||||||
|
output,
|
||||||
|
signal,
|
||||||
|
} from '@angular/core';
|
||||||
|
|
||||||
|
import { ButtonComponent } from '../button/button.component';
|
||||||
|
import { IconButtonComponent } from '../icon-button/icon-button.component';
|
||||||
|
import {
|
||||||
|
VariantSelectorComponent,
|
||||||
|
VariantSelectorVariant,
|
||||||
|
} from '../variant-selector/variant-selector.component';
|
||||||
|
|
||||||
|
export interface TicketSelectorVariant extends VariantSelectorVariant {
|
||||||
|
precio?: string | number;
|
||||||
|
stock_tecnico?: number | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface TicketSelectionRow {
|
||||||
|
id: number;
|
||||||
|
variantId: number | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-product-ticket-selector',
|
||||||
|
imports: [ButtonComponent, IconButtonComponent, VariantSelectorComponent],
|
||||||
|
templateUrl: './product-ticket-selector.component.html',
|
||||||
|
styleUrl: './product-ticket-selector.component.scss',
|
||||||
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||||
|
})
|
||||||
|
export class ProductTicketSelectorComponent {
|
||||||
|
readonly title = input.required<string>();
|
||||||
|
readonly description = input<string>('');
|
||||||
|
readonly price = input<number>(0);
|
||||||
|
readonly imageUrl = input<string | null>(null);
|
||||||
|
readonly variants = input<TicketSelectorVariant[]>([]);
|
||||||
|
readonly unavailableVariantIds = input<ReadonlySet<number>>(new Set<number>());
|
||||||
|
readonly disabled = input(false);
|
||||||
|
|
||||||
|
readonly buy = output<number[]>();
|
||||||
|
|
||||||
|
protected readonly rows = signal<TicketSelectionRow[]>([{ id: 1, variantId: null }]);
|
||||||
|
private nextRowId = 2;
|
||||||
|
|
||||||
|
protected readonly selectableVariants = computed<TicketSelectorVariant[]>(() =>
|
||||||
|
this.variants().filter(
|
||||||
|
(variant) =>
|
||||||
|
!this.unavailableVariantIds().has(variant.id as number) &&
|
||||||
|
(variant.stock_tecnico == null || variant.stock_tecnico > 0),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
protected readonly hasSelection = computed(
|
||||||
|
() => this.rows().length > 0 && this.rows().every((row) => row.variantId !== null),
|
||||||
|
);
|
||||||
|
protected readonly canAddRow = computed(
|
||||||
|
() => this.rows().length < this.selectableVariants().length,
|
||||||
|
);
|
||||||
|
protected readonly priceRange = computed(() => {
|
||||||
|
const prices = this.selectableVariants()
|
||||||
|
.map((variant) => Number(variant.precio ?? this.price()))
|
||||||
|
.filter(Number.isFinite);
|
||||||
|
|
||||||
|
if (prices.length === 0) {
|
||||||
|
const price = this.formatCurrency(this.price());
|
||||||
|
return { minimum: price, maximum: price, hasRange: false };
|
||||||
|
}
|
||||||
|
|
||||||
|
const minimum = Math.min(...prices);
|
||||||
|
const maximum = Math.max(...prices);
|
||||||
|
return {
|
||||||
|
minimum: this.formatCurrency(minimum),
|
||||||
|
maximum: this.formatCurrency(maximum),
|
||||||
|
hasRange: minimum !== maximum,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
effect(() => {
|
||||||
|
const unavailable = this.unavailableVariantIds();
|
||||||
|
|
||||||
|
if (!this.rows().some((row) => row.variantId !== null && unavailable.has(row.variantId))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.rows.update((rows) =>
|
||||||
|
rows.map((row) =>
|
||||||
|
row.variantId !== null && unavailable.has(row.variantId)
|
||||||
|
? { ...row, variantId: null }
|
||||||
|
: row,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected onBuy(): void {
|
||||||
|
const variantIds = this.rows().flatMap((row) =>
|
||||||
|
row.variantId === null ? [] : [row.variantId],
|
||||||
|
);
|
||||||
|
|
||||||
|
if (variantIds.length === this.rows().length && variantIds.length > 0) {
|
||||||
|
this.buy.emit(variantIds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected addRow(): void {
|
||||||
|
if (!this.canAddRow()) return;
|
||||||
|
this.rows.update((rows) => [...rows, { id: this.nextRowId++, variantId: null }]);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected removeRow(rowId: number): void {
|
||||||
|
this.rows.update((rows) => rows.filter((row) => row.id !== rowId));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected updateRow(rowId: number, selectedVariant: unknown): void {
|
||||||
|
const variantId = typeof selectedVariant === 'number' ? selectedVariant : null;
|
||||||
|
this.rows.update((rows) => rows.map((row) => (row.id === rowId ? { ...row, variantId } : row)));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected variantsForRow(rowId: number): VariantSelectorVariant[] {
|
||||||
|
const selectedByOtherRows = new Set(
|
||||||
|
this.rows()
|
||||||
|
.filter((row) => row.id !== rowId && row.variantId !== null)
|
||||||
|
.map((row) => row.variantId),
|
||||||
|
);
|
||||||
|
|
||||||
|
return this.selectableVariants().filter(
|
||||||
|
(variant) => !selectedByOtherRows.has(variant.id as number),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private formatCurrency(value: number): string {
|
||||||
|
return new Intl.NumberFormat('es-AR', {
|
||||||
|
style: 'currency',
|
||||||
|
currency: 'ARS',
|
||||||
|
maximumFractionDigits: 0,
|
||||||
|
}).format(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,10 +21,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="product-vertical-with-cart-card__variant-selectors">
|
<div class="product-vertical-with-cart-card__variant-selectors">
|
||||||
<app-variant-selector
|
<app-variant-selector [variants]="variants()" [(selectedVariant)]="selectedVariant" />
|
||||||
[variants]="selectorVariants()"
|
|
||||||
[(selectedVariant)]="selectedVariant"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { TestBed, getTestBed } from '@angular/core/testing';
|
import { TestBed, getTestBed } from '@angular/core/testing';
|
||||||
import { BrowserTestingModule, platformBrowserTesting } from '@angular/platform-browser/testing';
|
import { BrowserTestingModule, platformBrowserTesting } from '@angular/platform-browser/testing';
|
||||||
import { afterEach, beforeAll, describe, expect, it, vi } from 'vitest';
|
import { afterEach, beforeAll, describe, expect, it, vi } from 'vitest';
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@ describe('ProductVerticalWithCartCardComponent', () => {
|
|||||||
TestBed.resetTestingModule();
|
TestBed.resetTestingModule();
|
||||||
});
|
});
|
||||||
|
|
||||||
async function createComponent(description = 'Pancho con aderezo a elección.') {
|
async function createComponent(description = 'Pancho con aderezo a elección.') {
|
||||||
await TestBed.configureTestingModule({
|
await TestBed.configureTestingModule({
|
||||||
imports: [ProductVerticalWithCartCardComponent],
|
imports: [ProductVerticalWithCartCardComponent],
|
||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
@@ -40,7 +40,7 @@ describe('ProductVerticalWithCartCardComponent', () => {
|
|||||||
);
|
);
|
||||||
expect(
|
expect(
|
||||||
element.querySelector('.product-vertical-with-cart-card__description')?.textContent,
|
element.querySelector('.product-vertical-with-cart-card__description')?.textContent,
|
||||||
).toContain('Pancho con aderezo a elección.');
|
).toContain('Pancho con aderezo a elección.');
|
||||||
expect(
|
expect(
|
||||||
element.querySelector('.product-vertical-with-cart-card__price')?.textContent?.trim(),
|
element.querySelector('.product-vertical-with-cart-card__price')?.textContent?.trim(),
|
||||||
).toBe('$ 11.500');
|
).toBe('$ 11.500');
|
||||||
@@ -130,16 +130,14 @@ describe('ProductVerticalWithCartCardComponent', () => {
|
|||||||
|
|
||||||
expect(summary?.querySelector('.product-vertical-with-cart-card__price')).not.toBeNull();
|
expect(summary?.querySelector('.product-vertical-with-cart-card__price')).not.toBeNull();
|
||||||
expect(summary?.querySelector('app-quantity-selector')).not.toBeNull();
|
expect(summary?.querySelector('app-quantity-selector')).not.toBeNull();
|
||||||
expect(
|
expect(selectors?.querySelectorAll('.variant-selector__select')).toHaveLength(1);
|
||||||
selectors?.querySelectorAll('.variant-selector__select'),
|
|
||||||
).toHaveLength(1);
|
|
||||||
expect(selectors?.querySelector('app-quantity-selector')).toBeNull();
|
expect(selectors?.querySelector('app-quantity-selector')).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('places all variant selectors together below price and quantity', async () => {
|
it('places all variant selectors together below price and quantity', async () => {
|
||||||
const fixture = await createComponent();
|
const fixture = await createComponent();
|
||||||
fixture.componentRef.setInput('variants', [
|
fixture.componentRef.setInput('variants', [
|
||||||
{ id: 20, values: { fecha: '10 de octubre', turno: 'Mañana' } },
|
{ id: 20, values: { fecha: '10 de octubre', turno: 'Mañana' } },
|
||||||
{ id: 21, values: { fecha: '10 de octubre', turno: 'Tarde' } },
|
{ id: 21, values: { fecha: '10 de octubre', turno: 'Tarde' } },
|
||||||
]);
|
]);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
@@ -181,7 +179,7 @@ describe('ProductVerticalWithCartCardComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('prioritizes the selected variant description and price', async () => {
|
it('prioritizes the selected variant description and price', async () => {
|
||||||
const fixture = await createComponent('Descripción general');
|
const fixture = await createComponent('Descripción general');
|
||||||
fixture.componentRef.setInput('variants', [
|
fixture.componentRef.setInput('variants', [
|
||||||
{
|
{
|
||||||
id: 40,
|
id: 40,
|
||||||
@@ -206,9 +204,7 @@ describe('ProductVerticalWithCartCardComponent', () => {
|
|||||||
element.querySelector('.product-vertical-with-cart-card__price')?.textContent?.trim(),
|
element.querySelector('.product-vertical-with-cart-card__price')?.textContent?.trim(),
|
||||||
).toBe('$ 10.000');
|
).toBe('$ 10.000');
|
||||||
|
|
||||||
const select = element.querySelector(
|
const select = element.querySelector('.variant-selector__select') as HTMLSelectElement;
|
||||||
'.variant-selector__select',
|
|
||||||
) as HTMLSelectElement;
|
|
||||||
select.value = select.options[1].value;
|
select.value = select.options[1].value;
|
||||||
select.dispatchEvent(new Event('change'));
|
select.dispatchEvent(new Event('change'));
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|||||||
@@ -1,11 +1,4 @@
|
|||||||
import {
|
import { ChangeDetectionStrategy, Component, computed, input, model, output } from '@angular/core';
|
||||||
ChangeDetectionStrategy,
|
|
||||||
Component,
|
|
||||||
computed,
|
|
||||||
input,
|
|
||||||
model,
|
|
||||||
output,
|
|
||||||
} from '@angular/core';
|
|
||||||
|
|
||||||
import { ButtonComponent } from '../button/button.component';
|
import { ButtonComponent } from '../button/button.component';
|
||||||
import { QuantitySelectorComponent } from '../quantity-selector/quantity-selector.component';
|
import { QuantitySelectorComponent } from '../quantity-selector/quantity-selector.component';
|
||||||
@@ -14,11 +7,9 @@ import {
|
|||||||
VariantSelectorVariant,
|
VariantSelectorVariant,
|
||||||
} from '../variant-selector/variant-selector.component';
|
} from '../variant-selector/variant-selector.component';
|
||||||
|
|
||||||
export interface VerticalCartVariant {
|
export interface VerticalCartVariant extends VariantSelectorVariant {
|
||||||
id: number;
|
|
||||||
descripcion?: string | null;
|
descripcion?: string | null;
|
||||||
precio?: string | number;
|
precio?: string | number;
|
||||||
values: Record<string, string>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@@ -52,10 +43,7 @@ export class ProductVerticalWithCartCardComponent {
|
|||||||
return Number.isFinite(variantPrice) ? variantPrice : this.price();
|
return Number.isFinite(variantPrice) ? variantPrice : this.price();
|
||||||
});
|
});
|
||||||
protected readonly formattedPrice = computed(() => this.formatCurrency(this.effectivePrice()));
|
protected readonly formattedPrice = computed(() => this.formatCurrency(this.effectivePrice()));
|
||||||
protected readonly selectorVariants = computed<VariantSelectorVariant[]>(() =>
|
protected readonly hasVariants = computed(() => this.variants().length > 0);
|
||||||
this.variants().map((variant) => ({ value: variant.id, values: variant.values })),
|
|
||||||
);
|
|
||||||
protected readonly hasVariants = computed(() => this.selectorVariants().length > 0);
|
|
||||||
|
|
||||||
protected onAddToCart(): void {
|
protected onAddToCart(): void {
|
||||||
this.addToCart.emit({ quantity: this.quantity(), variant: this.selectedVariant() });
|
this.addToCart.emit({ quantity: this.quantity(), variant: this.selectedVariant() });
|
||||||
|
|||||||
@@ -22,9 +22,9 @@ describe('VariantSelectorComponent', () => {
|
|||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
const fixture = TestBed.createComponent(VariantSelectorComponent);
|
const fixture = TestBed.createComponent(VariantSelectorComponent);
|
||||||
fixture.componentRef.setInput('variants', [
|
fixture.componentRef.setInput('variants', [
|
||||||
{ value: 1, values: { alojamiento: 'Carpa', servicio: 'Almuerzo' } },
|
{ id: 1, values: { alojamiento: 'Carpa', servicio: 'Almuerzo' } },
|
||||||
{ value: 2, values: { alojamiento: 'Carpa', servicio: 'Cena' } },
|
{ id: 2, values: { alojamiento: 'Carpa', servicio: 'Cena' } },
|
||||||
{ value: 3, values: { alojamiento: 'Hotel', servicio: 'Cena' } },
|
{ id: 3, values: { alojamiento: 'Hotel', servicio: 'Cena' } },
|
||||||
]);
|
]);
|
||||||
fixture.componentRef.setInput('selectedVariant', 1);
|
fixture.componentRef.setInput('selectedVariant', 1);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
@@ -46,14 +46,14 @@ describe('VariantSelectorComponent', () => {
|
|||||||
const fixture = TestBed.createComponent(VariantSelectorComponent);
|
const fixture = TestBed.createComponent(VariantSelectorComponent);
|
||||||
fixture.componentRef.setInput('variants', [
|
fixture.componentRef.setInput('variants', [
|
||||||
{
|
{
|
||||||
value: 1,
|
id: 1,
|
||||||
values: {
|
values: {
|
||||||
color: { value: 'red', label: 'Rojo' },
|
color: { value: 'red', label: 'Rojo' },
|
||||||
talle: { value: 's', label: 'Small' },
|
talle: { value: 's', label: 'Small' },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: 2,
|
id: 2,
|
||||||
values: {
|
values: {
|
||||||
color: { value: 'red', label: 'Rojo' },
|
color: { value: 'red', label: 'Rojo' },
|
||||||
talle: { value: 'm', label: 'Medium' },
|
talle: { value: 'm', label: 'Medium' },
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export type VariantAttributeScalar = string | VariantAttributeOption;
|
|||||||
export type VariantAttributeValue = VariantAttributeScalar | VariantAttributeScalar[];
|
export type VariantAttributeValue = VariantAttributeScalar | VariantAttributeScalar[];
|
||||||
|
|
||||||
export interface VariantSelectorVariant {
|
export interface VariantSelectorVariant {
|
||||||
value: unknown;
|
id: unknown;
|
||||||
values: Record<string, VariantAttributeValue>;
|
values: Record<string, VariantAttributeValue>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,9 +91,9 @@ export class VariantSelectorComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const selected =
|
const selected =
|
||||||
variants.find((variant) => Object.is(variant.value, selectedVariant)) ?? variants[0];
|
variants.find((variant) => Object.is(variant.id, selectedVariant)) ?? variants[0];
|
||||||
this.selectedValues.set({ ...selected.values });
|
this.selectedValues.set({ ...selected.values });
|
||||||
if (!Object.is(selected.value, selectedVariant)) this.selectedVariant.set(selected.value);
|
if (!Object.is(selected.id, selectedVariant)) this.selectedVariant.set(selected.id);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -128,7 +128,7 @@ export class VariantSelectorComponent {
|
|||||||
);
|
);
|
||||||
|
|
||||||
this.selectedValues.set(values);
|
this.selectedValues.set(values);
|
||||||
this.selectedVariant.set(matchingVariant?.value ?? null);
|
this.selectedVariant.set(matchingVariant?.id ?? null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private optionsFor(variants: VariantSelectorVariant[], key: string): VariantSelectorOption[] {
|
private optionsFor(variants: VariantSelectorVariant[], key: string): VariantSelectorOption[] {
|
||||||
|
|||||||
Reference in New Issue
Block a user