update
This commit is contained in:
16
src/lib/product/productdetail/index.ts
Normal file
16
src/lib/product/productdetail/index.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { ProductDetailData } from '@/types';
|
||||
|
||||
// Hàm helper để lấy URL an toàn từ các cấu trúc dữ liệu khác nhau
|
||||
function getSlug(url: string): string {
|
||||
const parts = url.split('/').filter(Boolean);
|
||||
return parts[parts.length - 1];
|
||||
}
|
||||
|
||||
export function findProductDetailBySlug(
|
||||
slug: string,
|
||||
ProductDetail: ProductDetailData[],
|
||||
): ProductDetailData | null {
|
||||
const found = ProductDetail.find((item) => item.product_info.productUrl === slug);
|
||||
|
||||
return found ?? null;
|
||||
}
|
||||
Reference in New Issue
Block a user