File size: 46,879 Bytes
d259c1a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 | """Synthetic, locally authored catalog for the ace-hardware offline clone.
Clean-room data. The taxonomy shape (departments -> categories -> leaf
categories), sort options, facet groups, page sizes and the URL patterns
mirror structures directly observed by EA1/EA2 in sanitized evidence.
Two product identities (4007532, 4009449) reproduce directly observed
name/SKU facts; every description, image and all remaining products are
locally invented. No source text, markup, style or image bytes are copied.
"""
from __future__ import annotations
import hashlib
from typing import Any
SORT_OPTIONS: list[dict[str, str]] = [
{"id": "", "label": "Recommended"},
{"id": "price asc", "label": "Price: Low to High"},
{"id": "price desc", "label": "Price: High to Low"},
{"id": "name asc", "label": "Alphabetical: A-Z"},
{"id": "name desc", "label": "Alphabetical: Z-A"},
{"id": "newest", "label": "Date Added: Most Recent First"},
{"id": "oldest", "label": "Date Added: Most Recent Last"},
]
PAGE_SIZES = [15, 30, 46, 50] # "All" is expressed as pageSize=0
DEFAULT_PAGE_SIZE = 30
FACET_GROUPS = [
"Get It Fast",
"Departments",
"Brand Name",
"Price",
"Special Offers",
"Customer Rating",
]
PRICE_BUCKETS = [
{"id": "0-25", "label": "Under $25", "min": 0, "max": 2500},
{"id": "25-50", "label": "$25 - $50", "min": 2500, "max": 5000},
{"id": "50-100", "label": "$50 - $100", "min": 5000, "max": 10000},
{"id": "100-", "label": "$100 & Above", "min": 10000, "max": 10**9},
]
DEPARTMENTS: dict[str, dict[str, Any]] = {
"plumbing": {
"name": "Plumbing",
"blurb": "Everything to repair, replace and upgrade the water lines, "
"fixtures and drains in your home.",
"categories": {
"plumbing-tools": {
"name": "Plumbing Tools",
"leaves": {
"plumbing-wrenches": "Plumbing Wrenches",
"pipe-cutters": "Pipe and Tubing Cutters",
"drain-cleaning-tools": "Drain Cleaning Tools",
"plumbing-tool-kits": "Plumbing Tool Kits",
},
},
"pipe": {
"name": "Pipe",
"leaves": {"pex-pipe": "PEX Pipe", "copper-pipe": "Copper Pipe"},
},
"pipe-fittings": {
"name": "Pipe Fittings",
"leaves": {
"push-fittings": "Push-to-Connect Fittings",
"threaded-fittings": "Threaded Fittings",
},
},
"faucet-and-faucet-repair": {
"name": "Faucet and Faucet Repair",
"leaves": {"faucet-parts": "Faucet Parts", "kitchen-faucets": "Kitchen Faucets"},
},
"drain-openers": {
"name": "Drain Openers",
"leaves": {"chemical": "Chemical Drain Openers", "plungers": "Plungers"},
},
"supply-lines": {
"name": "Supply Lines",
"leaves": {"faucet-supply": "Faucet Supply Lines", "toilet-supply": "Toilet Supply Lines"},
},
},
},
"tools": {
"name": "Tools",
"blurb": "Hand tools, power tools and tool storage for every project.",
"categories": {
"hand-tools": {
"name": "Hand Tools",
"leaves": {
"wrenches": "Wrenches",
"pliers": "Pliers",
"tool-sets": "Tool Sets",
},
},
"power-tools": {
"name": "Power Tools",
"leaves": {"drills": "Drills", "saws": "Saws"},
},
},
},
"paint-and-supplies": {
"name": "Paint and Supplies",
"blurb": "Interior and exterior paint, stain, brushes and supplies.",
"categories": {
"interior-paint": {
"name": "Interior Paint",
"leaves": {"wall-paint": "Wall Paint", "primer": "Primer"},
},
},
},
"hardware": {
"name": "Hardware",
"blurb": "Fasteners, door hardware, picture hanging and more.",
"categories": {
"fasteners": {
"name": "Fasteners",
"leaves": {"screws": "Screws", "anchors": "Anchors"},
},
},
},
"outdoor-living": {
"name": "Outdoor Living",
"blurb": "Grills, patio and backyard gear.",
"categories": {
"grills": {
"name": "Grills and Smokers",
"leaves": {"gas-grills": "Gas Grills", "charcoal-grills": "Charcoal Grills"},
},
"coolers": {
"name": "Coolers",
"leaves": {"hard-sided-coolers": "Hard-Sided Coolers"},
},
},
},
"heating-and-cooling": {
"name": "Heating and Cooling",
"blurb": "Fans, air conditioners and home comfort equipment.",
"categories": {
"portable-and-exhaust-fans": {
"name": "Portable and Exhaust Fans",
"leaves": {"household-fans": "Household Fans"},
},
"air-conditioners-and-coolers": {
"name": "Air Conditioners and Coolers",
"leaves": {"ductless-mini-splits": "Ductless Mini Splits"},
},
},
},
"home-and-decor": {
"name": "Home and Decor",
"blurb": "Kitchen, cleaning and everyday home essentials.",
"categories": {
"kitchen-utensils-and-gadgets": {
"name": "Kitchen Utensils and Gadgets",
"leaves": {
"water-bottles-and-travel-mugs": "Water Bottles and Travel Mugs"
},
},
},
},
"lawn-and-garden": {
"name": "Lawn and Garden",
"blurb": "Lawn care, watering and garden tools.",
"categories": {
"watering": {
"name": "Watering and Irrigation",
"leaves": {"hoses": "Garden Hoses", "sprinklers": "Sprinklers"},
},
},
},
}
def _p(
sku: str,
slug: str,
name: str,
brand: str,
price: int,
dept: str,
cat: str,
leaf: str,
*,
was: int | None = None,
rating: float = 0.0,
reviews: int = 0,
stock: str = "in-stock",
badge: str | None = None,
keywords: str = "",
added: int = 0,
description: str = "",
bullets: list[str] | None = None,
specs: dict[str, str] | None = None,
variants: list[dict[str, Any]] | None = None,
images: int = 3,
evidence: str = "synthetic",
) -> dict[str, Any]:
return {
"sku": sku,
"slug": slug,
"name": name,
"brand": brand,
"price_minor": price,
"was_price_minor": was,
"department": dept,
"category": cat,
"leaf": leaf,
"rating": rating,
"review_count": reviews,
"stock": stock, # in-stock | low-stock | out-of-stock | online-only
"badge": badge,
"keywords": keywords,
"added_order": added,
"description": description,
"bullets": bullets or [],
"specs": specs or {},
"variants": variants or [],
"image_count": images,
"evidence": evidence,
}
PRODUCTS: list[dict[str, Any]] = [
# Current public PDP captured in the isolated Mac source session (task 62).
# Only public catalogue facts are retained; store/account state stays synthetic.
_p(
"4826053",
"milwaukee-m18-short-throw-press-w-3-pex-crimp-jaws-1-in-press-tool-kit-red",
"Milwaukee M18 Short Throw Press w/ 3 PEX Crimp Jaws 1 in. Press Tool Kit Red",
"Milwaukee",
79900,
"plumbing",
"plumbing-tools",
"pipe-cutters",
rating=4.8,
reviews=6,
added=41,
badge="Special Offer",
keywords="milwaukee m18 press tool pex crimp jaws pipe cutter 2674-22c",
description=(
"A compact M18 short-throw press tool kit supplied with three PEX "
"crimp jaws for common residential plumbing work."
),
bullets=[
"Includes 1/2 in., 3/4 in. and 1 in. PEX crimp jaws",
"Cordless M18 platform",
"Kit includes carrying case, battery and charger",
],
specs={"Manufacturer number": "2674-22C", "Maximum capacity": "1 in."},
images=1,
evidence="directly-observed-public-task62-20260824",
),
# --- Plumbing wrenches -------------------------------------------------
_p(
"4007532",
"milwaukee-pipe-wrench-14-in-l-1-pc",
"Milwaukee Pipe Wrench 14 in. L 1 pc",
"Milwaukee",
5299,
"plumbing",
"plumbing-tools",
"plumbing-wrenches",
rating=4.7,
reviews=3,
added=40,
keywords="pipe wrench steel heavy duty plumbing 14 inch",
description=(
"A 14 inch straight pipe wrench built for daily service work. The "
"forged jaw keeps a firm grip on iron pipe and threaded fittings, "
"and the adjustment nut spins smoothly with one thumb."
),
bullets=[
"14 in. overall length",
"Forged, replaceable steel jaws",
"I-beam handle with hang hole",
"Full-floating hook jaw for fast one-hand adjustment",
],
specs={
"Length": "14 in.",
"Jaw capacity": "2 in.",
"Material": "Forged steel",
"Handle": "I-beam",
},
variants=[
{"sku": "4007530", "label": "10 in."},
{"sku": "4007532", "label": "14 in."},
{"sku": "4007534", "label": "18 in."},
],
evidence="observed-name-sku-price",
),
_p(
"4007530",
"milwaukee-pipe-wrench-10-in-l-1-pc",
"Milwaukee Pipe Wrench 10 in. L 1 pc",
"Milwaukee",
4399,
"plumbing",
"plumbing-tools",
"plumbing-wrenches",
rating=4.5,
reviews=8,
added=39,
keywords="pipe wrench compact plumbing 10 inch",
description=(
"The 10 inch member of the same forged pipe wrench family, sized "
"for supply lines and tight cabinet work."
),
bullets=["10 in. overall length", "Forged steel jaws", "Hang hole"],
specs={"Length": "10 in.", "Jaw capacity": "1.5 in."},
variants=[
{"sku": "4007530", "label": "10 in."},
{"sku": "4007532", "label": "14 in."},
{"sku": "4007534", "label": "18 in."},
],
),
_p(
"4007534",
"milwaukee-pipe-wrench-18-in-l-1-pc",
"Milwaukee Pipe Wrench 18 in. L 1 pc",
"Milwaukee",
6899,
"plumbing",
"plumbing-tools",
"plumbing-wrenches",
rating=4.8,
reviews=5,
added=38,
stock="low-stock",
keywords="pipe wrench large plumbing 18 inch",
description=(
"An 18 inch pipe wrench with the leverage for stubborn, corroded "
"joints on larger diameter pipe."
),
bullets=["18 in. overall length", "Forged steel jaws", "High-leverage handle"],
specs={"Length": "18 in.", "Jaw capacity": "2.5 in."},
variants=[
{"sku": "4007530", "label": "10 in."},
{"sku": "4007532", "label": "14 in."},
{"sku": "4007534", "label": "18 in."},
],
),
_p(
"4009449",
"superior-tool-pipe-wrench-plier-black-red-3-pc",
"Superior Tool Pipe Wrench Plier Black/Red 3 pc",
"Superior Tool",
3999,
"plumbing",
"plumbing-tools",
"plumbing-wrenches",
rating=4.4,
reviews=12,
added=37,
badge="Best Seller",
keywords="pipe wrench set pliers three piece plumbing kit",
description=(
"A three piece pipe wrench and plier set that covers most "
"household plumbing jobs: two slip-jaw pipe wrenches plus a "
"groove-joint plier in a single set."
),
bullets=[
"3 pc set: 10 in. and 14 in. pipe wrenches plus 12 in. plier",
"Slip-resistant grips",
"Corrosion-resistant finish",
],
specs={"Pieces": "3", "Finish": "Black/Red", "Largest wrench": "14 in."},
evidence="observed-name-sku",
),
_p(
"4010101",
"ace-adjustable-pipe-wrench-set-2-pc",
"Ace Adjustable Pipe Wrench Set 2 pc",
"Ace",
2999,
"plumbing",
"plumbing-tools",
"plumbing-wrenches",
was=3599,
rating=4.2,
reviews=21,
added=36,
badge="Sale",
keywords="pipe wrench set two piece adjustable value",
description=(
"A two piece cast pipe wrench set sized for everyday repairs "
"under sinks and behind toilets."
),
bullets=["8 in. and 12 in. wrenches", "Epoxy-coated handles"],
specs={"Pieces": "2", "Sizes": "8 in., 12 in."},
),
_p(
"4010102",
"superior-tool-aluminum-pipe-wrench-24-in",
"Superior Tool Aluminum Pipe Wrench 24 in. L",
"Superior Tool",
8999,
"plumbing",
"plumbing-tools",
"plumbing-wrenches",
rating=4.9,
reviews=4,
added=35,
keywords="aluminum pipe wrench lightweight 24 inch",
description=(
"A 24 inch aluminum-bodied pipe wrench that trims pounds off the "
"biggest wrench in the bag without giving up jaw strength."
),
bullets=["Aluminum I-beam handle", "24 in. length"],
specs={"Length": "24 in.", "Material": "Aluminum"},
),
_p(
"4010103",
"ace-basin-wrench-telescoping",
"Ace Telescoping Basin Wrench 10-17 in.",
"Ace",
1899,
"plumbing",
"plumbing-tools",
"plumbing-wrenches",
rating=4.0,
reviews=17,
added=34,
keywords="basin wrench faucet nut telescoping sink",
description=(
"Reaches the fasteners hiding behind the sink bowl. The shaft "
"telescopes and the head pivots to work at any angle."
),
bullets=["Telescoping 10-17 in. shaft", "Spring-loaded jaw"],
specs={"Reach": "10-17 in."},
),
_p(
"4010104",
"knipex-pipe-wrench-s-type-16-in",
"Knipex S-Type Pipe Wrench 16 in.",
"Knipex",
11499,
"plumbing",
"plumbing-tools",
"plumbing-wrenches",
rating=5.0,
reviews=2,
added=33,
keywords="premium pipe wrench s jaw 16 inch",
description=(
"A premium S-jaw pipe wrench whose three-point grip bites round "
"stock and fittings without flattening them."
),
bullets=["S-shaped jaw", "Fast push-button adjustment"],
specs={"Length": "16 in."},
),
_p(
"4010105",
"superior-tool-drain-wrench-5-1-4-in",
"Superior Tool Drain Wrench 5-1/4 in. L",
"Superior Tool",
1299,
"plumbing",
"plumbing-tools",
"plumbing-wrenches",
rating=3.9,
reviews=9,
added=32,
stock="out-of-stock",
keywords="drain wrench remover sink strainer",
description=(
"A compact dumbbell-style wrench for sink strainers and bath "
"drains. Currently out of stock online."
),
bullets=["Fits 4 common drain sizes", "Zinc body"],
specs={"Length": "5-1/4 in."},
),
# --- Plumbing tool kits ------------------------------------------------
_p(
"4020201",
"ace-home-plumbing-repair-tool-kit-9-pc",
"Ace Home Plumbing Repair Tool Kit 9 pc",
"Ace",
5999,
"plumbing",
"plumbing-tools",
"plumbing-tool-kits",
rating=4.6,
reviews=34,
added=31,
badge="Best Seller",
keywords="home plumbing repair tool kit starter set faucet drain",
description=(
"The starter kit for home plumbing repairs: pipe wrench, basin "
"wrench, groove-joint plier, thread seal tape, washers and a "
"storage tote, chosen to cover the most common weekend fixes."
),
bullets=[
"9 pieces including 12 in. pipe wrench and basin wrench",
"Thread seal tape and assorted washers included",
"Rugged storage tote",
],
specs={"Pieces": "9", "Tote": "Included"},
),
_p(
"4020202",
"superior-tool-plumbers-tool-kit-14-pc",
"Superior Tool Plumber's Tool Kit 14 pc",
"Superior Tool",
9499,
"plumbing",
"plumbing-tools",
"plumbing-tool-kits",
rating=4.3,
reviews=11,
added=30,
keywords="plumbing repair tool kit professional set",
description=(
"A fuller kit for repeat repairs, adding a tubing cutter, hex "
"keys, a faucet seat wrench and a mini hacksaw to the basics."
),
bullets=["14 pieces", "Tubing cutter included", "Blow-molded case"],
specs={"Pieces": "14", "Case": "Blow-molded"},
),
_p(
"4020203",
"dewalt-plumbing-service-set-20v",
"DEWALT 20V MAX Plumbing Service Combo Kit",
"DEWALT",
24900,
"plumbing",
"plumbing-tools",
"plumbing-tool-kits",
rating=4.8,
reviews=6,
added=29,
keywords="cordless plumbing kit drill cutter combo",
description=(
"A cordless service pair for plumbing installs: compact drill "
"driver plus a powered tubing cutter, with two batteries and bag."
),
bullets=["Drill/driver + powered cutter", "Two 20V batteries"],
specs={"Voltage": "20V", "Pieces": "2 tools"},
),
# --- Pipe cutters ------------------------------------------------------
_p(
"4030301",
"milwaukee-close-quarters-tubing-cutter-set-3-pc",
"Milwaukee Close Quarters Tubing Cutter Set 3 pc",
"Milwaukee",
3499,
"plumbing",
"plumbing-tools",
"pipe-cutters",
rating=4.7,
reviews=15,
added=28,
keywords="tubing cutter close quarters copper set",
description=(
"Three thumb-wheel cutters sized 3/8, 5/8 and 1 in. for cutting "
"copper in the tight spaces where a full cutter cannot swing."
),
bullets=["3 sizes", "Hardened cutting wheels"],
specs={"Pieces": "3"},
),
_p(
"4030302",
"sharkbite-1-in-tube-cutter-orange",
"SharkBite 1 in. Tube Cutter Orange",
"SharkBite",
1949,
"plumbing",
"plumbing-tools",
"pipe-cutters",
rating=4.4,
reviews=19,
added=27,
keywords="pex tube cutter one inch",
description=(
"A single-squeeze PEX cutter that leaves the square, clean end "
"push fittings need."
),
bullets=["Cuts up to 1 in. PEX", "Blade replaceable"],
specs={"Capacity": "1 in."},
),
_p(
"4030303",
"superior-tool-ratcheting-pipe-cutter-1-5-8-in",
"Superior Tool 1-5/8 in. Ratcheting Pipe Cutter",
"Superior Tool",
2299,
"plumbing",
"plumbing-tools",
"pipe-cutters",
was=2799,
rating=4.1,
reviews=7,
added=26,
badge="Sale",
keywords="ratcheting pvc pipe cutter",
description=(
"A ratcheting cutter for PVC and PEX up to 1-5/8 in. that cuts "
"with repeated easy squeezes instead of one hard one."
),
bullets=["Ratcheting action", "Stainless blade"],
specs={"Capacity": "1-5/8 in."},
),
# --- Drain cleaning ----------------------------------------------------
_p(
"4040401",
"general-pipe-cleaners-drain-auger-25-ft",
"General Pipe Cleaners Drain Auger 25 ft.",
"General Pipe Cleaners",
3299,
"plumbing",
"plumbing-tools",
"drain-cleaning-tools",
rating=4.5,
reviews=26,
added=25,
keywords="drain auger snake 25 foot clog",
description=(
"A 25 foot drum auger with a corkscrew tip for sink and tub "
"clogs beyond a plunger's reach."
),
bullets=["25 ft. cable", "Enclosed drum"],
specs={"Cable": "25 ft."},
),
_p(
"4040402",
"ace-toilet-plunger-with-caddy",
"Ace Toilet Plunger with Caddy",
"Ace",
1499,
"plumbing",
"plumbing-tools",
"drain-cleaning-tools",
rating=4.2,
reviews=41,
added=24,
keywords="plunger toilet flange caddy",
description=(
"A flange plunger shaped to seal modern toilet traps, with a "
"drip caddy for storage."
),
bullets=["Flange cup", "Storage caddy included"],
specs={"Type": "Flange"},
),
_p(
"4040403",
"general-pipe-cleaners-power-drain-gun",
"General Pipe Cleaners Power Drain Gun",
"General Pipe Cleaners",
6799,
"plumbing",
"plumbing-tools",
"drain-cleaning-tools",
rating=4.0,
reviews=5,
added=23,
stock="online-only",
keywords="drain gun kinetic ram clog air",
description=(
"A kinetic drain opener that clears blockages with a burst of "
"compressed air. Ships to home only."
),
bullets=["No chemicals", "Four fitting heads"],
specs={"Type": "Kinetic"},
),
# --- Pipe / fittings / faucet / drain openers / supply lines -----------
_p(
"4050501",
"sharkbite-pex-pipe-1-2-in-x-25-ft-red",
"SharkBite PEX Pipe 1/2 in. x 25 ft. Red",
"SharkBite",
1599,
"plumbing",
"pipe",
"pex-pipe",
rating=4.6,
reviews=13,
added=22,
keywords="pex pipe red half inch 25 feet",
description="Flexible PEX-B tubing for hot and cold supply lines.",
bullets=["1/2 in. x 25 ft.", "Color-coded red for hot"],
specs={"Diameter": "1/2 in.", "Length": "25 ft."},
),
_p(
"4050502",
"streamline-copper-pipe-1-2-in-x-5-ft",
"Streamline Copper Pipe 1/2 in. x 5 ft. Type M",
"Streamline",
1249,
"plumbing",
"pipe",
"copper-pipe",
rating=4.8,
reviews=3,
added=21,
keywords="copper pipe type m five feet",
description="Rigid Type M copper pipe for interior water lines.",
bullets=["1/2 in. nominal", "5 ft. stick"],
specs={"Type": "M"},
),
_p(
"4060601",
"sharkbite-push-to-connect-coupling-1-2-in",
"SharkBite Push-to-Connect Coupling 1/2 in.",
"SharkBite",
899,
"plumbing",
"pipe-fittings",
"push-fittings",
rating=4.7,
reviews=52,
added=20,
badge="Best Seller",
keywords="push fit coupling half inch no solder",
description=(
"A push-to-connect coupling that joins copper, PEX or CPVC "
"without soldering."
),
bullets=["No tools needed", "Removable and reusable"],
specs={"Size": "1/2 in."},
),
_p(
"4060602",
"bk-brass-threaded-elbow-3-4-in",
"B&K Brass Threaded Elbow 3/4 in. FPT",
"B&K",
649,
"plumbing",
"pipe-fittings",
"threaded-fittings",
rating=4.3,
reviews=8,
added=19,
keywords="brass elbow threaded fitting",
description="A 90 degree brass elbow for threaded supply connections.",
bullets=["Lead-free brass", "3/4 in. FPT both ends"],
specs={"Size": "3/4 in."},
),
_p(
"4070701",
"danco-faucet-repair-kit-universal",
"Danco Universal Faucet Repair Kit",
"Danco",
1099,
"plumbing",
"faucet-and-faucet-repair",
"faucet-parts",
rating=4.1,
reviews=29,
added=18,
keywords="faucet repair kit washers o-rings seats",
description=(
"Washers, O-rings, seats and screws that stop most dripping "
"compression faucets."
),
bullets=["Fits common faucet brands", "Sorted case"],
specs={"Pieces": "58"},
),
_p(
"4070702",
"moen-style-kitchen-faucet-pulldown",
"Ace Collection Pull-Down Kitchen Faucet Brushed",
"Ace",
12900,
"plumbing",
"faucet-and-faucet-repair",
"kitchen-faucets",
was=15900,
rating=4.5,
reviews=14,
added=17,
badge="Sale",
keywords="kitchen faucet pull down sprayer brushed nickel",
description=(
"A single-handle pull-down kitchen faucet with a two-mode spray "
"head and deck plate for one or three hole sinks."
),
bullets=["Pull-down sprayer", "Brushed finish"],
specs={"Handle": "Single"},
),
_p(
"4080801",
"instant-power-drain-opener-1-gal",
"Instant Power Hair and Grease Drain Opener 1 gal.",
"Instant Power",
1299,
"plumbing",
"drain-openers",
"chemical",
rating=4.0,
reviews=63,
added=16,
keywords="drain opener liquid hair grease gallon",
description="A non-acid drain opener for hair and grease clogs.",
bullets=["1 gallon", "Safe for pipes and septic"],
specs={"Volume": "1 gal."},
),
_p(
"4080802",
"korky-beehive-max-plunger",
"Korky Beehive Max Universal Toilet Plunger",
"Korky",
1799,
"plumbing",
"drain-openers",
"plungers",
rating=4.6,
reviews=38,
added=15,
keywords="plunger beehive universal toilet",
description="A tapered plunger head that fits old and new bowls alike.",
bullets=["Universal fit", "T-handle"],
specs={"Type": "Beehive"},
),
_p(
"4090901",
"ace-faucet-supply-line-20-in",
"Ace Faucet Supply Line 3/8 in. x 20 in. Braided",
"Ace",
749,
"plumbing",
"supply-lines",
"faucet-supply",
rating=4.4,
reviews=22,
added=14,
keywords="supply line braided faucet stainless",
description="A braided stainless supply line for faucet hookups.",
bullets=["20 in. length", "Braided stainless jacket"],
specs={"Length": "20 in."},
),
_p(
"4090902",
"fluidmaster-toilet-connector-12-in",
"Fluidmaster Click Seal Toilet Connector 12 in.",
"Fluidmaster",
999,
"plumbing",
"supply-lines",
"toilet-supply",
rating=4.7,
reviews=31,
added=13,
keywords="toilet supply connector click seal",
description="A toilet supply connector that clicks when hand-tight.",
bullets=["Click when sealed", "12 in. length"],
specs={"Length": "12 in."},
),
# --- Tools department --------------------------------------------------
_p(
"4101001",
"craftsman-adjustable-wrench-set-3-pc",
"Craftsman Adjustable Wrench Set 3 pc",
"Craftsman",
2999,
"tools",
"hand-tools",
"wrenches",
rating=4.5,
reviews=44,
added=12,
keywords="adjustable wrench set three",
description="Three chrome adjustable wrenches: 6, 8 and 10 in.",
bullets=["3 sizes", "Laser-etched scales"],
specs={"Pieces": "3"},
),
_p(
"4101002",
"channellock-tongue-and-groove-plier-set",
"Channellock Tongue and Groove Plier Set 2 pc",
"Channellock",
3899,
"tools",
"hand-tools",
"pliers",
rating=4.9,
reviews=27,
added=11,
keywords="groove joint pliers set channel",
description="The 9.5 and 12 in. groove-joint pliers every kit needs.",
bullets=["2 pc", "Right-angle teeth"],
specs={"Pieces": "2"},
),
_p(
"4101003",
"ace-mechanics-tool-set-105-pc",
"Ace Mechanic's Tool Set 105 pc",
"Ace",
8999,
"tools",
"hand-tools",
"tool-sets",
was=10999,
rating=4.6,
reviews=58,
added=10,
badge="Sale",
keywords="mechanics tool set socket ratchet 105",
description="Sockets, ratchets and bits in a latching case.",
bullets=["105 pieces", "72-tooth ratchets"],
specs={"Pieces": "105"},
),
_p(
"4101004",
"dewalt-20v-drill-driver-kit",
"DEWALT 20V MAX Cordless Drill/Driver Kit",
"DEWALT",
13900,
"tools",
"power-tools",
"drills",
rating=4.8,
reviews=72,
added=9,
badge="Best Seller",
keywords="cordless drill driver kit battery",
description="A compact 20V drill/driver with battery and charger.",
bullets=["1/2 in. chuck", "Battery + charger included"],
specs={"Voltage": "20V"},
),
_p(
"4101005",
"milwaukee-hackzall-recip-saw",
"Milwaukee M12 HACKZALL Reciprocating Saw",
"Milwaukee",
9900,
"tools",
"power-tools",
"saws",
rating=4.7,
reviews=33,
added=8,
keywords="reciprocating saw compact one hand",
description="A one-hand reciprocating saw for pipe and stud work.",
bullets=["One-hand control", "Tool-free blade change"],
specs={"Voltage": "12V"},
),
# --- Other departments (representative density) ------------------------
_p(
"4201001",
"clark-kensington-interior-paint-gal",
"Clark+Kensington Interior Paint and Primer 1 gal.",
"Clark+Kensington",
4299,
"paint-and-supplies",
"interior-paint",
"wall-paint",
rating=4.4,
reviews=88,
added=7,
keywords="interior paint primer gallon eggshell",
description="Paint and primer in one for interior walls.",
bullets=["Paint + primer", "Eggshell finish"],
specs={"Volume": "1 gal."},
),
_p(
"4201002",
"kilz-primer-interior-1-gal",
"KILZ 2 All-Purpose Interior Primer 1 gal.",
"KILZ",
2799,
"paint-and-supplies",
"interior-paint",
"primer",
rating=4.6,
reviews=54,
added=6,
keywords="primer sealer stain blocker",
description="A fast-drying primer, sealer and stain blocker.",
bullets=["Water-based", "Seals porous surfaces"],
specs={"Volume": "1 gal."},
),
_p(
"4301001",
"ace-wood-screw-assortment",
"Ace Wood Screw Assortment 200 pc",
"Ace",
1499,
"hardware",
"fasteners",
"screws",
rating=4.3,
reviews=16,
added=5,
keywords="wood screws assortment case",
description="A 200 piece wood screw assortment in a sorted case.",
bullets=["200 pieces", "Phillips drive"],
specs={"Pieces": "200"},
),
_p(
"4301002",
"toggler-drywall-anchor-kit",
"TOGGLER Drywall Anchor Kit with Screws 20 pc",
"TOGGLER",
1199,
"hardware",
"fasteners",
"anchors",
rating=4.7,
reviews=25,
added=4,
keywords="drywall anchors toggle kit",
description="Self-drilling drywall anchors rated for shelves and rails.",
bullets=["20 anchors + screws", "No pilot hole"],
specs={"Pieces": "20"},
),
_p(
"4401001",
"weber-spirit-gas-grill-3-burner",
"Weber Spirit E-315 3-Burner Gas Grill",
"Weber",
56900,
"outdoor-living",
"grills",
"gas-grills",
rating=4.8,
reviews=112,
added=3,
keywords="gas grill three burner propane",
description="A three-burner propane grill with cast-iron grates.",
bullets=["3 burners", "Cast-iron grates"],
specs={"Burners": "3"},
),
_p(
"4401002",
"weber-kettle-charcoal-grill-22",
"Weber Original Kettle 22 in. Charcoal Grill",
"Weber",
21900,
"outdoor-living",
"grills",
"charcoal-grills",
rating=4.9,
reviews=201,
added=2,
keywords="charcoal kettle grill 22",
description="The classic 22 in. charcoal kettle.",
bullets=["22 in. grate", "One-touch cleaning"],
specs={"Diameter": "22 in."},
),
_p(
"4501001",
"ace-garden-hose-5-8-x-50",
"Ace Premium Garden Hose 5/8 in. x 50 ft.",
"Ace",
3499,
"lawn-and-garden",
"watering",
"hoses",
rating=4.2,
reviews=67,
added=1,
keywords="garden hose fifty feet",
description="A kink-resistant 50 ft. garden hose.",
bullets=["5/8 in. x 50 ft.", "Crush-proof couplings"],
specs={"Length": "50 ft."},
),
_p(
"4501002",
"melnor-oscillating-sprinkler",
"Melnor Turbo Oscillating Sprinkler 4500 sq. ft.",
"Melnor",
2499,
"lawn-and-garden",
"watering",
"sprinklers",
rating=4.1,
reviews=39,
added=0,
keywords="oscillating sprinkler lawn watering",
description="An oscillating sprinkler covering up to 4500 sq. ft.",
bullets=["Adjustable width", "Clog-resistant nozzles"],
specs={"Coverage": "4500 sq. ft."},
),
]
# Clean-room records matching the observed public collection depth. Generation
# is deterministic so filtering, pagination, reset and detail-route tests remain
# stable without importing source copy or media.
_SYNTHETIC_TOOL_BRANDS = (
"Ace", "Cobalt Creek", "Northline", "Workshop Pro", "Redwood", "Harbor Peak",
)
_SYNTHETIC_TOOL_TYPES = (
("plumbing-wrenches", "Offset Basin Wrench", "wrench basin faucet nut"),
("pipe-cutters", "Quick-Adjust Tubing Cutter", "pipe tubing cutter wheel"),
("drain-cleaning-tools", "Hand-Crank Drain Auger", "drain auger cable clog"),
("plumbing-tool-kits", "Home Plumbing Service Kit", "plumbing repair service kit"),
)
for _number in range(57):
_leaf, _kind, _keywords = _SYNTHETIC_TOOL_TYPES[_number % len(_SYNTHETIC_TOOL_TYPES)]
_brand = _SYNTHETIC_TOOL_BRANDS[_number % len(_SYNTHETIC_TOOL_BRANDS)]
_series = _number + 1
PRODUCTS.append(
_p(
f"510{_series:04d}",
f"{_brand.lower().replace(' ', '-')}-{_kind.lower().replace(' ', '-')}-{_series}",
f"{_brand} {_kind} Series {_series}", _brand,
1299 + ((_number * 937) % 11800), "plumbing", "plumbing-tools", _leaf,
was=(1599 + ((_number * 937) % 11800)) if _number % 7 == 0 else None,
rating=round(3.6 + (_number % 14) / 10, 1),
reviews=4 + ((_number * 11) % 93),
stock=("low-stock" if _number % 11 == 0 else "online-only" if _number % 17 == 0 else "in-stock"),
badge=("Sale" if _number % 7 == 0 else "Best Seller" if _number % 13 == 0 else None),
keywords=f"{_keywords} synthetic series {_series}", added=100 + _number,
description=f"A locally authored {_kind.lower()} for routine home maintenance. Series {_series} is deterministic demo inventory.",
bullets=["Comfort-grip handle", "Replaceable service component", "Local synthetic inventory"],
specs={"Series": str(_series), "Use": "Home plumbing maintenance", "Origin": "Synthetic demo"},
)
)
# Homepage topic inventory captured from the current public entry page. These
# locally authored records keep each promoted search journey inside the clone.
PRODUCTS.extend(
[
_p(
"8001001",
"ace-home-air-circulator-fan-12-in",
"Ace Home Air Circulator Fan 12 in.",
"Ace",
3999,
"heating-and-cooling",
"portable-and-exhaust-fans",
"household-fans",
rating=4.6,
reviews=84,
keywords="fans household portable cooling air circulator",
description="A compact three-speed fan for everyday room circulation.",
bullets=["Three speed settings", "Adjustable tilt", "Carry handle"],
specs={"Diameter": "12 in.", "Speeds": "3"},
),
_p(
"8001002",
"ace-rolling-hard-sided-cooler-50-qt",
"Ace Rolling Hard-Sided Cooler 50 qt.",
"Ace",
6999,
"outdoor-living",
"coolers",
"hard-sided-coolers",
rating=4.7,
reviews=112,
keywords="coolers ice chest rolling outdoor insulated",
description="A wheeled hard-sided cooler for picnics, games and job sites.",
bullets=["50 qt. capacity", "Telescoping handle", "Drain plug"],
specs={"Capacity": "50 qt.", "Type": "Hard-sided"},
),
_p(
"8001003",
"ace-stainless-steel-travel-tumbler-30-oz",
"Ace Stainless Steel Travel Tumbler 30 oz.",
"Ace",
2499,
"home-and-decor",
"kitchen-utensils-and-gadgets",
"water-bottles-and-travel-mugs",
rating=4.8,
reviews=63,
keywords="drinkware tumbler water bottle travel mug insulated",
description="An insulated stainless steel tumbler sized for daily travel.",
bullets=["Double-wall insulation", "Splash-resistant lid", "Cup-holder friendly"],
specs={"Capacity": "30 oz.", "Material": "Stainless steel"},
),
_p(
"8001004",
"northline-ductless-mini-split-system-12000-btu",
"Northline Ductless Mini Split System 12000 BTU",
"Northline",
89900,
"heating-and-cooling",
"air-conditioners-and-coolers",
"ductless-mini-splits",
rating=4.5,
reviews=28,
keywords="ductless mini splits mini-split air conditioner heat pump",
description="A locally authored single-zone mini split for efficient room comfort.",
bullets=["12,000 BTU output", "Heating and cooling modes", "Remote control"],
specs={"Capacity": "12,000 BTU", "Zones": "1"},
),
]
)
PRODUCT_INDEX: dict[str, dict[str, Any]] = {p["sku"]: p for p in PRODUCTS}
STORES: list[dict[str, Any]] = [
{
"id": "6001",
"name": "Loop Ace Hardware",
"address": "112 W Lake St",
"city": "Chicago",
"state": "IL",
"zip": "60601",
"phone": "(312) 555-0161",
"hours": "Mon-Sat 8am-8pm, Sun 9am-6pm",
"lat": 41.8857,
"lng": -87.6318,
},
{
"id": "6002",
"name": "River North Ace Hardware",
"address": "800 N Orleans St",
"city": "Chicago",
"state": "IL",
"zip": "60610",
"phone": "(312) 555-0188",
"hours": "Mon-Sat 7am-9pm, Sun 8am-7pm",
"lat": 41.8963,
"lng": -87.6371,
},
{
"id": "6003",
"name": "Lincoln Park Ace Hardware",
"address": "2468 N Clark St",
"city": "Chicago",
"state": "IL",
"zip": "60614",
"phone": "(773) 555-0142",
"hours": "Mon-Sat 8am-8pm, Sun 9am-6pm",
"lat": 41.9276,
"lng": -87.6413,
},
{
"id": "6004",
"name": "Oak Park Ace Hardware",
"address": "35 Harrison St",
"city": "Oak Park",
"state": "IL",
"zip": "60304",
"phone": "(708) 555-0177",
"hours": "Mon-Sat 8am-7pm, Sun 9am-5pm",
"lat": 41.8722,
"lng": -87.7871,
},
{
"id": "6005",
"name": "Evanston Ace Hardware",
"address": "920 Church St",
"city": "Evanston",
"state": "IL",
"zip": "60201",
"phone": "(847) 555-0129",
"hours": "Mon-Sat 8am-8pm, Sun 9am-6pm",
"lat": 42.0483,
"lng": -87.6837,
},
{
"id": "6006",
"name": "Naperville Ace Hardware",
"address": "1550 N Route 59",
"city": "Naperville",
"state": "IL",
"zip": "60563",
"phone": "(630) 555-0193",
"hours": "Mon-Sat 7am-9pm, Sun 8am-6pm",
"lat": 41.7948,
"lng": -88.2034,
},
]
STORE_INDEX = {s["id"]: s for s in STORES}
DEFAULT_STORE_ID = "6001"
# ZIP prefixes resolve to a deterministic ordering of nearby stores.
ZIP_STORE_ORDER: dict[str, list[str]] = {
"606": ["6001", "6002", "6003", "6004"],
"603": ["6004", "6006", "6001", "6002"],
"602": ["6005", "6003", "6002", "6001"],
"605": ["6006", "6004", "6001", "6002"],
}
PROMO_CODES: dict[str, dict[str, Any]] = {
"SAVE10": {"kind": "percent", "value": 10, "label": "10% off your order"},
"WELCOME5": {
"kind": "amount",
"value": 500,
"minimum_minor": 2500,
"label": "$5 off orders over $25",
},
"ACESHIP": {"kind": "free-shipping", "value": 0, "label": "Free delivery"},
}
# Flat combined state sales-tax rates used by the local tax simulation.
STATE_TAX_RATES: dict[str, float] = {
"IL": 0.1025,
"WI": 0.055,
"IN": 0.07,
"IA": 0.06,
"MI": 0.06,
"MO": 0.0823,
"OH": 0.0725,
"CA": 0.0875,
"NY": 0.08875,
"TX": 0.0825,
}
DEFAULT_TAX_RATE = 0.07
DELIVERY_FEE_MINOR = 999
FREE_DELIVERY_THRESHOLD_MINOR = 5000
US_STATES = [
"AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE", "DC", "FL", "GA", "HI",
"ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MD", "MA", "MI", "MN",
"MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "OH",
"OK", "OR", "PA", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VA", "WA",
"WV", "WI", "WY",
]
def money(minor: int | None) -> str:
if minor is None:
return ""
return f"${minor / 100:,.2f}"
def store_availability(sku: str, store_id: str) -> dict[str, Any]:
"""Deterministic per-store availability for one product."""
product = PRODUCT_INDEX[sku]
if product["stock"] == "out-of-stock":
return {"state": "out-of-stock", "quantity": 0}
if product["stock"] == "online-only":
return {"state": "online-only", "quantity": 0}
digest = hashlib.sha256(f"{sku}:{store_id}".encode()).digest()
bucket = digest[0] % 10
if product["stock"] == "low-stock":
bucket = min(bucket, 2)
if bucket == 0:
return {"state": "out-of-stock", "quantity": 0}
if bucket <= 2:
return {"state": "low-stock", "quantity": bucket}
return {"state": "in-stock", "quantity": 3 + bucket}
def category_products(dept: str, cat: str | None = None, leaf: str | None = None) -> list[dict[str, Any]]:
out = []
for p in PRODUCTS:
if p["department"] != dept:
continue
if cat is not None and p["category"] != cat:
continue
if leaf is not None and p["leaf"] != leaf:
continue
out.append(p)
return out
def breadcrumb_for(product: dict[str, Any]) -> list[tuple[str, str]]:
dept = DEPARTMENTS[product["department"]]
cat = dept["categories"][product["category"]]
leaf_name = cat["leaves"][product["leaf"]]
return [
("Ace Hardware", "/"),
(dept["name"], f"/departments/{product['department']}"),
(cat["name"], f"/departments/{product['department']}/{product['category']}"),
(
leaf_name,
f"/departments/{product['department']}/{product['category']}?leaf={product['leaf']}",
),
]
def canonical_pdp_path(product: dict[str, Any]) -> str:
return (
f"/departments/{product['department']}/{product['category']}/"
f"{product['leaf']}/{product['sku']}"
)
def related_products(sku: str, limit: int = 6) -> list[dict[str, Any]]:
product = PRODUCT_INDEX[sku]
same_leaf = [
p
for p in PRODUCTS
if p["sku"] != sku
and p["department"] == product["department"]
and p["category"] == product["category"]
]
same_leaf.sort(key=lambda p: (p["leaf"] != product["leaf"], -p["rating"]))
return same_leaf[:limit]
def search_products(query: str) -> list[dict[str, Any]]:
"""Token scoring over name, brand and keywords."""
tokens = [t for t in query.lower().split() if t]
if not tokens:
return []
scored: list[tuple[float, dict[str, Any]]] = []
for p in PRODUCTS:
haystack_name = p["name"].lower()
haystack = " ".join(
[haystack_name, p["brand"].lower(), p["keywords"], p["leaf"].replace("-", " "), p["category"].replace("-", " ")]
)
hits = sum(1 for t in tokens if t in haystack)
if hits == 0:
continue
name_hits = sum(1 for t in tokens if t in haystack_name)
phrase_bonus = 2.0 if query.lower() in haystack_name else 0.0
score = hits * 2 + name_hits * 1.5 + phrase_bonus + p["rating"] / 10
scored.append((score, p))
scored.sort(key=lambda item: (-item[0], item[1]["name"]))
return [p for _, p in scored]
def suggestions(prefix: str, limit: int = 8) -> list[dict[str, str]]:
prefix = prefix.lower().strip()
if len(prefix) < 2:
return []
seen: list[dict[str, str]] = []
for p in search_products(prefix)[:limit]:
seen.append(
{
"label": p["name"],
"url": canonical_pdp_path(p),
"kind": "product",
}
)
# Category suggestions
for dept_id, dept in DEPARTMENTS.items():
for cat_id, cat in dept["categories"].items():
if prefix in cat["name"].lower():
seen.append(
{
"label": f"{cat['name']} in {dept['name']}",
"url": f"/departments/{dept_id}/{cat_id}",
"kind": "category",
}
)
return seen[:limit]
|