# reach-digital/magento2-prooph-event-store

`composer require reach-digital/magento2-prooph-event-store`

Canonical URL: https://packagento.com/reach-digital/magento2-prooph-event-store

## At a glance

- **Vendor**: reach-digital (https://packagento.com/reach-digital.md)
- **Latest version**: 2.0.0-beta9 — released 2018-12-21
- **Pricing**: Free
- **Package type**: Magento 2 module
- **Status**: active, accepting new buyers

## Installation

Packagento is licence-gated, so even free packages need a licence on a project before Composer can resolve them.

1. **Sign in or create an account** at https://packagento.com/customer/account/.

2. **Add the package to your account.** Open https://packagento.com/reach-digital/magento2-prooph-event-store and complete the free checkout. A licence is minted automatically.

3. **Create or pick a project, then activate the licence on it.**
   - Projects represent the Magento installs you deploy to. Manage them at https://packagento.com/projects/.
   - Activate the new licence on the project you'll deploy this package to. Activation is what generates the Composer credentials scoped to that project.

4. **Add the project credentials to your Magento codebase.**

   Grab the project's public + private key from https://packagento.com/projects/ (open the project, then its Credentials tab), and add them to `auth.json`:

   ```json
   {
     "http-basic": {
       "packagento.com": {
         "username": "ppk_live_...",
         "password": "psk_live_..."
       }
     }
   }
   ```

   Add the Packagento Composer repository to `composer.json`:

   ```json
   {
     "repositories": [
       { "type": "composer", "url": "https://packagento.com" }
     ]
   }
   ```

5. **Install and apply.**

   ```bash
   composer require reach-digital/magento2-prooph-event-store:*
   bin/magento setup:upgrade
   bin/magento setup:di:compile
   bin/magento cache:flush
   ```

## README

Integration with Prooph software and Magento 2's DI.
Reduce boilerplate in setting up your project.

### Installation

https://github.com/prolic/fpp/blob/master/docs/PhpStorm-Integration.md
https://github.com/ho-nl/docs-internal/issues/22

### Modules build with ES

https://github.com/ho-nl/magento2-ReachDigital_Subscription
https://github.com/ho-nl/magento2-ReachDigital_ProophJira
https://github.com/ho-nl/magento2-ReachDigital-TransferOrdersES

### What is ES?
https://www.youtube.com/watch?v=B6XUEoZlsWk
http://getprooph.org/
http://docs.getprooph.org/tutorial/
https://github.com/prooph/proophessor-do

### When to use ES?
- When you are creating new entities
- When you are creating new Commands
- When you want to have a high development velocity

### Building your own ES based module

For a full example, take a look at [ReachDigital_TransferOrdersES](https://github.com/ho-nl/magento2-ReachDigital-TransferOrdersES),
which implements all the patterns discussed here. [ReachDigital_Subscription](https://github.com/ho-nl/magento2-ReachDigital_Subscription)
is actually in production so everything is more stable out, but doesn't follow all patterns described here and therefor
is a bit messy.

The Module we are going to build will be split up in multiple logical Magento Modules. We define the following sections:
- Api
- Command+Event Implementation
- Query Implementation
- Frontend UI
- Backend UI

#### Api Module

##### Field Types, Commands and events with FPP

Generate your classes with [fpp](https://github.com/prolic/fpp) (there is a PHPStorm file watcher for fast development).

Logical Magento Module: https://github.com/ho-nl/magento2-ReachDigital-TransferOrdersES/tree/master/TransferOrdersESApi
Domain Model: https://github.com/ho-nl/magento2-ReachDigital-TransferOrdersES/blob/master/TransferOrdersESApi/etc/domain.fpp
Generated Code: https://github.com/ho-nl/magento2-ReachDigital-TransferOrdersES/tree/master/TransferOrdersESApi/Model

Domain Model: https://github.com/ho-nl/magento2-ReachDigital_Subscription/blob/master/src/Model/Domain.fpp

To create your own Domain model, understand this http://docs.getprooph.org/tutorial/why_event_sourcing.html

##### Your Model (AggregateRoot)

Create your Domain Model (AggregateRoot). Because this model actually contains business logic, this class can't be
auto generated. This is a bit of chore, but writing all your commands, events, fields down in the class validates your
domain model.

This class is a leaky abstraction: This class actually defines the business logic required and belongs in the domain
model, but it extends AggregateRoot which is an implementation specific thing.. Therefor it is a bit of odd class here.

Examples:
https://github.com/ho-nl/magento2-ReachDigital-TransferOrdersES/blob/master/TransferOrdersESApi/Model/Transfer/Transfer.php
https://github.com/ho-nl/magento2-ReachDigital_Subscription/blob/master/src/Model/Subscription/Subscription.php
https://github.com/ho-nl/magento2-ReachDigital_Subscription/blob/master/src/Model/ProductPlan/ProductPlan.php

##### GetTransferInterface + SaveTransferInterface

Since we dont want any save/load logic in this module, we're defining the interfaces here.

https://github.com/ho-nl/magento2-ReachDigital-TransferOrdersES/blob/ab296875bce658196775b911edb9892e492a6012/TransferOrdersESApi/Model/Transfer/GetTransferInterface.php
https://github.com/ho-nl/magento2-ReachDigital-TransferOrdersES/blob/ab296875bce658196775b911edb9892e492a6012/TransferOrdersESApi/Model/Transfer/SaveTransferInterface.php

### Event Store setup (chore)

We're now implementing the Command side of CQRS (Command Query Responsibility Seggegation). This means we need to
implement the GetTransferInterface, SaveTransferInterface.

Create a second module (composer.json PSR4, registration.php, module.xml) and enable the module via php bin/magento
module enable, make sure it works.

Create a event store table by creating a SchemaPatch:
https://github.com/ho-nl/magento2-ReachDigital-TransferOrdersES/blob/ab296875bce658196775b911edb9892e492a6012/TransferOrdersES/Setup/Patch/Schema/CreateEventStore.php

To access the information of the event store, use the [AggregateRepository](http://docs.getprooph.org/event-sourcing/repositories.html#4-2-6) to fetch the information.

https://github.com/ho-nl/magento2-ReachDigital-TransferOrdersES/blob/ab296875bce658196775b911edb9892e492a6012/TransferOrdersES/Model/Transfer/GetTransfer.php
https://github.com/ho-nl/magento2-ReachDigital-TransferOrdersES/blob/ab296875bce658196775b911edb9892e492a6012/TransferOrdersES/Model/Transfer/SaveTransfer.php
https://github.com/ho-nl/magento2-ReachDigital-TransferOrdersES/blob/ab296875bce658196775b911edb9892e492a6012/TransferOrdersES/etc/di.xml

### Command Handlers

Now onto the meat of the application, making everything work. First we create handlers (with tests for the application).

https://github.com/ho-nl/magento2-ReachDigital-TransferOrdersES/tree/7512a2ad62f297cdb31f96e84161dab884867e29/TransferOrdersES/Model/Transfer/Handler
https://github.com/ho-nl/magento2-ReachDigital-TransferOrdersES/blob/7512a2ad62f297cdb31f96e84161dab884867e29/TransferOrdersES/etc/di.xml#L10-L27
https://github.com/ho-nl/magento2-ReachDigital-TransferOrdersES/tree/7512a2ad62f297cdb31f96e84161dab884867e29/TransferOrdersES/Test/Integration/Model/Handler

In the examples I first focus on the internals of the application, and don't bother with stuff that interacts with the
rest of Magento. This way I can focus on this part of the application, which keeps everything simple.

#### Interaction with the rest of the system
A feature usually doesn't exist in a vacuum, so we need to integrate it with the rest of Magento.

### Admin UI

- Controllers
- UI


### Create a Admin Grid event store Projection

_(README truncated for .md surface. Full README on https://packagento.com/reach-digital/magento2-prooph-event-store.)_

## Recent Versions

| Version | Released |
|---|---|
| 2.0.0-beta9 | 2018-12-21 |
| 2.0.0-beta8 | 2018-11-30 |
| 2.0.0-beta7 | 2018-11-27 |
| 2.0.0-beta6 | 2018-11-27 |
| 2.0.0-beta5 | 2018-11-21 |
| 2.0.0-beta4 | 2018-11-05 |
| 2.0.0-beta3 | 2018-10-10 |
| 2.0.0-beta2 | 2018-10-10 |
| 2.0.0-beta1 | 2018-10-09 |

## Dependencies

### Require

| Package | Constraint |
|---|---|
| mindplay/composer-locator | ^2.1 |
| php | ~7.1.0 |
| prooph/event-sourcing | ^5.2 |
| prooph/event-store | ^7.5 |
| prooph/event-store-bus-bridge | ^3.0 |
| prooph/pdo-event-store | ^1.10.1 |
| prooph/pdo-snapshot-store | ^1.3 |
| prooph/service-bus | ^6.1 |
| prooph/snapshotter | ^2.0 |

## Quality

Latest release (2.0.0-beta9) fails the Packagento QA pipeline. Verdicts below are per-cell (Magento line × PHP version) for the matrixed tools, and run-once for the static / security tiers.


### Compatibility

Each Magento line is installed on its supported PHP versions, then the module is built (DI compile + static-content deploy). Cells show passed / failed / untested; staircase gaps render as `–`.

| Magento | PHP 8.2 | PHP 8.3 | PHP 8.4 | PHP 8.5 |
|---|---|---|---|---|
| 2.4.7 | not tested | not tested | – | – |
| 2.4.8 | – | not tested | not tested | – |
| 2.4.9 | – | – | not tested | not tested |


### Code Quality

Advisory checks against the module's source. Never affect the Compatibility verdict — a phpcs finding can't make a module incompatible.

#### Static Analysis

Coding standards (phpcs), mess detection (phpmd), copy-pasted code (cpd), PHP cross-version compatibility, composer.json validity. Each runs once for the whole module.

| Tool | Status | Findings | Summary |
|---|---|---|---|
| PHPCS | Fail | 109 | 10 errors, 99 warnings (ruleset: Magento2) — 40 auto-fixable with phpcbf |
| PHPMD | Warning | 19 | 19 rule violations (MissingImport:9, UnusedFormalParameter:5, UnusedLocalVariable:3, TooManyPublicMethods:2) |
| Cpd | Pass | 0 |  |
| Composer validate | Info | 1 | valid; 1 advisory note (composer validate --strict) |

#### PHPStan

Type-checks the module against a real Magento install. Re-runs per Magento + PHP version because resolvable symbols differ between releases.

| Magento | PHP 8.2 | PHP 8.3 | PHP 8.4 | PHP 8.5 |
|---|---|---|---|---|
| 2.4.7 | N/A | N/A | – | – |
| 2.4.8 | – | N/A | N/A | – |
| 2.4.9 | – | – | N/A | N/A |


### Tests

Unit and integration suites run per Magento + PHP cell. Test failures speak to the module's behaviour, not its compatibility with a line, so they're reported here separately.

#### Unit Tests

| Magento | PHP 8.2 | PHP 8.3 | PHP 8.4 | PHP 8.5 |
|---|---|---|---|---|
| 2.4.7 | N/A | N/A | – | – |
| 2.4.8 | – | N/A | N/A | – |
| 2.4.9 | – | – | N/A | N/A |

#### Integration Tests

| Magento | PHP 8.2 | PHP 8.3 | PHP 8.4 | PHP 8.5 |
|---|---|---|---|---|
| 2.4.7 | N/A | N/A | – | – |
| 2.4.8 | – | N/A | N/A | – |
| 2.4.9 | – | – | N/A | N/A |


### Security

Dependency-advisory audit (composer audit) plus a source malware scan. A malware detection fails the version outright.

| Tool | Status | Findings | Summary |
|---|---|---|---|
| Composer audit | Pass | 0 |  |
| Malware scan | Pass | 0 |  |

## Licence and pricing

Free. A licence is still minted on checkout and bound to your project for Composer access — no payment step.

Refundable within 14 days of first purchase via https://packagento.com/account/refunds/.

## Install via Claude Code or any MCP client

The Packagento MCP server can run the licence + project + Composer steps above in one tool call:

```
purchase_and_install_packages(
  composer_names=["reach-digital/magento2-prooph-event-store"],
  project_id="proj_xxx"
)
```

This handles cart, checkout, licence minting, project activation, and writes auth.json credentials. Connect a client with `claude mcp add packagento https://mcp.packagento.com`. Full setup at https://packagento.com/docs/mcp-setup.

## Vendor

reach-digital is a Magento 2 vendor on Packagento. See https://packagento.com/reach-digital.md for their full catalogue.

