# Quick Order Module

A bulk ordering interface that lets customers search for products and add multiple items to their basket without navigating away from the page.

## Features

- Live product search by name, EPoS code, PLU, or EAN
- Inline size selection, quantity input, and add-to-basket
- Assessment/consultation redirect for pharmacy and prescription products
- Multi-currency support
- Enable/disable via environment variable

## Configuration

The module is controlled by a single env var:

```env
QUICK_ORDER_ENABLED=true   # default: true
```

When disabled, the routes are not registered and the page is inaccessible.

## Structure

```
modules/QuickOrder/
├── Providers/
│   └── QuickOrderServiceProvider.php   # Registers config, routes
├── Http/
│   └── Controllers/
│       └── QuickOrderController.php    # index (page) + search (JSON API)
├── routes/
│   └── quick_order.php                 # GET /quick-order, GET /quick-order/search
├── config/
│   └── quick_order.php                 # enabled flag
├── templates/
│   └── shop/
│       └── quick_order.twig            # Page template (extends default layout)
├── css/
│   └── quick_order.less                # All component styles
└── js/
    └── components/
        ├── quick_order_page.vue        # Search + results list container
        ├── quick_order_row.vue         # Single product row with add-to-basket
        └── quick_order_modal.vue       # Assessment/consultation redirect modal
```

## Routes

| Method | URI                  | Name                | Description          |
|--------|----------------------|---------------------|----------------------|
| GET    | `/quick-order`       | `quick-order`       | Renders the page     |
| GET    | `/quick-order/search`| `quick-order-search`| JSON product search  |

### Search API

**GET** `/quick-order/search?term={query}`

- `term` must be at least 2 characters
- Returns up to 24 products ordered by popularity (`num_sold`)
- Searches product name, EPoS code, PLU, and EAN

**Response:**

```json
{
  "status": "ok",
  "products": [
    {
      "id": 1,
      "name": "Paracetamol 500mg",
      "image": "/uploads/images/products/smallthumbs/example.jpg",
      "from_price": "2.99",
      "product_type": "general",
      "in_stock": true,
      "url": "/shop/paracetamol-500mg",
      "sizes": [
        { "id": 10, "size": "16 Tablets", "pack_size": "", "price": "2.99", "sale_price": "0.00", "stock": 50, "hide": 0 }
      ],
      "requires_assessment": false,
      "assessment_url": null
    }
  ]
}
```

## Frontend Integration

The Vue component is registered globally in `sites/default/js/main-app.js`:

```js
import QuickOrderPage from "@modules/QuickOrder/js/components/quick_order_page.vue";
Vue.component('quick-order-page', QuickOrderPage);
```

The `@modules` alias is defined in `vite.config.js`.

LESS styles are imported in `sites/default/includes.less`:

```less
@import '../../modules/QuickOrder/css/quick_order.less';
```

## Registration

The service provider is registered in `config/app.php`:

```php
\Mtc\Modules\QuickOrder\Providers\QuickOrderServiceProvider::class,
```

## Tests

```sh
docker exec mtc-pharmacy-web ./vendor/bin/phpunit tests/Feature/QuickOrderPageTest.php tests/Feature/QuickOrderSearchTest.php
```
