# Complete Workflow Guide

## System Overview

You have 3 components working together:
1. **PostgreSQL Database** - All content, product data, navigation, file references
2. **CRUD Admin + File Uploads** - Manage products and upload files to `products/uploads/`
3. **Static Generator** - Combines database + uploaded files into static HTML

## Adding a New Product

### Step 1: Add Product via CRUD Admin

Access the CRUD admin interface at https://dev.handlingdevices.net/products/

1. **Create Product Record**:
   - Navigate to Products section
   - Click "Add New Product"
   - Fill in product details:
     - Product Title
     - Folder Name (URL slug)
     - Category
     - Description
     - Pricing tiers (Basic, Professional, Premium)
     - Snipcart IDs

2. **Upload Product Images**:
   - In the product edit screen, upload images
   - Mark one as "main image" for category page
   - Mark technical drawings if applicable
   - Set display order
   - Images saved to `generated/products/uploads/`
   - Filenames saved to `site.product_images`

3. **Upload STL File** (if applicable):
   - Upload 3D model file
   - File saved to `generated/products/uploads/`
   - Filename saved to `site.products.stl_filename`

4. **Upload SVG Charts** (for crane products):
   - Upload load chart SVG: `{filename}.svg`
   - Upload lifting table SVG: `{filename}LT.svg`
   - Files saved to `generated/products/uploads/`
   - References saved to database

5. **Add Product Features**:
   - Add technical specifications
   - Set display order

### Step 2: Generate Static Site

```bash
cd /var/www/html/mh.maint-data.dev
php SiteGenerator.php
```

This will:
1. Read product data from database
2. Copy files from `products/uploads/` to `generated/buy-models/{category}/{product}/`
3. Generate HTML page at `generated/buy-models/{category}/{product}/index.html`

### Step 3: Deploy to Production

```bash
cd /var/www/html/mh.maint-data.dev
./deployment.sh
```

This creates a deployment archive excluding the `products/` directory.

## Updating Existing Content

### Update Page Content (Home, Pricing, Usage)

**Option 1: Via CRUD Admin** (if available)
- Access https://dev.handlingdevices.net/products/
- Navigate to Pages section
- Edit content

**Option 2: Direct SQL**
```sql
UPDATE site.pages
SET content = 'New markdown content here...'
WHERE slug = 'home';
```

Then regenerate:
```bash
cd /var/www/html/mh.maint-data.dev
php SiteGenerator.php
```

### Update Product Price

**Via CRUD Admin:**
- Access product edit screen
- Update pricing fields
- Save

**Via SQL:**
```sql
UPDATE site.products
SET basic_price = 349
WHERE site_id = 'NEW-CRANE-01';
```

Then regenerate site.

### Add New Product Image

**Via CRUD Admin:**
1. Access product edit screen
2. Upload new image
3. Set display order
4. Save

**Regenerate site:**
```bash
cd /var/www/html/mh.maint-data.dev
php SiteGenerator.php
```

## Common Scenarios

### Full Site Rebuild

```bash
cd /var/www/html/mh.maint-data.dev
php SiteGenerator.php
./deployment.sh
```

### Replace Product Image

**Via CRUD Admin:**
1. Access product edit screen
2. Delete old image or upload new one with same filename
3. Save

**Regenerate site:**
```bash
cd /var/www/html/mh.maint-data.dev
php SiteGenerator.php
```

## Troubleshooting

**Problem: Product page shows no images**
- Check: Are images uploaded via CRUD admin?
- Check: Are filenames in `site.product_images` table correct?
- Check: Do files exist in `generated/products/uploads/`?
- Check: Did you run `php SiteGenerator.php` after uploading?

**Problem: Load charts not showing**
- Check: Are SVG files uploaded to `products/uploads/`?
- Check: Are filenames correct in database (crane_setup_filename table)?
- Check: Do both `{filename}.svg` and `{filename}LT.svg` exist?
- Run: `php SiteGenerator.php` to copy files

**Problem: Product metadata wrong (price, description)**
- Check: Database content in `site.products` table
- Update via CRUD admin or SQL
- Run: `php SiteGenerator.php` to regenerate

**Problem: Page content not updating**
- Check: Content in `site.pages` table
- Run: `php SiteGenerator.php` to regenerate

**Problem: Files not being copied**
- Check: Files exist in `generated/products/uploads/`
- Check: Filenames in database match actual files (case-sensitive)
- Check: Directory permissions on `products/uploads/`

## File Management

### Where Files Are Stored

- **Source**: `generated/products/uploads/` - All product files (managed by CRUD)
- **Destination**: `generated/buy-models/{category}/{product}/` - Copied during generation
- **Production**: Only `generated/` (excluding `products/`) is deployed

### File Naming

- Files must match database references exactly (case-sensitive)
- Images: Listed in `site.product_images.filename`
- STL: Listed in `site.products.stl_filename`
- SVG Charts: Referenced in `site.crane_setup_filename.filename`
