mucahitkantepe commited on
Commit
a9fc7b2
·
1 Parent(s): 3ef384e

add Shop the look outfit composition

Browse files

- taste/outfits.py: pairing rules per anchor bucket
(dress→shoes+bag+outerwear, top→bottom+shoes+bag, etc.)
picks top-scored in-stock complement per bucket, deduped by
(brand, name) to avoid variant spam
- GET /api/products/outfit?url= returns anchor + complements + total
- frontend OutfitModal: hover "Shop the look" pill on each pairable
card, opens a dark modal with the curated edit and run-total

backend/app/routers/products.py CHANGED
@@ -2,10 +2,11 @@
2
 
3
  import json
4
 
5
- from fastapi import APIRouter, Query
6
 
7
  from backend.app.deps import get_store
8
- from backend.app.schemas import ProductOut, ProductsResponse
 
9
 
10
  router = APIRouter(prefix="/api/products", tags=["products"])
11
 
@@ -62,7 +63,8 @@ def _row_to_product(row) -> ProductOut:
62
 
63
  # Ensure string fields are never None
64
  for str_field in ("brand", "name", "color", "material", "category", "price_text",
65
- "currency", "image_url", "url", "store", "external_id"):
 
66
  if d.get(str_field) is None:
67
  d[str_field] = ""
68
 
@@ -224,3 +226,27 @@ def price_range():
224
  FROM products WHERE price_nok > 0 AND score IS NOT NULL
225
  """).fetchone()
226
  return {"min": row["min_price"] or 0, "max": row["max_price"] or 0}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  import json
4
 
5
+ from fastapi import APIRouter, HTTPException, Query
6
 
7
  from backend.app.deps import get_store
8
+ from backend.app.schemas import OutfitComplement, OutfitResponse, ProductOut, ProductsResponse
9
+ from taste.outfits import compose_outfit
10
 
11
  router = APIRouter(prefix="/api/products", tags=["products"])
12
 
 
63
 
64
  # Ensure string fields are never None
65
  for str_field in ("brand", "name", "color", "material", "category", "price_text",
66
+ "currency", "image_url", "url", "store", "external_id",
67
+ "canonical_category"):
68
  if d.get(str_field) is None:
69
  d[str_field] = ""
70
 
 
226
  FROM products WHERE price_nok > 0 AND score IS NOT NULL
227
  """).fetchone()
228
  return {"min": row["min_price"] or 0, "max": row["max_price"] or 0}
229
+
230
+
231
+ @router.get("/outfit", response_model=OutfitResponse)
232
+ def get_outfit(url: str = Query(..., description="Anchor product URL")):
233
+ """Build a stylist's outfit around an anchor product.
234
+
235
+ Returns the anchor + complementary pieces (shoes, bag, outerwear, etc.)
236
+ drawn from the user's top-scored in-stock catalog. Pairing rules per
237
+ bucket live in `taste.outfits.PAIRING_RULES`.
238
+ """
239
+ db = get_store()
240
+ out = compose_outfit(url, db.conn)
241
+ if out is None:
242
+ raise HTTPException(status_code=404, detail="Anchor product not found")
243
+
244
+ return OutfitResponse(
245
+ anchor=_row_to_product(out["anchor"]),
246
+ anchor_bucket=out["anchor_bucket"],
247
+ complements=[
248
+ OutfitComplement(bucket=c["bucket"], product=_row_to_product(c["product"]))
249
+ for c in out["complements"]
250
+ ],
251
+ total_nok=out["total_nok"],
252
+ )
backend/app/schemas.py CHANGED
@@ -22,6 +22,19 @@ class ProductOut(BaseModel):
22
  in_stock: bool = True
23
  sizes: list[str] = []
24
  external_id: str = ""
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
 
27
  class ProductsResponse(BaseModel):
 
22
  in_stock: bool = True
23
  sizes: list[str] = []
24
  external_id: str = ""
25
+ canonical_category: str = ""
26
+
27
+
28
+ class OutfitComplement(BaseModel):
29
+ bucket: str
30
+ product: ProductOut
31
+
32
+
33
+ class OutfitResponse(BaseModel):
34
+ anchor: ProductOut
35
+ anchor_bucket: str
36
+ complements: list[OutfitComplement]
37
+ total_nok: float
38
 
