Skip to content

ho-nl/magento2-ReachDigital_InventoryOrderSourceReservations

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

  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.

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: 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.
  3. Create shipment

  4. Create creditmemo:

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.