# Parcel2Go Shipping

A WooCommerce admin extension for creating shipments via the Parcel2Go API. It lets you get quotes, book services, pay (Braintree or prepay), and manage shipping labels from the WooCommerce admin.

**Architecture:** The plugin entry is `parcel2go-shipping.php`; the PHP backend lives in `includes/` (REST API and helpers). The admin UI is a React/TypeScript app in `src/`, built with `@wordpress/scripts` and served inside WooCommerce Admin.

## Prerequisites

- [NPM](https://www.npmjs.com/)
- [Composer](https://getcomposer.org/download/)
- [wp-env](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-env/)
- [WooCommerce](https://woocommerce.com/) already installed and active
- [Docker](https://www.docker.com/products/docker-desktop/) - Install and ensure docker is running before starting a local development

## Installation and build

```bash
npm install
composer install
wp-env start
```

Optional: To get live updates as you make changes locally, run

```bash
npm run dev

```

Visit the app at:

- **Main:** `http://localhost:8888/wp-admin/admin.php?page=wc-admin&path=%2Fparcel2go-shipping`
- **Settings:** `http://localhost:8888/wp-admin/admin.php?page=wc-admin&path=%2Fparcel2go-shipping%2Fsettings`
- **Previous labels:** `http://localhost:8888/wp-admin/admin.php?page=wc-admin&path=%2Fparcel2go-shipping%2Fshipments`

In the admin menu the plugin appears under **WooCommerce → Parcel2Go Shipping**.
If you are prompted to enter admin credentials, use (admin / password)

## Scripts

| Command | Purpose |
|--------|--------|
| `npm run build` | Production build (output in `build/`) |
| `npm run start` / `npm run dev` | Development build with watch |
| `npm run lint:js` | Lint JavaScript/TypeScript |
| `npm run lint:css` | Lint styles |
| `npm run format` | Format code |
| `npm run composer:install` | Install composer for dev |
| `npm run composer:prod` | install composer for distribution build |
| `npm run plugin-zip` | Create a distributable plugin zip |

## Other useful scripts

| Command | Purpose |
|--------|--------|
| `wp-env stop` | To stop the current plugin container from running |
| `wp-env clean` | To clean the test environment |
| `wp-env destroy` | To delete all the plugin images from docker (for fresh start) | 

## Plugin Check (PCP)

To test the plugin against [WordPress.org Plugin Check](https://wordpress.org/plugins/plugin-check/) (required for directory submission), use your existing wp-env setup. Plugin Check runs inside the same WordPress instance where your plugin is installed.

### 1. Start the environment

From the plugin directory (where `.wp-env.json` lives):

```bash
wp-env start
```

### 2. Install and activate Plugin Check

Run this so the Plugin Check plugin is available inside the Docker WordPress:

```bash
wp-env run cli wp plugin install plugin-check --activate
```

### 3. Run the check

**Option A – Admin UI (recommended)**

1. Open `http://localhost:8888/wp-admin` (log in if needed; default is often `admin` / `password`).
2. Go to **Tools → Plugin Check**.
3. Choose **Parcel2Go Shipping** from the dropdown and click **Run Plugin Check**.
4. Review the report and fix any errors or warnings.

**Option B – WP-CLI**

From your machine (outside Docker), run:

```bash
wp-env run cli wp plugin check parcel2go-shipping/parcel2go-shipping.php --require=wp-content/plugins/plugin-check/cli.php
```

Using `--require` loads Plugin Check’s CLI bootstrap so both static and runtime checks run. Without it, only static checks run.

If your plugin appears under a different folder name in wp-env, use that path instead of `parcel2go-shipping/parcel2go-shipping.php` (e.g. the first segment is the plugin directory name inside `wp-content/plugins/`).

## CREATING PRODUCTION BUILD
To create a distributable production build.zip

```bash
npm run composer:prod
npm run build
npm run plugin-zip
```

## PHP tests

The project includes a `tests/` directory and PHPUnit as a dev dependency. From the plugin or repo root, run PHPUnit if you have a `phpunit.xml` (or similar) configured; for example:

```bash
composer run test
```

or, if PHPUnit is on your path:

```bash
vendor/bin/phpunit
```

If no test runner is set up yet, add a `composer` script or `phpunit.xml` as needed.


## PHP tests

The project includes a `tests/` directory and PHPUnit as a dev dependency. From the plugin or repo root, run PHPUnit if you have a `phpunit.xml` (or similar) configured; for example:

```bash
composer run test
```

or, if PHPUnit is on your path:

```bash
vendor/bin/phpunit
```

If no test runner is set up yet, add a `composer` script or `phpunit.xml` as needed.


## Further documentation

- [Architecture](docs/architecture.md) – Bootstrap, admin UI, frontend flow, directory map
- [REST API](docs/api.md) – Plugin REST routes (method, path, purpose)
- [Configuration](docs/configuration.md) – Sentry, P2G API constants, store/settings
