Skip to content

Commit

Permalink
deterministic inventory; data changes
Browse files Browse the repository at this point in the history
  • Loading branch information
naltatis committed Feb 20, 2024
1 parent a148402 commit aae1d0f
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 76 deletions.
108 changes: 54 additions & 54 deletions src/checkout/database/database.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,279 +6,279 @@
"sku": "AU-01-SI",
"price": 1000,
"image": "/cdn/img/product/AU-01-SI.png",
"inventory": 57
"inventory": 8
},
{
"id": "AU-02",
"name": "AgriTech Titan Sunset Copper",
"sku": "AU-02-OG",
"price": 1100,
"image": "/cdn/img/product/AU-02-OG.png",
"inventory": 2
},
{
"id": "AU-02",
"name": "AgriTech Titan Cosmic Sapphire",
"sku": "AU-02-BL",
"price": 1000,
"image": "/cdn/img/product/AU-02-BL.png",
"inventory": 23
"inventory": 1
},
{
"id": "AU-02",
"name": "AgriTech Titan Verdant Shadow",
"sku": "AU-02-GG",
"price": 1000,
"image": "/cdn/img/product/AU-02-GG.png",
"inventory": 15
"inventory": 4
},
{
"id": "AU-02",
"name": "AgriTech Titan Sunset Copper",
"sku": "AU-02-OG",
"price": 1100,
"image": "/cdn/img/product/AU-02-OG.png",
"inventory": 46
"id": "AU-03",
"name": "AgriMaster Navigator Turquoise Titan",
"sku": "AU-03-TQ",
"price": 1600,
"image": "/cdn/img/product/AU-03-TQ.png",
"inventory": 0
},
{
"id": "AU-03",
"name": "AgriMaster Navigator Majestic Violet",
"sku": "AU-03-PL",
"price": 1700,
"image": "/cdn/img/product/AU-03-PL.png",
"inventory": 91
"inventory": 9
},
{
"id": "AU-03",
"name": "AgriMaster Navigator Scarlet Dynamo",
"sku": "AU-03-RD",
"price": 1900,
"image": "/cdn/img/product/AU-03-RD.png",
"inventory": 73
},
{
"id": "AU-03",
"name": "AgriMaster Navigator Turquoise Titan",
"sku": "AU-03-TQ",
"price": 1600,
"image": "/cdn/img/product/AU-03-TQ.png",
"inventory": 56
"inventory": 10
},
{
"id": "AU-03",
"name": "AgriMaster Navigator Sunbeam Yellow",
"sku": "AU-03-YE",
"price": 1800,
"image": "/cdn/img/product/AU-03-YE.png",
"inventory": 59
},
{
"id": "AU-04",
"name": "Sapphire Sunworker 460R Midnight Onyx",
"sku": "AU-04-BK",
"price": 4000,
"image": "/cdn/img/product/AU-04-BK.png",
"inventory": 11
"inventory": 5
},
{
"id": "AU-04",
"name": "Sapphire Sunworker 460R Ruby Red",
"sku": "AU-04-RD",
"price": 5000,
"image": "/cdn/img/product/AU-04-RD.png",
"inventory": 93
"inventory": 9
},
{
"id": "AU-04",
"name": "Sapphire Sunworker 460R Midnight Onyx",
"sku": "AU-04-BK",
"price": 4000,
"image": "/cdn/img/product/AU-04-BK.png",
"inventory": 8
},
{
"id": "AU-05",
"name": "AgriTech Crop Commander Zestful Horizon",
"sku": "AU-05-ZH",
"price": 3400,
"image": "/cdn/img/product/AU-05-ZH.png",
"inventory": 60
"inventory": 1
},
{
"id": "AU-06",
"name": "AgriTech Field Sovereign Canary Zenith",
"sku": "AU-06-CZ",
"price": 2200,
"image": "/cdn/img/product/AU-06-CZ.png",
"inventory": 15
"inventory": 1
},
{
"id": "AU-06",
"name": "AgriTech Field Sovereign Minted Jade",
"sku": "AU-06-MT",
"price": 2100,
"image": "/cdn/img/product/AU-06-MT.png",
"inventory": 98
"inventory": 3
},
{
"id": "AU-07",
"name": "Verde Voyager Glacial Mint",
"sku": "AU-07-MT",
"price": 4000,
"image": "/cdn/img/product/AU-07-MT.png",
"inventory": 87
"inventory": 4
},
{
"id": "AU-07",
"name": "Verde Voyager Sunbeam Yellow",
"sku": "AU-07-YE",
"price": 5000,
"image": "/cdn/img/product/AU-07-YE.png",
"inventory": 36
"inventory": 9
},
{
"id": "CL-005",
"name": "Golden Grain Harvester 520L 100hp",
"sku": "CL-005-100",
"price": 1000,
"image": "/cdn/img/product/CL-005.png",
"inventory": 98
"inventory": 1
},
{
"id": "CL-005",
"name": "Golden Grain Harvester 520L 200hp",
"sku": "CL-005-200",
"price": 2000,
"image": "/cdn/img/product/CL-005.png",
"inventory": 71
"inventory": 2
},
{
"id": "CL-006",
"name": "Jasper Journeyman 670H 100hp",
"sku": "CL-006-100",
"price": 1000,
"image": "/cdn/img/product/CL-006.png",
"inventory": 14
"inventory": 9
},
{
"id": "CL-006",
"name": "Jasper Journeyman 670H 200hp",
"sku": "CL-006-200",
"price": 2000,
"image": "/cdn/img/product/CL-006.png",
"inventory": 83
"inventory": 10
},
{
"id": "CL-007",
"name": "Garnet Grove Guardian 560S 100hp",
"sku": "CL-007-100",
"price": 1000,
"image": "/cdn/img/product/CL-007.png",
"inventory": 82
"inventory": 0
},
{
"id": "CL-007",
"name": "Garnet Grove Guardian 560S 200hp",
"sku": "CL-007-200",
"price": 2000,
"image": "/cdn/img/product/CL-007.png",
"inventory": 26
"inventory": 1
},
{
"id": "CL-008",
"name": "Sienna Soil Sovereign 370X 100hp",
"sku": "CL-008-100",
"price": 1000,
"image": "/cdn/img/product/CL-008.png",
"inventory": 65
"inventory": 6
},
{
"id": "CL-008",
"name": "Sienna Soil Sovereign 370X 200hp",
"sku": "CL-008-200",
"price": 2000,
"image": "/cdn/img/product/CL-008.png",
"inventory": 52
"inventory": 7
},
{
"id": "CL-009",
"name": "Maroon Meadow Marshal 530Q 100hp",
"sku": "CL-009-100",
"price": 1000,
"image": "/cdn/img/product/CL-009.png",
"inventory": 83
"inventory": 8
},
{
"id": "CL-009",
"name": "Maroon Meadow Marshal 530Q 200hp",
"sku": "CL-009-200",
"price": 2000,
"image": "/cdn/img/product/CL-009.png",
"inventory": 10
"inventory": 9
},
{
"id": "CL-010",
"name": "Quartz Quarry Queen 360L 100hp",
"sku": "CL-010-100",
"price": 1000,
"image": "/cdn/img/product/CL-010.png",
"inventory": 34
"inventory": 0
},
{
"id": "CL-010",
"name": "Quartz Quarry Queen 360L 200hp",
"sku": "CL-010-200",
"price": 2000,
"image": "/cdn/img/product/CL-010.png",
"inventory": 0
"inventory": 1
},
{
"id": "CL-011",
"name": "Steel Seed Sower 470W 100hp",
"sku": "CL-011-100",
"price": 1000,
"image": "/cdn/img/product/CL-011.png",
"inventory": 60
"inventory": 8
},
{
"id": "CL-011",
"name": "Steel Seed Sower 470W 200hp",
"sku": "CL-011-200",
"price": 2000,
"image": "/cdn/img/product/CL-011.png",
"inventory": 48
"inventory": 9
},
{
"id": "CL-012",
"name": "Cobalt Countryside Cruiser 340M 100hp",
"sku": "CL-012-100",
"price": 1000,
"image": "/cdn/img/product/CL-012.png",
"inventory": 22
"inventory": 1
},
{
"id": "CL-012",
"name": "Cobalt Countryside Cruiser 340M 200hp",
"sku": "CL-012-200",
"price": 2000,
"image": "/cdn/img/product/CL-012.png",
"inventory": 62
"inventory": 2
},
{
"id": "CL-013",
"name": "Cerulean Crop Commander 310A 100hp",
"sku": "CL-013-100",
"price": 1000,
"image": "/cdn/img/product/CL-013.png",
"inventory": 68
"inventory": 1
},
{
"id": "CL-013",
"name": "Cerulean Crop Commander 310A 200hp",
"sku": "CL-013-200",
"price": 2000,
"image": "/cdn/img/product/CL-013.png",
"inventory": 28
"inventory": 2
},
{
"id": "AU-001",
"name": "Futuro Fieldmaster 800Xi 100hp",
"sku": "AU-001-100",
"price": 1000,
"image": "/cdn/img/product/AU-001.png",
"inventory": 46
"inventory": 9
},
{
"id": "AU-001",
"name": "Futuro Fieldmaster 800Xi 200hp",
"sku": "AU-001-200",
"price": 2000,
"image": "/cdn/img/product/AU-001.png",
"inventory": 94
"inventory": 10
}
]
}
13 changes: 9 additions & 4 deletions src/checkout/database/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,25 @@ import fs from "fs";
import path from "path";
import products from "../../../products.js";

function getInventory() {
return Math.floor(Math.random() * 100);
function getInventory(name) {
// generate deterministic inventory (0-10) based on the name
const hash = name
.split("")
.reduce((acc, char) => acc + char.charCodeAt(0), 0);
return hash % 11;
}

const database = {
variants: products.flatMap((p) => {
return p.variants.map((v) => {
const name = `${p.name} ${v.name}`;
return {
id: p.id,
name: `${p.name} ${v.name}`,
name,
sku: v.sku,
price: v.price,
image: v.image,
inventory: getInventory(),
inventory: getInventory(name),
};
});
}),
Expand Down
Loading

0 comments on commit aae1d0f

Please sign in to comment.