# aa-shop

An [Alliance Auth](https://gitlab.com/allianceauth/allianceauth) plugin that lets registered
auth members run a publicly available shop stocked from their own (or their corporation's)
assets.

## Features

- Members create and manage **personal** shops; authorized users manage **corporation** shops.
- A member **back-office** at `/shop-backoffice/` (lists your shops, create/edit/delete).
- Each published shop gets a **public storefront** at `/shop/<slug>/` — no login required.
  Unpublished shops are visible only to their managers (preview).

## Requirements

- Alliance Auth >= 5
- [aa-memberaudit](https://pypi.org/project/aa-memberaudit/) >= 5, installed and syncing

## Installation

1. Install into your Alliance Auth virtual environment:

   ```bash
   pip install aa-shop
   ```

2. Add `"shop"` to `INSTALLED_APPS` in your auth project's `local.py`:

   ```python
   INSTALLED_APPS += ["shop"]
   ```

3. Allow the storefront to expose its public (non-gated) views — **required**, or anonymous
   visitors are redirected to login:

   ```python
   APPS_WITH_PUBLIC_VIEWS = ["storefront"]
   ```

4. Run migrations and collect static files, then restart your AA services:

   ```bash
   python manage.py migrate
   python manage.py collectstatic
   ```

5. **EVE universe data:** the Hulls picker lists ship types from
   [django-eveuniverse](https://gitlab.com/ErikKalkoken/django-eveuniverse), so make sure
   your eveuniverse data is populated with ship types (load the full EVE universe, or at
   least the Ship category, using eveuniverse's load tooling). Ships that aren't loaded
   won't be selectable.

6. Grant permissions (Django admin, or via groups/states):

   | Permission | Grants |
   |---|---|
   | `shop.basic_access` | Access the back-office; create/manage your personal shops |
   | `shop.manage_corporation_shops` | Create/manage your corporation's shops |

### Periodic price refresh

Hulls priced as **% Jita Buy** / **% Jita Sell** are refreshed by a Celery task
every 6 hours. Add to your `local.py`:

```python
from celery.schedules import crontab

CELERYBEAT_SCHEDULE["shop_refresh_pct_prices"] = {
    "task": "shop.tasks.refresh_pct_prices",
    "schedule": crontab(minute=0, hour="*/6"),
}
CELERYBEAT_SCHEDULE["shop_refresh_all_stock"] = {
    "task": "shop.tasks.refresh_all_stock",
    "schedule": crontab(minute=0),   # hourly
}
```

Stock is recomputed from memberaudit assets (no ESI). Refresh on demand with
`python manage.py shop_refresh_stock` (`--async` to enqueue the per-shop tasks).

The task uses the public ESI market endpoint (no token) at low priority
(override with `SHOP_TASKS_PRIORITY`, 1=urgent .. 9=idle; default 7). Prices are
best-of-book at Jita 4-4 (highest buy / lowest sell), the same as Janice.

To refresh on demand (e.g. after setting up %-pricing), run inline:

```bash
python manage.py shop_refresh_prices           # synchronous, prints results
python manage.py shop_refresh_prices --async    # enqueue Celery tasks instead
```

## Usage

- **Members:** open **Shop** in the auth sidebar (`/shop-backoffice/`) to create a shop —
  set a slug, name, type (personal/corporation), and publish it.
- **Public:** share `/shop/<slug>/`; published shops are browsable by anyone.

## Contributing

Design docs and implementation plans live in `docs/superpowers/`. The storefront stylesheet
ships compiled (`shop/static/shop/storefront.css`); to rebuild it after changing storefront
templates, use the standalone Tailwind v4 CLI + daisyUI (no Node required):

```bash
bash scripts/build-css.sh        # add --watch during development
```

## License

MIT
