wip
This commit is contained in:
73
lib/data.ts
73
lib/data.ts
@@ -3,6 +3,7 @@
|
||||
*/
|
||||
|
||||
import wordpressData from '../data/processed/wordpress-data.json';
|
||||
import { getExcelTechnicalDataForProduct } from './excel-products';
|
||||
|
||||
export interface SiteInfo {
|
||||
title: string;
|
||||
@@ -69,6 +70,12 @@ export interface Product {
|
||||
variations: any[];
|
||||
updatedAt: string;
|
||||
translation: TranslationReference | null;
|
||||
// Excel-derived technical data
|
||||
excelConfigurations?: string[];
|
||||
excelAttributes?: Array<{
|
||||
name: string;
|
||||
options: string[];
|
||||
}>;
|
||||
}
|
||||
|
||||
export interface ProductCategory {
|
||||
@@ -279,4 +286,68 @@ export const getPostsForLocale = (locale: string): Post[] => {
|
||||
|
||||
export const getProductsForLocale = (locale: string): Product[] => {
|
||||
return data.content.products.filter(p => p.locale === locale);
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Enrich a product with Excel-derived technical data
|
||||
* This function merges Excel data into the product's attributes
|
||||
*/
|
||||
export function enrichProductWithExcelData(product: Product): Product {
|
||||
// Skip if already enriched
|
||||
if (product.excelConfigurations || product.excelAttributes) {
|
||||
return product;
|
||||
}
|
||||
|
||||
const excelData = getExcelTechnicalDataForProduct({
|
||||
name: product.name,
|
||||
slug: product.slug,
|
||||
sku: product.sku,
|
||||
translationKey: product.translationKey,
|
||||
});
|
||||
|
||||
if (!excelData) {
|
||||
return product;
|
||||
}
|
||||
|
||||
// Create a copy of the product with Excel data
|
||||
const enrichedProduct: Product = {
|
||||
...product,
|
||||
excelConfigurations: excelData.configurations,
|
||||
excelAttributes: excelData.attributes,
|
||||
};
|
||||
|
||||
return enrichedProduct;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single product by slug with Excel enrichment
|
||||
*/
|
||||
export function getProductBySlugWithExcel(slug: string, locale: string): Product | undefined {
|
||||
const product = getProductBySlug(slug, locale);
|
||||
if (!product) return undefined;
|
||||
return enrichProductWithExcelData(product);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all products for a locale with Excel enrichment
|
||||
*/
|
||||
export function getProductsForLocaleWithExcel(locale: string): Product[] {
|
||||
const products = getProductsForLocale(locale);
|
||||
return products.map(p => enrichProductWithExcelData(p));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get products by category with Excel enrichment
|
||||
*/
|
||||
export function getProductsByCategoryWithExcel(categoryId: number, locale: string): Product[] {
|
||||
const products = getProductsByCategory(categoryId, locale);
|
||||
return products.map(p => enrichProductWithExcelData(p));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get products by category slug with Excel enrichment
|
||||
*/
|
||||
export function getProductsByCategorySlugWithExcel(categorySlug: string, locale: string): Product[] {
|
||||
const products = getProductsByCategorySlug(categorySlug, locale);
|
||||
return products.map(p => enrichProductWithExcelData(p));
|
||||
}
|
||||
Reference in New Issue
Block a user