reach-digital / magento2-order-source-reservations
reach-digital/magento2-order-source-reservations
Order Source Reservations
Installation
Make sure you have access to our private composer repository.
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).
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.
- If the SSA has been ran a single time we need to store the result, it can't
change. - 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.
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
-
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.
- Order Cancelled: The Stock reservation is nullified and the qty is released
-
Create invoice: 🔹Cron
MoveReservationsFromStockToSourceRunner:
Periodically we run the 'heavy' SSA on all orders that are succesfully
invoiced (and therefor authorized to be shipped).- 🔹OrderSelectionService
will return a list of unsourced orders based on a certain algorithm (only
byDateCreated implemented right now). - 🔹Selection criteria
All state:processing and unsourced orders. - 🔹MoveReservationsFromStockToSource
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.
- 🔹OrderSelectionService
-
Create shipment
- 🔹
DeductSourceAndNullifyReservationOnShipment:
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
- 🔹
-
Create creditmemo:
- 🔹
RevertSourceReservationsOnCreditBeforeShipment
will automatically revert any source reservations.
- 🔹
REST Api / Internal Api
Adds a filter to
GET /orders
called assigned_source_code.
searchCriteria[filterGroups][0][filters][0][conditionType] = 'eq';
searchCriteria[filterGroups][0][filters][0][field] = 'assigned_source_code';
searchCriteria[filterGroups][0][filters][0][value] = 'eu-1';
Adds source_reservations as an extension attribute on an order item, which
allows you to see the sources that are assigned to an order item.
Commits
Commits will be validated with
https://github.com/conventional-changelog/commitlint
Gittower: Gittower doesn't properly read your PATH variable and thus commit
validation doesn't work. Use gittower . to open this repo.
No changelog yet
The vendor hasn't published a changelog. Tagged releases appear in the Versions tab.
| Version | Stability | QA Status | Compatibility | Released |
|---|---|---|---|---|
| 1.4.0 | stable | Fail | Not compatible Details | 2021-07-14 10:55:51 |
| 1.4.0-canary.6 | stable | Not tested | Not yet tested Details | 2020-10-08 18:57:49 |
| 1.4.0-canary.5 | stable | Not tested | Not yet tested Details | 2020-10-08 17:28:15 |
| 1.3.2 | stable | Not tested | Not yet tested Details | 2020-10-08 16:56:47 |
| 1.4.0-canary.4 | stable | Not tested | Not yet tested Details | 2020-08-26 09:59:35 |
| 1.4.0-canary.3 | stable | Not tested | Not yet tested Details | 2020-08-26 09:03:36 |
| 1.4.0-canary.2 | stable | Not tested | Not yet tested Details | 2020-08-26 08:54:27 |
| 1.4.0-canary.1 | stable | Not tested | Not yet tested Details | 2020-08-19 15:39:12 |
| 1.3.1 | stable | Not tested | Not yet tested Details | 2020-08-12 12:39:47 |
| 1.3.0 | stable | Not tested | Not yet tested Details | 2020-08-05 09:09:52 |
| 1.2.7 | stable | Not tested | Not yet tested Details | 2020-08-04 18:37:35 |
| 1.2.6 | stable | Not tested | Not yet tested Details | 2020-07-10 07:44:26 |
| 1.2.5 | stable | Not tested | Not yet tested Details | 2020-07-09 19:44:07 |
| 1.2.4 | stable | Not tested | Not yet tested Details | 2020-07-06 21:26:35 |
| 1.2.3 | stable | Not tested | Not yet tested Details | 2020-07-03 10:12:35 |
| 1.2.2 | stable | Not tested | Not yet tested Details | 2020-06-23 12:23:31 |
| 1.2.1 | stable | Not tested | Not yet tested Details | 2020-06-22 07:02:07 |
| 1.2.0 | stable | Not tested | Not yet tested Details | 2020-06-19 12:37:31 |
| 1.1.0 | stable | Not tested | Not yet tested Details | 2020-06-19 12:35:05 |
| 1.0.2 | stable | Not tested | Not yet tested Details | 2020-05-14 11:56:47 |
| 1.0.1 | stable | Not tested | Not yet tested Details | 2020-01-20 10:32:16 |
| 1.0.0 | stable | Not tested | Not yet tested Details | 2020-01-10 15:03:41 |
Requires 3
| Package | Constraint |
|---|---|
| php | ~7.1.3||~7.2.0||~7.3.0||~7.4.0 |
| magento/framework | * |
| reach-digital/magento2-inventory-source-reservations | * |
Compatibility
Each Magento release line is installed on its supported PHP versions, then the module is built (DI compilation + static-content deploy) and its unit and integration suites are run. The matrix shows the lines and PHP versions the module is confirmed to install and run on. Code-quality results further down (phpstan, phpcs, …) are reported separately and never affect compatibility.
| 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 | Fail unknown | ||
| 2.4.9 | not tested | not tested |
Code Quality
Advisory checks against the module's source. Static analysis runs once across the whole module; PHPStan re-runs per Magento + PHP version because resolvable symbols differ between releases. These NEVER affect the Compatibility badge — 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's PHP against a real Magento install at the configured gate level. Re-runs per Magento and PHP version because resolvable symbols differ between releases. Cell → details modal.
Tests
Unit and integration suites, run for each applicable Magento and PHP version. A test failure speaks to the module's behaviour, not its compatibility with a Magento line, so it is reported here separately and never reddens the compatibility matrix.
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 |
Security
Security checks run directly against the module: an audit of its declared dependencies for known vulnerabilities (composer audit) and a scan of its source for malware and web-shell signatures. Each runs once. A malware detection fails the version outright.
More from reach-digital
View vendorTurn an existing module into recurring revenue.
If you already maintain a Magento 2 module on GitHub or GitLab, listing it on Packagento takes about five minutes. We mirror your tags, handle distribution signing, and route paid licenses through Stripe Connect, so you can keep shipping the way you already do.