# Brand Images Fix

## Problem
Brands are showing without images in the local development environment (`mptechnic.test`), but they display correctly in production (`mp-technic.fr`).

## Root Cause
The application was designed to load brand images from a CDN (`@cdn/brands/{slug}.webp` alias) on production. In the local development environment, there's no CDN folder with brand images, so they don't display.

## Solution

### Quick Fix (Local Development)

1. **Add brand logo images locally:**
   - Place brand logo images in: `frontend/web/img/brands/`
   - Name the files using the brand slug (lowercase), e.g.:
     - `mitutoyo.png`
     - `amaya.webp`
     - `bosch.jpg`
   - Supported formats: `.png`, `.jpg`, `.jpeg`, `.gif`, `.webp`

2. **The display priority is now:**
   - Database image relationship (if configured)
   - Local folder: `frontend/web/img/brands/{slug}.{ext}`
   - CDN: production fallback
   - Plain text: brand name only

### Optional: Database Integration

To store brand images in the database (more flexible, allows admin uploads):

1. **Run the migration:**
   ```bash
   ./yii migrate --migrationPath=console/migrations
   ```
   
   Or manually run the SQL:
   ```sql
   ALTER TABLE brand ADD COLUMN image_id INT NULL AFTER slug;
   ALTER TABLE brand ADD CONSTRAINT fk_brand_image_id 
   FOREIGN KEY (image_id) REFERENCES image(id) 
   ON DELETE SET NULL ON UPDATE CASCADE;
   ```

2. **Add image upload field to backend:**
   - Edit `backend/views/brand/_form.php`
   - Add image_id field with image upload widget

## Files Modified

1. **frontend/helpers/Html.php** - Updated `brandIcon()` helper to:
   - Check database image relationship first
   - Fall back to local file system
   - Fall back to CDN
   - Display brand name as last resort

2. **common/models/Brand.php** - Added:
   - `image_id` property documentation
   - `getImage()` relationship method for database images
   - Updated rules and attribute labels

3. **frontend/web/img/brands/** - New folder for local brand images

## How to Use

### For Local Development:
1. Add brand logo files to `frontend/web/img/brands/` folder
2. Name them with the brand's slug (e.g., if brand slug is "mitutoyo", name the file "mitutoyo.png")
3. Refresh the page - images should now appear

### For Production:
- Keep using the CDN (no changes needed)
- The fallback will automatically use CDN images if local files don't exist

## Example

If you have a brand with:
- Name: "Mitutoyo"
- Slug: "mitutoyo"

Then add: `frontend/web/img/brands/mitutoyo.png`

The helper will automatically find and display it!