39
 
40
  class ProductsResponse(BaseModel):
frontend/src/api.ts CHANGED
@@ -1,4 +1,5 @@
1
  import type {
 
2
  Product,
3
  ProductsResponse,
4
  StoreInfo,
@@ -132,3 +133,7 @@ export async function undoDiscoverRating(): Promise<{
132
  export async function getDiscoverStats(): Promise<DiscoverStats> {
133
  return request<DiscoverStats>("/discover/stats");
134
  }
 
 
 
 
 
1
  import type {
2
+ Outfit,
3
  Product,
4
  ProductsResponse,
5
  StoreInfo,
 
133
  export async function getDiscoverStats(): Promise<DiscoverStats> {
134
  return request<DiscoverStats>("/discover/stats");
135
  }
136
+
137
+ export async function getOutfit(url: string): Promise<Outfit> {
138
+ return request<Outfit>(`/products/outfit?url=${encodeURIComponent(url)}`);
139
+ }
frontend/src/components/OutfitModal.tsx ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { useEffect, useState } from "react";
2
+ import { getOutfit } from "../api";
3
+ import type { Outfit, Product } from "../types";
4
+
5
+ const PLACEHOLDER =
6
+ "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Crect fill='%23262626' width='100' height='100'/%3E%3Ctext x='50' y='55' text-anchor='middle' fill='%23737373' font-size='12'%3ENo Image%3C/text%3E%3C/svg%3E";
7
+
8
+ const BUCKET_LABEL: Record<string, string> = {
9
+ top: "Top",
10
+ bottom: "Bottom",
11
+ dress: "Dress",
12
+ outerwear: "Outerwear",
13
+ shoes: "Shoes",
14
+ bag: "Bag",
15
+ accessory: "Accessory",
16
+ intimates: "Intimates",
17
+ swimwear: "Swimwear",
18
+ };
19
+
20
+ function bucketLabel(b: string) {
21
+ return BUCKET_LABEL[b] ?? b;
22
+ }
23
+
24
+ interface Props {
25
+ anchorUrl: string;
26
+ onClose: () => void;
27
+ }
28
+
29
+ function OutfitTile({ p, label, isAnchor = false }: { p: Product; label: string; isAnchor?: boolean }) {
30
+ return (
31
+ <a
32
+ className={`outfit-tile${isAnchor ? " anchor" : ""}`}
33
+ href={p.url}
34
+ target="_blank"
35
+ rel="noopener noreferrer"
36
+ >
37
+ <div className="outfit-tile-label">{label}</div>
38
+ <div className="outfit-tile-img-wrap">
39
+ <img
40
+ className="outfit-tile-img"
41
+ src={p.image_url}
42
+ alt={p.name}
43
+ onError={(e) => {
44
+ (e.target as HTMLImageElement).src = PLACEHOLDER;
45
+ }}
46
+ />
47
+ </div>
48
+ <div className="outfit-tile-body">
49
+ <div className="outfit-tile-brand">{p.brand || p.store}</div>
50
+ <div className="outfit-tile-name">{p.name}</div>
51
+ <div className="outfit-tile-price">
52
+ {p.price_text || `${Math.round(p.price_nok)} kr`}
53
+ </div>
54
+ </div>
55
+ </a>
56
+ );
57
+ }
58
+
59
+ export function OutfitModal({ anchorUrl, onClose }: Props) {
60
+ const [outfit, setOutfit] = useState<Outfit | null>(null);
61
+ const [error, setError] = useState<string | null>(null);
62
+ const [loading, setLoading] = useState(true);
63
+
64
+ useEffect(() => {
65
+ setLoading(true);
66
+ setError(null);
67
+ getOutfit(anchorUrl)
68
+ .then(setOutfit)
69
+ .catch((e) => setError(String(e)))
70
+ .finally(() => setLoading(false));
71
+ }, [anchorUrl]);
72
+
73
+ useEffect(() => {
74
+ function onKey(e: KeyboardEvent) {
75
+ if (e.key === "Escape") onClose();
76
+ }
77
+ window.addEventListener("keydown", onKey);
78
+ return () => window.removeEventListener("keydown", onKey);
79
+ }, [onClose]);
80
+
81
+ return (
82
+ <div className="outfit-modal-backdrop" onClick={onClose}>
83
+ <div className="outfit-modal" onClick={(e) => e.stopPropagation()}>
84
+ <div className="outfit-modal-head">
85
+ <div>
86
+ <h2>Shop the look</h2>
87
+ {outfit && (
88
+ <p className="outfit-modal-subtitle">
89
+ Curated around your top {bucketLabel(outfit.anchor_bucket).toLowerCase()} pick
90
+ </p>
91
+ )}
92
+ </div>
93
+ <button className="outfit-modal-close" onClick={onClose} aria-label="Close">
94
+ ×
95
+ </button>
96
+ </div>
97
+
98
+ {loading && <div className="outfit-modal-state">Building the look…</div>}
99
+ {error && <div className="outfit-modal-state error">Couldn't build outfit: {error}</div>}
100
+
101
+ {outfit && (
102
+ <>
103
+ <div className="outfit-grid">
104
+ <OutfitTile
105
+ p={outfit.anchor}
106
+ label={`The ${bucketLabel(outfit.anchor_bucket).toLowerCase()}`}
107
+ isAnchor
108
+ />
109
+ {outfit.complements.map((c) => (
110
+ <OutfitTile
111
+ key={c.product.url}
112
+ p={c.product}
113
+ label={`+ ${bucketLabel(c.bucket)}`}
114
+ />
115
+ ))}
116
+ </div>
117
+
118
+ {outfit.complements.length === 0 ? (
119
+ <div className="outfit-modal-empty">
120
+ No complements found for this {bucketLabel(outfit.anchor_bucket).toLowerCase()} —
121
+ try one with more catalog coverage.
122
+ </div>
123
+ ) : (
124
+ <div className="outfit-total">
125
+ <span>Total look</span>
126
+ <span className="outfit-total-amount">
127
+ {Math.round(outfit.total_nok).toLocaleString()} kr
128
+ </span>
129
+ </div>
130
+ )}
131
+ </>
132
+ )}
133
+ </div>
134
+ </div>
135
+ );
136
+ }
frontend/src/index.css CHANGED
@@ -1278,3 +1278,230 @@ select:focus {
1278
  font-size: 13px;
1279
  }
1280
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1278
  font-size: 13px;
1279
  }
1280
  }
1281
+
1282
+ /* ============================================================
1283
+ Shop-the-look button + outfit modal
1284
+ ============================================================ */
1285
+
1286
+ .shop-the-look-btn {
1287
+ position: absolute;
1288
+ bottom: 12px;
1289
+ left: 50%;
1290
+ transform: translateX(-50%) translateY(8px);
1291
+ padding: 8px 14px;
1292
+ background: rgba(255, 255, 255, 0.95);
1293
+ color: #111;
1294
+ border: none;
1295
+ border-radius: 999px;
1296
+ font-size: 12px;
1297
+ font-weight: 600;
1298
+ letter-spacing: 0.02em;
1299
+ cursor: pointer;
1300
+ opacity: 0;
1301
+ transition: opacity 0.18s ease, transform 0.18s ease, background 0.15s;
1302
+ white-space: nowrap;
1303
+ z-index: 3;
1304
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
1305
+ }
1306
+
1307
+ .product-card:hover .shop-the-look-btn {
1308
+ opacity: 1;
1309
+ transform: translateX(-50%) translateY(0);
1310
+ }
1311
+
1312
+ .shop-the-look-btn:hover {
1313
+ background: #fff;
1314
+ }
1315
+
1316
+ .outfit-modal-backdrop {
1317
+ position: fixed;
1318
+ inset: 0;
1319
+ background: rgba(0, 0, 0, 0.65);
1320
+ backdrop-filter: blur(4px);
1321
+ display: flex;
1322
+ align-items: center;
1323
+ justify-content: center;
1324
+ z-index: 1000;
1325
+ padding: 24px;
1326
+ animation: outfit-fade-in 0.18s ease-out;
1327
+ }
1328
+
1329
+ @keyframes outfit-fade-in {
1330
+ from { opacity: 0; }
1331
+ to { opacity: 1; }
1332
+ }
1333
+
1334
+ .outfit-modal {
1335
+ background: #1a1a1a;
1336
+ border: 1px solid #2a2a2a;
1337
+ border-radius: 16px;
1338
+ max-width: 1100px;
1339
+ width: 100%;
1340
+ max-height: 90vh;
1341
+ overflow-y: auto;
1342
+ padding: 32px;
1343
+ box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
1344
+ }
1345
+
1346
+ .outfit-modal-head {
1347
+ display: flex;
1348
+ justify-content: space-between;
1349
+ align-items: flex-start;
1350
+ margin-bottom: 24px;
1351
+ }
1352
+
1353
+ .outfit-modal-head h2 {
1354
+ margin: 0 0 4px 0;
1355
+ font-size: 22px;
1356
+ font-weight: 600;
1357
+ color: #fff;
1358
+ }
1359
+
1360
+ .outfit-modal-subtitle {
1361
+ margin: 0;
1362
+ font-size: 13px;
1363
+ color: #999;
1364
+ }
1365
+
1366
+ .outfit-modal-close {
1367
+ background: none;
1368
+ border: none;
1369
+ color: #888;
1370
+ font-size: 28px;
1371
+ line-height: 1;
1372
+ cursor: pointer;
1373
+ padding: 0 8px;
1374
+ transition: color 0.15s;
1375
+ }
1376
+
1377
+ .outfit-modal-close:hover { color: #fff; }
1378
+
1379
+ .outfit-modal-state {
1380
+ padding: 48px 24px;
1381
+ text-align: center;
1382
+ color: #999;
1383
+ font-size: 14px;
1384
+ }
1385
+
1386
+ .outfit-modal-state.error { color: #ef6c6c; }
1387
+
1388
+ .outfit-modal-empty {
1389
+ padding: 24px;
1390
+ text-align: center;
1391
+ color: #888;
1392
+ font-size: 13px;
1393
+ background: #111;
1394
+ border-radius: 10px;
1395
+ margin-top: 8px;
1396
+ }
1397
+
1398
+ .outfit-grid {
1399
+ display: grid;
1400
+ grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
1401
+ gap: 16px;
1402
+ margin-bottom: 24px;
1403
+ }
1404
+
1405
+ .outfit-tile {
1406
+ display: flex;
1407
+ flex-direction: column;
1408
+ background: #111;
1409
+ border: 1px solid #2a2a2a;
1410
+ border-radius: 12px;
1411
+ overflow: hidden;
1412
+ text-decoration: none;
1413
+ color: inherit;
1414
+ transition: border-color 0.15s, transform 0.15s;
1415
+ }
1416
+
1417
+ .outfit-tile:hover {
1418
+ border-color: #4a4a4a;
1419
+ transform: translateY(-2px);
1420
+ }
1421
+
1422
+ .outfit-tile.anchor {
1423
+ border-color: #6f8fff;
1424
+ box-shadow: 0 0 0 2px rgba(111, 143, 255, 0.18);
1425
+ }
1426
+
1427
+ .outfit-tile-label {
1428
+ padding: 8px 12px;
1429
+ font-size: 11px;
1430
+ font-weight: 600;
1431
+ letter-spacing: 0.06em;
1432
+ text-transform: uppercase;
1433
+ color: #999;
1434
+ background: #0c0c0c;
1435
+ border-bottom: 1px solid #1c1c1c;
1436
+ }
1437
+
1438
+ .outfit-tile.anchor .outfit-tile-label { color: #aab9ff; }
1439
+
1440
+ .outfit-tile-img-wrap {
1441
+ position: relative;
1442
+ aspect-ratio: 3 / 4;
1443
+ background: #1c1c1c;
1444
+ overflow: hidden;
1445
+ }
1446
+
1447
+ .outfit-tile-img {
1448
+ width: 100%;
1449
+ height: 100%;
1450
+ object-fit: cover;
1451
+ }
1452
+
1453
+ .outfit-tile-body {
1454
+ padding: 12px;
1455
+ display: flex;
1456
+ flex-direction: column;
1457
+ gap: 4px;
1458
+ }
1459
+
1460
+ .outfit-tile-brand {
1461
+ font-size: 11px;
1462
+ font-weight: 600;
1463
+ text-transform: uppercase;
1464
+ letter-spacing: 0.04em;
1465
+ color: #aaa;
1466
+ }
1467
+
1468
+ .outfit-tile-name {
1469
+ font-size: 13px;
1470
+ color: #ddd;
1471
+ line-height: 1.3;
1472
+ display: -webkit-box;
1473
+ -webkit-line-clamp: 2;
1474
+ -webkit-box-orient: vertical;
1475
+ overflow: hidden;
1476
+ }
1477
+
1478
+ .outfit-tile-price {
1479
+ font-size: 14px;
1480
+ font-weight: 600;
1481
+ color: #fff;
1482
+ margin-top: 4px;
1483
+ }
1484
+
1485
+ .outfit-total {
1486
+ display: flex;
1487
+ justify-content: space-between;
1488
+ align-items: center;
1489
+ padding: 16px 20px;
1490
+ background: #0c0c0c;
1491
+ border: 1px solid #2a2a2a;
1492
+ border-radius: 10px;
1493
+ font-size: 14px;
1494
+ color: #aaa;
1495
+ }
1496
+
1497
+ .outfit-total-amount {
1498
+ font-size: 18px;
1499
+ font-weight: 700;
1500
+ color: #fff;
1501
+ }
1502
+
1503
+ @media (max-width: 600px) {
1504
+ .outfit-modal { padding: 20px; border-radius: 12px; }
1505
+ .outfit-modal-head h2 { font-size: 18px; }
1506
+ .outfit-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
1507
+ }
frontend/src/pages/BrowsePage.tsx CHANGED
@@ -1,7 +1,12 @@
1
  import { useState, useEffect, useCallback } from "react";
2
  import { getProducts, getStores, getBrands, getCategories, getPriceRange } from "../api";
 
3
  import type { Product, StoreInfo } from "../types";
4
 
 
 
 
 
5
  function scoreBadgeClass(score: number): string {
6
  if (score >= 70) return "score-badge green";
7
  if (score >= 40) return "score-badge blue";
@@ -10,10 +15,11 @@ function scoreBadgeClass(score: number): string {
10
 
11
  const PLACEHOLDER = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Crect fill='%23262626' width='100' height='100'/%3E%3Ctext x='50' y='55' text-anchor='middle' fill='%23737373' font-size='12'%3ENo Image%3C/text%3E%3C/svg%3E";
12
 
13
- function ProductCard({ product: p }: { product: Product }) {
14
  const [hoverIdx, setHoverIdx] = useState(0);
15
  const imgs = p.image_urls?.length > 0 ? p.image_urls : [p.image_url];
16
  const matchPct = Math.round(p.score * 100);
 
17
 
18
  return (
19
  <div className="product-card" onMouseLeave={() => setHoverIdx(0)}>
@@ -39,6 +45,19 @@ function ProductCard({ product: p }: { product: Product }) {
39
  ))}
40
  </div>
41
  )}
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  </div>
43
  {p.on_sale && <div className="product-card-sale-badge">Sale</div>}
44
  {!p.in_stock && <div className="product-card-oos-badge">Sold Out</div>}
@@ -82,6 +101,7 @@ export function BrowsePage() {
82
  const [priceRange, setPriceRange] = useState({ min: 0, max: 50000 });
83
  const [loading, setLoading] = useState(true);
84
  const [showFilters, setShowFilters] = useState(false);
 
85
 
86
  useEffect(() => {
87
  getStores().then(setStores).catch(console.error);
@@ -308,10 +328,18 @@ export function BrowsePage() {
308
  <>
309
  <div className="product-grid">
310
  {products.map((p, i) => (
311
- <ProductCard key={`${p.store}-${p.name}-${i}`} product={p} />
 
 
 
 
312
  ))}
313
  </div>
314
 
 
 
 
 
315
  {totalPages > 1 && (
316
  <div className="pagination">
317
  <button disabled={page <= 1} onClick={() => setPage((p) => p - 1)}>
 
1
  import { useState, useEffect, useCallback } from "react";
2
  import { getProducts, getStores, getBrands, getCategories, getPriceRange } from "../api";
3
+ import { OutfitModal } from "../components/OutfitModal";
4
  import type { Product, StoreInfo } from "../types";
5
 
6
+ const PAIRABLE_BUCKETS = new Set([
7
+ "dress", "top", "bottom", "outerwear", "shoes", "bag", "swimwear",
8
+ ]);
9
+
10
  function scoreBadgeClass(score: number): string {
11
  if (score >= 70) return "score-badge green";
12
  if (score >= 40) return "score-badge blue";
 
15
 
16
  const PLACEHOLDER = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Crect fill='%23262626' width='100' height='100'/%3E%3Ctext x='50' y='55' text-anchor='middle' fill='%23737373' font-size='12'%3ENo Image%3C/text%3E%3C/svg%3E";
17
 
18
+ function ProductCard({ product: p, onShopTheLook }: { product: Product; onShopTheLook: (url: string) => void }) {
19
  const [hoverIdx, setHoverIdx] = useState(0);
20
  const imgs = p.image_urls?.length > 0 ? p.image_urls : [p.image_url];
21
  const matchPct = Math.round(p.score * 100);
22
+ const showShopTheLook = PAIRABLE_BUCKETS.has(p.canonical_category);
23
 
24
  return (
25
  <div className="product-card" onMouseLeave={() => setHoverIdx(0)}>
 
45
  ))}
46
  </div>
47
  )}
48
+ {showShopTheLook && (
49
+ <button
50
+ className="shop-the-look-btn"
51
+ onClick={(e) => {
52
+ e.preventDefault();
53
+ e.stopPropagation();
54
+ onShopTheLook(p.url);
55
+ }}
56
+ aria-label="Shop the look"
57
+ >
58
+ Shop the look
59
+ </button>
60
+ )}
61
  </div>
62
  {p.on_sale && <div className="product-card-sale-badge">Sale</div>}
63
  {!p.in_stock && <div className="product-card-oos-badge">Sold Out</div>}
 
101
  const [priceRange, setPriceRange] = useState({ min: 0, max: 50000 });
102
  const [loading, setLoading] = useState(true);
103
  const [showFilters, setShowFilters] = useState(false);
104
+ const [outfitAnchor, setOutfitAnchor] = useState<string | null>(null);
105
 
106
  useEffect(() => {
107
  getStores().then(setStores).catch(console.error);
 
328
  <>
329
  <div className="product-grid">
330
  {products.map((p, i) => (
331
+ <ProductCard
332
+ key={`${p.store}-${p.name}-${i}`}
333
+ product={p}
334
+ onShopTheLook={setOutfitAnchor}
335
+ />
336
  ))}
337
  </div>
338
 
339
+ {outfitAnchor && (
340
+ <OutfitModal anchorUrl={outfitAnchor} onClose={() => setOutfitAnchor(null)} />
341
+ )}
342
+
343
  {totalPages > 1 && (
344
  <div className="pagination">
345
  <button disabled={page <= 1} onClick={() => setPage((p) => p - 1)}>
frontend/src/types.ts CHANGED
@@ -17,6 +17,19 @@ export interface Product {
17
  in_stock: boolean;
18
  sizes: string[];
19
  external_id: string;
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  }
21
 
22
  export interface ProductsResponse {
 
17
  in_stock: boolean;
18
  sizes: string[];
19
  external_id: string;
20
+ canonical_category: string;
21
+ }
22
+
23
+ export interface OutfitComplement {
24
+ bucket: string;
25
+ product: Product;
26
+ }
27
+
28
+ export interface Outfit {
29
+ anchor: Product;
30
+ anchor_bucket: string;
31
+ complements: OutfitComplement[];
32
+ total_nok: number;
33
  }
34
 
35
  export interface ProductsResponse {
taste/outfits.py ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Compose outfits from canonical-bucketed products.
2
+
3
+ Given an anchor SKU (the product the user is viewing), pick the best-matching
4
+ complementary pieces from the catalog so the result reads like a stylist's
5
+ edit rather than an unrelated grid.
6
+
7
+ v1 strategy is intentionally cheap:
8
+ 1. Bucket the anchor (top, dress, etc).
9
+ 2. For each bucket the anchor *needs*, pick the top-scoring in-stock SKU.
10
+ 3. Within a bucket, optionally bias by visual harmony (cosine sim of image
11
+ embeddings to the anchor) — but only if the embedding lookup is fast.
12
+
13
+ No new model, no co-occurrence learning. Layer color / brand cohesion later.
14
+ """
15
+
16
+ from __future__ import annotations
17
+
18
+ # Pairing rules: anchor bucket → ordered list of complement buckets to fill.
19
+ # `None` slots are skipped if the catalog can't fill them. `dress` notably has
20
+ # no `bottom` since it's already a one-piece.
21
+ PAIRING_RULES: dict[str, list[str]] = {
22
+ "dress": ["shoes", "bag", "outerwear"],
23
+ "top": ["bottom", "shoes", "bag"],
24
+ "bottom": ["top", "shoes", "bag"],
25
+ "outerwear": ["dress", "shoes", "bag"],
26
+ "shoes": ["dress", "bag"],
27
+ "bag": ["dress", "shoes"],
28
+ "intimates": [], # not stylist-pairable; suppress
29
+ "swimwear": ["bag"],
30
+ "accessory": [],
31
+ "unknown": [],
32
+ }
33
+
34
+
35
+ def _pick_complement(conn, bucket: str, anchor: dict) -> dict | None:
36
+ """Pick best in-stock product from `bucket`, biased to anchor's price band.
37
+
38
+ Heuristics:
39
+ - filter to `canonical_category = bucket`, in-stock, scored
40
+ - prefer same currency
41
+ - drop the anchor itself if it somehow shares a bucket (e.g. dress→dress)
42
+ - rank by score DESC (already absorbs taste + price + sale biases)
43
+ - dedupe by (brand, name) within the bucket — variants would otherwise
44
+ all win consecutive slots
45
+ """
46
+ row = conn.execute(
47
+ """
48
+ SELECT * FROM (
49
+ SELECT *, ROW_NUMBER() OVER (
50
+ PARTITION BY brand, name ORDER BY score DESC
51
+ ) AS rn
52
+ FROM products
53
+ WHERE canonical_category = ?
54
+ AND in_stock = 1
55
+ AND score IS NOT NULL
56
+ AND score > 0
57
+ AND url != ?
58
+ AND image_url != ''
59
+ ) WHERE rn = 1
60
+ ORDER BY score DESC
61
+ LIMIT 1
62
+ """,
63
+ (bucket, anchor.get("url", "")),
64
+ ).fetchone()
65
+ return dict(row) if row else None
66
+
67
+
68
+ def compose_outfit(anchor_url: str, conn) -> dict | None:
69
+ """Build an outfit around `anchor_url`. Returns None if anchor not found.
70
+
71
+ Returns:
72
+ {
73
+ "anchor": <product dict>,
74
+ "anchor_bucket": "dress",
75
+ "complements": [
76
+ {"bucket": "shoes", "product": <dict>},
77
+ {"bucket": "bag", "product": <dict>},
78
+ ...
79
+ ],
80
+ "total_nok": 4530.0,
81
+ }
82
+ """
83
+ anchor_row = conn.execute(
84
+ "SELECT * FROM products WHERE url = ?", (anchor_url,)
85
+ ).fetchone()
86
+ if not anchor_row:
87
+ return None
88
+ anchor = dict(anchor_row)
89
+ bucket = anchor.get("canonical_category") or "unknown"
90
+
91
+ complements = []
92
+ total = float(anchor.get("price_nok") or 0)
93
+ for comp_bucket in PAIRING_RULES.get(bucket, []):
94
+ prod = _pick_complement(conn, comp_bucket, anchor)
95
+ if prod:
96
+ complements.append({"bucket": comp_bucket, "product": prod})
97
+ total += float(prod.get("price_nok") or 0)
98
+
99
+ return {
100
+ "anchor": anchor,
101
+ "anchor_bucket": bucket,
102
+ "complements": complements,
103
+ "total_nok": total,
104
+ }