# reach-digital/magento2-order-source-reservations

`composer require reach-digital/magento2-order-source-reservations`

Canonical URL: https://packagento.com/reach-digital/magento2-order-source-reservations

## At a glance

- **Vendor**: reach-digital (https://packagento.com/reach-digital.md)
- **Latest version**: 1.4.0 — released 2021-07-14
- **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-order-source-reservations 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-order-source-reservations:*
   bin/magento setup:upgrade
   bin/magento setup:di:compile
   bin/magento cache:flush
   ```

## README

### Installation

Make sure you have access to our private composer repository.

```bash
composer require reach-digital/magento2-order-source-reservations
bin/magento module:enable ReachDigital_IOSReservationsApi
bin/magento module:enable ReachDigital_IOSReservations
bin/magento module:enable ReachDigital_IOSReservationsAdminUI
bin/magento module:enable ReachDigital_IOSReservationsCancellationApi
bin/magento module:enable ReachDigital_IOSReservationsCancellation
bin/magento module:enable ReachDigital_IOSReservationsPriorityApi
bin/magento module:enable ReachDigital_IOSReservationsPriority
bin/magento module:enable ReachDigital_IOSReservationsPriorityAdminUI
bin/magento setup:upgrade
```

#### Backstory

We had a requirement to make a connection with a fulfillment warehouse, we
wanted to be future-proof and want to intergrate it with the new Multi Source
Inventory functionality introduced in Magento 2.3 If you don't fully understand
MSI yet, please read our blogpost
[The Definitive Guide to Magento MSI Multi Source Inventory](https://www.reachdigital.nl/en/blog/magento-msi-multi-source-inventory-features)).

While writing specifications for the integration with the warehouse it came to
our attention that MSI has a feature-gap regarding the creation of shipments:

We need to make an API-call to the actual source (warehouse) to actually request
a shipment for the ordered products. But to know what to actually communicate to
the warehouse, the Source Selection Algorithm needs to have run. We can't run
that algorithm during the shipment creation because the product hasn't actually
shipped and thus the source isn't deducted at that point.

#### Proposed solution

To implement a warehouse connector based on MSI, we need to know to what
warehouse to send which products. The warehouse selection is done in MSI with
the Source Selection Algorithm. The SSA is triggered via the UI, right before
creating the shipment.

The feature-gap here is that we need the result of the SSA, because we need to
send an API call at some point to the warehouse... After we've sent the API
calls to the warehouse we can't have the result of the SSA be changed.

1. If the SSA has been ran a single time we need to store the result, it can't
   change.
2. If an item has a source selected we have a moment to send of an API call to
   the warehouse.

To store the result of the SSA we make an
[Inventory Source Reservations](https://github.com/ho-nl/magento2-ReachDigital_InventorySourceReservations).

##### Flow

- 🔸 Already handled by Magento
- 🔹 Added by this package

Order created:

- 🔸Create StockReservations ✅

Invoice created:

- 🔹Cron to 🔹Add SourceReservations + 🔹Revert StockReservations ✅

Shipment Created

- 🔹Revert SourceReservations instead of Stock + 🔸Deduct Source ✅

Order Cancelled

- 🔸Revert StockReservations ✅

Credit Order when not shipped:

- 🔹Revert Source Reservations by refunded qty, if reservation exists. ✅
- 🔹Low Prio: Hide 'Return Qty to Source' because it isn't deducted yet.

Credit Order when shipped:

- 🔸Increment Source ✅

#### Step by step

1. Order created: When a new order is created in Magento MSI will make a
   reservation on the Stock🔸, this will be exactly the same.

   - Order Cancelled: The Stock reservation is nullified and the qty is released
     to be sold again.

2. Create invoice: 🔹Cron
   [MoveReservationsFromStockToSourceRunner](https://github.com/ho-nl/magento2-ReachDigital_InventoryOrderSourceReservations/blob/master/IOSReservations/Model/MoveReservationsFromStockToSourceRunner.php#L65-L78):
   Periodically we run the 'heavy' SSA on all orders that are succesfully
   invoiced (and therefor authorized to be shipped).

   - 🔹[OrderSelectionService](https://github.com/ho-nl/magento2-ReachDigital_InventoryOrderSourceReservations/blob/master/IOSReservationsPriorityApi/Api/OrderSelectionServiceInterface.php)
     will return a list of unsourced orders based on a certain algorithm (only
     byDateCreated implemented right now).
   - 🔹[Selection criteria](https://github.com/ho-nl/magento2-ReachDigital_InventoryOrderSourceReservations/blob/master/IOSReservationsPriority/Model/Algorithms/ByDateCreatedAlgorithm.php#L63-L65)
     All state:processing and unsourced orders.
   - 🔹[MoveReservationsFromStockToSource](https://github.com/ho-nl/magento2-ReachDigital_InventoryOrderSourceReservations/blob/master/IOSReservations/Model/MoveReservationsFromStockToSource.php)
     Will actually move the reservations from the Stock to the Source.
   - To integrate with a warehouse it becomes trivial to find a point where to
     hook into, to actually send the reservations to the actual warehouse:
     🔹afterExecute on MoveReservationsFromStockToSource.

3. Create shipment

   - 🔹
     [DeductSourceAndNullifyReservationOnShipment](https://github.com/ho-nl/magento2-ReachDigital_InventoryOrderSourceReservations/blob/master/IOSReservations/Plugin/MagentoInventoryShipping/DeductSourceAndNullifyReservationOnShipment.php#L103-L130):
     Instead of nullifying MSI's Stock Reservation we now nullify the Source
     Reservation. The Stock reservation already happened in step two.
   - The SSA will always return the earlier created reservations: 🔹
     [PriorityBasedAlgorithmWithSourceReservations](https://github.com/ho-nl/magento2-ReachDigital_InventoryOrderSourceReservations/blob/master/IOSReservations/Plugin/InventorySourceSelection/PriorityBasedAlgorithmWithSourceReservations.php#L101-L103)

4. Create creditmemo:
   - 🔹
     [RevertSourceReservationsOnCreditBeforeShipment](https://github.com/ho-nl/magento2-ReachDigital_InventoryOrderSourceReservations/blob/master/IOSReservations/Plugin/MagentoInventorySales/RevertSourceReservationsOnCreditBeforeShipment.php)
     will automatically revert any source reservations.

#### REST Api / Internal Api

_(README truncated for .md surface. Full README on https://packagento.com/reach-digital/magento2-order-source-reservations.)_

## Recent Versions

| Version | Released |
|---|---|
| 1.4.0 | 2021-07-14 |
| 1.4.0-canary.6 | 2020-10-08 |
| 1.4.0-canary.5 | 2020-10-08 |
| 1.3.2 | 2020-10-08 |
| 1.4.0-canary.4 | 2020-08-26 |
| 1.4.0-canary.3 | 2020-08-26 |
| 1.4.0-canary.2 | 2020-08-26 |
| 1.4.0-canary.1 | 2020-08-19 |
| 1.3.1 | 2020-08-12 |
| 1.3.0 | 2020-08-05 |

Showing 10 of 22 versions. Full release history on https://packagento.com/reach-digital/magento2-order-source-reservations.

## Dependencies

### Require

| Package | Constraint |
|---|---|
| magento/framework | * |
| php | ~7.1.3\|\|~7.2.0\|\|~7.3.0\|\|~7.4.0 |
| reach-digital/magento2-inventory-source-reservations | * |

## Quality

Latest release (1.4.0) 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 | 1 | – |
| 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 | 48 | 1 error, 47 warnings (ruleset: Magento2) — 5 auto-fixable with phpcbf |
| PHPMD | Warning | 20 | 20 rule violations (UnusedFormalParameter:13, UnusedLocalVariable:2, ExcessiveParameterList:1, CyclomaticComplexity:1, NPathComplexity:1) |
| Cpd | Warning | 12 | 12 duplicated chunks spanning 418 total lines (min-lines=5, min-tokens=70) |
| Composer validate | Info | 2 | valid; 2 advisory notes (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 | Error | Error | – | – |
| 2.4.8 | – | Error | Error | – |
| 2.4.9 | – | – | Error | Error |


### Security

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

| Tool | Status | Findings | Summary |
|---|---|---|---|
| Composer audit | N/A | 0 | no resolvable dependency tree to audit — Your requirements could not be resolved to an installable set of packages. Problem 1 |
| 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-order-source-reservations"],
  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.

