HooStore-UI/mock-backend/fixtures.js
2026-10-27 15:09:07 +07:00

334 lines
8.3 KiB
JavaScript

/**
* Fixture data for the mock Medusa Store API.
*
* Shapes mirror what `@medusajs/js-sdk` expects from a real Medusa v2 store
* so the storefront can be developed and demoed without a running backend.
*/
const REGION = {
id: "reg_01",
name: "United States",
currency_code: "usd",
countries: [
{
iso_2: "us",
iso_3: "usa",
display_name: "United States",
name: "united states",
num_code: 840,
region_id: "reg_01",
},
],
}
const APPAREL_IMG = "/apparel_collection.png"
const BAGS_IMG = "/bags_collection.png"
// --- Categories -------------------------------------------------------------
// Declared flat, then linked into a parent/child tree below.
const CATEGORY_DEFS = [
{
id: "cat_ready_to_wear",
name: "Ready-to-Wear",
handle: "ready-to-wear",
description: "Tailoring, knitwear and everyday pieces.",
parent_id: null,
},
{
id: "cat_dresses",
name: "Dresses",
handle: "dresses",
description: "Day and evening dresses.",
parent_id: "cat_ready_to_wear",
},
{
id: "cat_knitwear",
name: "Knitwear",
handle: "knitwear",
description: "Cashmere, wool and cotton knits.",
parent_id: "cat_ready_to_wear",
},
{
id: "cat_outerwear",
name: "Outerwear",
handle: "outerwear",
description: "Coats, jackets and tailoring.",
parent_id: "cat_ready_to_wear",
},
{
id: "cat_bags",
name: "Bags",
handle: "bags",
description: "Bags and leather goods.",
parent_id: null,
},
{
id: "cat_totes",
name: "Totes",
handle: "totes",
description: "Structured and soft totes.",
parent_id: "cat_bags",
},
{
id: "cat_shoulder_bags",
name: "Shoulder Bags",
handle: "shoulder-bags",
description: "Shoulder and crossbody bags.",
parent_id: "cat_bags",
},
{
id: "cat_mini_bags",
name: "Mini Bags",
handle: "mini-bags",
description: "Compact evening and day bags.",
parent_id: "cat_bags",
},
{
id: "cat_accessories",
name: "Accessories",
handle: "accessories",
description: "Small leather goods and finishing pieces.",
parent_id: null,
},
]
const CATEGORIES = CATEGORY_DEFS.map((def) => ({
id: def.id,
name: def.name,
handle: def.handle,
description: def.description,
category_children: [],
parent_category: null,
}))
const CATEGORY_BY_ID = new Map(CATEGORIES.map((c) => [c.id, c]))
CATEGORY_DEFS.forEach((def) => {
if (!def.parent_id) {
return
}
const child = CATEGORY_BY_ID.get(def.id)
const parent = CATEGORY_BY_ID.get(def.parent_id)
// Parent references are trimmed to avoid a circular structure that
// JSON.stringify cannot serialise.
child.parent_category = {
id: parent.id,
name: parent.name,
handle: parent.handle,
parent_category: null,
}
parent.category_children.push({
id: child.id,
name: child.name,
handle: child.handle,
})
})
// --- Collections ------------------------------------------------------------
const COLLECTIONS = [
{ id: "col_summer_edit", title: "The Summer Edit", handle: "summer-edit" },
{ id: "col_signatures", title: "Signatures", handle: "signatures" },
{ id: "col_leather_goods", title: "Leather Goods", handle: "leather-goods" },
]
// --- Products ---------------------------------------------------------------
const SIZES = ["S", "M", "L"]
const PRODUCT_OPTIONS = (colors) => [
{
id: "opt_size",
title: "Size",
values: SIZES.map((value) => ({ value })),
},
{
id: "opt_color",
title: "Color",
values: colors.map((value) => ({ value })),
},
]
function makeVariants(id, basePrice, colors) {
const variants = []
SIZES.forEach((size) => {
colors.forEach((color) => {
variants.push({
id: `variant_${id}_${size}_${color}`.toLowerCase().replace(/\s+/g, "-"),
title: `${size} / ${color}`,
sku: `${id.toUpperCase()}-${size}-${color.slice(0, 3).toUpperCase()}`,
manage_inventory: true,
allow_backorder: false,
inventory_quantity: 10,
options: [
{ option_id: "opt_size", value: size },
{ option_id: "opt_color", value: color },
],
calculated_price: {
calculated_amount: basePrice,
original_amount: basePrice,
currency_code: REGION.currency_code,
calculated_price: { price_list_type: "default" },
},
images: [],
})
})
})
return variants
}
function makeProduct({
id,
title,
handle,
description,
thumbnail,
price,
categoryId,
collectionId,
material,
colors,
}) {
const category = CATEGORY_BY_ID.get(categoryId)
return {
id,
title,
handle,
description,
thumbnail,
material,
status: "published",
created_at: "2026-01-01T00:00:00.000Z",
updated_at: "2026-01-01T00:00:00.000Z",
images: [
{ id: `img_${id}_1`, url: thumbnail },
{ id: `img_${id}_2`, url: thumbnail },
],
options: PRODUCT_OPTIONS(colors),
variants: makeVariants(id, price, colors),
categories: category
? [{ id: category.id, name: category.name, handle: category.handle }]
: [],
collection_id: collectionId,
collection: COLLECTIONS.find((c) => c.id === collectionId) ?? null,
tags: [],
metadata: {},
}
}
const PRODUCTS = [
makeProduct({
id: "prod_1",
title: "Wool Tailored Blazer",
handle: "wool-tailored-blazer",
description: "Structured wool blazer with a tailored silhouette.",
thumbnail: APPAREL_IMG,
price: 1890,
categoryId: "cat_outerwear",
collectionId: "col_signatures",
material: "Wool",
colors: ["Black", "Camel"],
}),
makeProduct({
id: "prod_2",
title: "Silk Midi Dress",
handle: "silk-midi-dress",
description: "Fluid silk dress with a modern midi length.",
thumbnail: APPAREL_IMG,
price: 1290,
categoryId: "cat_dresses",
collectionId: "col_summer_edit",
material: "Silk",
colors: ["Ivory", "Black"],
}),
makeProduct({
id: "prod_3",
title: "Cashmere Knit Sweater",
handle: "cashmere-knit-sweater",
description: "Soft cashmere knit in a relaxed fit.",
thumbnail: APPAREL_IMG,
price: 980,
categoryId: "cat_knitwear",
collectionId: "col_signatures",
material: "Cashmere",
colors: ["Grey", "Camel"],
}),
makeProduct({
id: "prod_4",
title: "Quilted Leather Shoulder Bag",
handle: "quilted-leather-shoulder-bag",
description: "Quilted leather shoulder bag with a chain strap.",
thumbnail: BAGS_IMG,
price: 2590,
categoryId: "cat_shoulder_bags",
collectionId: "col_leather_goods",
material: "Leather",
colors: ["Black", "Cognac"],
}),
makeProduct({
id: "prod_5",
title: "Leather Tote Bag",
handle: "leather-tote-bag",
description: "Spacious leather tote for everyday carry.",
thumbnail: BAGS_IMG,
price: 2190,
categoryId: "cat_totes",
collectionId: "col_leather_goods",
material: "Leather",
colors: ["Cognac", "Ivory"],
}),
makeProduct({
id: "prod_6",
title: "Mini Crossbody Bag",
handle: "mini-crossbody-bag",
description: "Compact crossbody bag in smooth leather.",
thumbnail: BAGS_IMG,
price: 1490,
categoryId: "cat_mini_bags",
collectionId: "col_leather_goods",
material: "Leather",
colors: ["Black", "Ivory"],
}),
makeProduct({
id: "prod_7",
title: "Raffia Summer Tote",
handle: "raffia-summer-tote",
description: "Hand-woven raffia tote with leather handles.",
thumbnail: BAGS_IMG,
price: 890,
categoryId: "cat_totes",
collectionId: "col_summer_edit",
material: "Raffia",
colors: ["Natural"],
}),
makeProduct({
id: "prod_8",
title: "Leather Card Holder",
handle: "leather-card-holder",
description: "Slim card holder in grained leather.",
thumbnail: BAGS_IMG,
price: 290,
categoryId: "cat_accessories",
collectionId: "col_leather_goods",
material: "Leather",
colors: ["Black", "Cognac"],
}),
makeProduct({
id: "prod_9",
title: "Linen Shirt Dress",
handle: "linen-shirt-dress",
description: "Relaxed linen shirt dress for warm days.",
thumbnail: APPAREL_IMG,
price: 740,
categoryId: "cat_dresses",
collectionId: "col_summer_edit",
material: "Linen",
colors: ["Ivory", "Sky"],
}),
]
module.exports = { REGION, CATEGORIES, COLLECTIONS, PRODUCTS }