Backend Status: WooCommerce v9.x (probably running on a $2/mo VPS somewhere)
All sales final. No refunds on bad impulse buys.
[Placeholder Image: A ceramic coffee mug with the tinyfiles.tv logo crudely printed in faded orange]

The Crude Logo Mug

$45.00 USD
A heavy ceramic mug that holds lukewarm coffee while you debug PHP scripts at 3 AM.
[Placeholder Image: A structured dad hat featuring a poorly stitched tinyfiles.tv wordmark across the front]

Unstructured Dad Hat

$38.00 USD
Hide your receding hairline or corporate fatigue with this mediocre cotton cap.
[Placeholder Image: A cheap plastic ballpoint pen with tinyfiles.tv printed in smudged white ink]

Smudged Plastic Pen (Single)

$12.50 USD
A promotional ballpoint pen that skips ink strokes whenever you try to write anything important.
[Placeholder Image: An oversized black cotton hoodie with a massive pixelated tinyfiles.tv graphic on the back]

Server Room Hoodie

$95.00 USD
Keep warm in an uninsulated home office. Smells faintly of solder flux and cold brew.
[Placeholder Image: A chunky 8GB USB 2.0 thumb drive stamped with the tinyfiles.tv brand]

8GB Backup USB Stick

$25.00 USD
Pre-loaded with exactly zero files. Use it to store your emergency SSH keys or cat pictures.
Backend  ·  Template · Proposed · Not connected

⬇ Backend — Shop Backend — Template

Right now Shop is local-only — the 5 products are hardcoded cards in this HTML, and addToCart() only shows a toast that says “Added to WooCommerce cart. Redirecting to checkout...” and never redirects. No real cart, no real checkout, no order is created. This backend is the map to make it real: products live on the server, the server owns price + stock + totals, and checkout creates a real order. Proposed, not connected.

01 / Files to create
api/shop/products.php        GET  /api/shop/products
api/shop/product.php         GET  /api/shop/product?slug=...
api/shop/cart.php            GET / POST  /api/shop/cart
api/shop/checkout.php        POST /api/shop/checkout
api/shop/order.php           GET  /api/shop/order?id=...
api/shop/admin-save.php      POST /api/shop/admin-save  (admin only)
sql/shop_tables.sql

Keep the tinyfiles PHP pattern: each endpoint loads /api/bootstrap.php, uses json_in() / json_out(), prepared PDO statements.

02 / Database tables
-- sql/shop_tables.sql
shop_products
  id INT AUTO_INCREMENT PRIMARY KEY
  slug VARCHAR(80) UNIQUE NOT NULL    -- "crude-logo-mug"
  name VARCHAR(120) NOT NULL          -- "The Crude Logo Mug"
  price_cents INT NOT NULL            -- 4500 = $45.00, never float
  description TEXT NOT NULL
  image VARCHAR(255) NOT NULL         -- "/assets/shop/mug.jpg"
  stock INT NOT NULL DEFAULT 0        -- -1 = unlimited / made-to-order
  active TINYINT(1) NOT NULL DEFAULT 1
  created_at DATETIME NOT NULL
  updated_at DATETIME NOT NULL

shop_orders
  id VARCHAR(32) PRIMARY KEY          -- e.g. "ord_..." 
  email VARCHAR(255) NOT NULL
  total_cents INT NOT NULL            -- server-calculated, never client
  status ENUM('pending','paid','shipped','cancelled') NOT NULL DEFAULT 'pending'
  created_at DATETIME NOT NULL

shop_order_items
  id INT AUTO_INCREMENT PRIMARY KEY
  order_id VARCHAR(32) NOT NULL       -- FK -> shop_orders.id
  product_id INT NOT NULL             -- FK -> shop_products.id
  qty INT NOT NULL                    -- >= 1
  price_cents INT NOT NULL            -- snapshot at checkout time

Price is always price_cents (integer). Never store $45.00 as a float — floats round, cents don’t. shop_order_items.price_cents is a snapshot so a later price change never rewrites an old order.

03 / API endpoints & request flow
GET /api/shop/products
- returns { "ok": true, "products": [ { id, slug, name,
  price_cents, description, image, stock }, ... ] }
- only active = 1, ordered by id

GET /api/shop/product?slug=crude-logo-mug
- returns one product, or { "ok": false, "error": "not-found" }

GET /api/shop/cart  /  POST /api/shop/cart
- cart lives in PHP session, not localStorage
- POST { "slug": "...", "qty": 1 } adds / updates
- returns { "ok": true, "cart": [ { slug, qty, price_cents }, ... ],
  "total_cents": 0 }

POST /api/shop/checkout
{ "email": "...", "items": [ { "slug": "...", "qty": 1 } ] }
- server re-loads every product, re-checks stock,
  re-calculates total_cents from DB prices
- if stock < qty: { "ok": false, "error": "out-of-stock", "slug": "..." }
- else: INSERT shop_orders + shop_order_items,
  decrement stock, clear cart,
  return { "ok": true, "order_id": "ord_...", "total_cents": 0 }
- checkout provider (Stripe / WooCommerce / etc.) is plugged in here,
  not in the browser

GET /api/shop/order?id=ord_...
- returns order + items for the thank-you page
- only if session / email matches, never list all orders

The browser never sends a price. It only sends slug + qty. The server is the only thing that knows what something costs.

04 / Cart, totals & validation (server owns this)
// Server validates on checkout:
//   email must be valid, qty must be integer >= 1, qty <= 99
//   slug must exist + active = 1, stock must cover qty
//   total_cents = sum(price_cents * qty) from DB, never from client
//   if client total != server total: reject, do not create order
//   no negative totals, no $0 orders unless product is $0

Keep the “All sales final. No refunds” rule in the checkout response + order email, not just in the .wc-notice on this page — so the rule is enforced where the order is created.

05 / Frontend wiring
// Replace the 5 hardcoded .product-card blocks in this page:
async function loadShop(){
  const res = await fetch('/api/shop/products');
  const data = await res.json();
  // data.products -> same .product-card HTML as now
  // price shown as (price_cents / 100).toFixed(2)
}

// Replace the toast-only addToCart():
async function addToCart(slug, qty = 1){
  const res = await fetch('/api/shop/cart', { method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ slug, qty }) });
  const data = await res.json();
  // data.cart -> show real cart count + toast with server total
}

// Replace the fake "Redirecting to checkout..." toast:
//   POST /api/shop/checkout with { email, items }
//   on success: window.location = '/shop-thank-you.html?id=' + order_id
//   which calls GET /api/shop/order?id=...

// On load: GET /api/shop/products -> render .shop-grid
// If API fails, fall back to current hardcoded 5 cards.

Keep the current 5 cards playable with no backend — if /api/shop/products fails, use the hardcoded cards already in this page.

Copy the snippets above into api/shop/ + sql/shop_tables.sql — no GitHub needed. The <pre> blocks are the backend spec: server-owned products, server-calculated totals, real cart + order, WooCommerce is a joke in the notice until this is wired — right now nothing actually checks out.