Search by

MyParcel Plugin Development Kit

Package info

github.com/myparcelnl/pdk

Homepage

pkg:composer/myparcelnl/pdk

Statistics

Installs: 23 364

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 12

5.3.3 2026-11-26 10:34 UTC

This package is auto-updated.

Last update: 2026-11-27 16:54:31 UTC


README

Latest version Packagist Downloads Code coverage PHPStan License Chat with us

The MyParcel PDK (Plugin Development Kit) is meant for developing entire plugins on PHP E-Commerce platforms. If you're just looking to connect to our API without creating an entire plugin, you should check out our php SDK.

Requirements

  • PHP 7.4 – 8.5
  • Composer

Documentation

For examples, guides and in-depth information, visit our Plugin Development Kit (PDK) documentation.

Support

Create an issue or contact us via our Developer Portal contact page.

Contributing

View our contribution guidelines for information on how to contribute to the PDK.

Prerequisites

  • Node.js 24, version 24.21 or later
  • pnpm 12, version 12.11 or later
  • Docker
  • No Volta on your machine. Its yarn does not go through corepack, so the packageManager field in package.json does not stop it.

Installation

Create .env:

cp .env.template .env

Install Node dependencies:

pnpm install

Install Composer dependencies:

docker compose up php

Running tests

Run all tests:

docker compose run php composer test

Testing on a specific PHP version

The default PHP version is 7.4. To test on a different version, change PHP_VERSION in .env and rebuild:

docker compose build --pull
docker compose run php composer test

--pull fetches the latest php-xd base image, which gets security fixes every week.

Testing your changes in a plugin

bin/pdk-dev links your local checkout of the PDK, and of js-pdk, into a plugin that uses them, for example woocommerce. It also undoes that.

Requirements:

  • git, jq and pnpm. The plugin must use pnpm.

  • A checkout of js-pdk in a folder named js-pdk, next to this repository, for example projects/pdk and projects/js-pdk. Has it another name or location? Set JS_PDK_PATH to its path.

  • When the plugin runs composer in Docker, mount this repository at the same path in the container, for example in the docker-compose.override.yml of the plugin:

    services:
      php:
        volumes:
          - /path/to/pdk:/path/to/pdk

Put the script on your PATH once:

ln -s "$(pwd)/bin/pdk-dev" /usr/local/bin/pdk-dev

Run these commands in the root folder of the plugin:

pdk-dev on        # link the PDK and js-pdk
pdk-dev on --php  # link only the PDK
pdk-dev on --js   # link only js-pdk

pdk-dev off       # undo both
pdk-dev off --php # undo only the PDK
pdk-dev off --js  # undo only js-pdk

on adds a composer path repository to composer.json and pnpm link: overrides to pnpm-workspace.yaml, and installs. When the plugin has a php service in docker compose, composer runs there. off restores composer.json, composer.lock, package.json, pnpm-workspace.yaml and pnpm-lock.yaml from git, and installs again. on stops when one of these files has uncommitted changes, because off would throw them away. Never commit the changes that on makes.

on does not build js-pdk. The pdk-builder command in the plugin runs the built files of @myparcel-dev/pdk-app-builder, so build it in js-pdk after on, and again after each change to it:

pnpm --filter @myparcel-dev/pdk-app-builder build

The other js-pdk packages that the plugins use export their source and need no build. To see your changes in them, run pnpm watch in the plugin.

Adding a shipment option

Shipment options are managed through the OrderOptionDefinitionInterface system. Each option is a single Definition class that declares all its keys (shipment, capabilities, carrier settings, product settings, allow, price). All models, views, and services build their attributes and form elements dynamically from these definitions.

To add a new option:

  1. Create a Definition class in src/App/Options/Definition/ extending AbstractOrderOptionDefinition. Implement:
    • getShipmentOptionsKey() — the PDK-internal key, derived from Str::camel(RefShipmentShipmentOptions::attributeMap()['sdk_key'])
  2. Register it in the orderOptionDefinitions array in config/pdk-business-logic.php.
  3. Optionally, add a deprecated constant to ShipmentOptions if platform integrations reference the key directly.

The SDK derives the capabilities key. Override getCapabilitiesOptionsKey() only for exceptions, such as returning null for an option without a capabilities equivalent.

Everything else (carrier settings, product settings, allow/price toggles, validation, frontend form fields, API export/import) is derived automatically. Run pnpm test:unit to verify the consistency tests pass.

If the option is not yet in the SDK types, update the SDK or regenerate the OpenAPI types first.

Using Claude Code? Run /add-shipment-option for a guided step-by-step walkthrough that asks the right questions and generates the code.

Writing a migration

Migrations are tracked by identity in an applied_migrations setting and run exactly once per install, independent of the plugin version. There are two kinds:

  • Timestamped migrations (preferred) — a file named YYYY_MM_DD_HHMMSS_<slug>.php in a plugin's src/Migration/ that returns an anonymous class extending AbstractTimestampedMigration. The PDK auto-discovers them and runs each once regardless of version, so they fire even on release-candidate builds where version comparison is unreliable.
  • Versioned migrations — classes implementing UpgradeMigrationInterface with a getVersion(). Deprecated: prefer a timestamped migration for new work.

To scaffold a timestamped migration, run this from a plugin checkout with the PDK linked by pdk-dev on (see Testing your changes in a plugin):

composer console generate:migration <slug>

It creates src/Migration/YYYY_MM_DD_HHMMSS_<slug>.php with empty up()/down() methods — implement up(); down() is optional and defaults to a no-op. Run composer console help generate:migration for the available options.

Linting

We use Prettier to format .json, .yml, .md and .html files.

Make sure Prettier is enabled in your IDE and runs on the following files:

{**/*,*}.{md,html,yml,json}

Set up Git hooks to run Prettier on each commit, correcting any formatting issues.

pnpm prepare

You can also run Prettier manually:

# Check formatting issues
pnpm lint

# Fix formatting issues
pnpm lint:fix