feat(catalog): fetch options for partial variant selections

This commit is contained in:
2026-08-14 09:43:47 -03:00
parent 0defe75adb
commit 15979874ce
3 changed files with 36 additions and 4 deletions

View File

@@ -117,6 +117,14 @@ export interface CatalogFeaturedItemVariant {
values: Record<string, CatalogVariantValue>;
}
export interface CatalogVariantOptionsResponse {
variants: CatalogFeaturedItemVariant[];
options: Record<string, CatalogVariantValue[]>;
selected_values: Record<string, string | string[]>;
resolved_variant_id: number | null;
valid: boolean;
}
export interface CatalogFeaturedItem {
id: number;
type: CatalogItemType;

View File

@@ -12,6 +12,7 @@ import {
CatalogFeaturedItem,
CatalogFeaturedItems,
CatalogItemDetail,
CatalogVariantOptionsResponse,
CategoryItemsResponse,
Product,
} from './catalog.interface';
@@ -74,10 +75,7 @@ export class CatalogService extends BaseApiService {
);
}
getCatalogItem(
id: number,
variantId?: number,
): Observable<CatalogItemDetail> {
getCatalogItem(id: number, variantId?: number): Observable<CatalogItemDetail> {
let params = new HttpParams();
if (variantId) {
params = params.set('variant_id', variantId);
@@ -90,6 +88,21 @@ export class CatalogService extends BaseApiService {
.pipe(map((response) => response.data));
}
getVariantOptions(
catalogItemId: number,
payload: {
selected_values: Record<string, string | string[]>;
excluded_variant_ids?: number[];
cart_item_id?: number | null;
},
): Observable<CatalogVariantOptionsResponse> {
return this.http
.post<
ApiResponse<CatalogVariantOptionsResponse>
>(`${this.tenantApiUrl}/catalog-items/${catalogItemId}/variant-options`, payload, { withCredentials: true })
.pipe(map((response) => response.data));
}
private buildHttpParams(params?: ApiPaginationQueryParams): HttpParams {
if (!params) {
return new HttpParams();