Skip to content

CLI Reference

Ievgen Shakhsuvarov edited this page Jul 16, 2019 · 6 revisions

DEVELOP User Guide - This guide provides MSI Develop Branch/Active Development merchant information on Magento Multi Source Inventory (MSI) features and project.


MSI Inventory Management provides CLI commands to manage inventory data and configuration settings.

These commands include:

  • Checking and resolving reservation inconsistencies affecting salable quantity
  • Adding geocodes for the Distance Priority algorithm

Resolve reservations inconsistencies

Reservations place a salable quantity hold for product SKUs per stock. When you ship, add products, cancel, or refund an order, compensation reservations enter to place or clear these holds.

MSI provides two CLI commands to check and resolve reservation inconsistencies:

  • inventory:reservation:list-inconsistencies
  • inventory:reservation:create-compensations

What causes reservation inconsistencies?

Inventory Management generates reservations for key events:

  • Order placement (initial reservation)
  • Order shipment (compensation reservation)
  • Refund order or issue a credit memo (compensation reservation)
  • Order cancellation (compensation reservation)

Reservation inconsistencies may occur when Inventory Management loses the initial reservation and enters too many reservation compensations (overcompensating and leading to inconsistent amounts), or correctly places the initial reservation but loses compensational reservations.

The following configurations and events can cause reservation inconsistencies:

  • Upgrade Magento to 2.3.x with orders not in a completed state (Complete, Canceled, or Closed). Inventory Management will create compensational reservations for these orders, but it will not enter or have the initial reservation that deducts from the salable quantity. We recommend using these commands after upgrading to Magento v2.3.x from 2.1.x or 2.2.x. If you have pending orders, the commands correctly update your salable quantity and reservations for sales and order fulfillment.
  • You do not manage stock then later change this configuration. You may start using 2.3.x with Manage Stock set to "No" in the Magento configuration. Magento does not place reservations at order placement and shipment events. If you later enable the Manage Stock configuration and some orders were created at that time, the Salable Qty would be corrupted with compensation reservation when you handle and fulfill that order.
  • You re-assign the Stock for a Website while orders submit to that website. The initial reservation enters for the initial stock and all compensational reservation enter to the new stock.
  • The sum total of all reservations may not resolve to 0. All reservations in the scope of an Order in a completed state (Complete, Canceled, Closed) should resolve to 0, clearing all salable quantity holds.

List inconsistencies command

The list-inconsistencies command detects and lists all reservation inconsistencies. Use the options to check completed or incomplete orders, or all.

bin/magento inventory:reservation:list-inconsistencies

Command options:

  • -c, --complete-orders - Returns inconsistencies for only completed orders. Incorrect reservations may still be on hold for completed orders.
  • -i, --incomplete-orders - Returns inconsistencies for only incomplete orders (partially shipped, unshipped). Incorrect reservations may hold too much or not enough salable quantity for the orders.
  • -r, --raw - Returns inconsistences for all orders in raw output.

If no issues are found, this message returns: No order inconsistencies were found.

Returned values are in <ORDER_INCREMENT_ID>:<SKU>:<QUANTITY>:<STOCK-ID> format:

  • Order ID indicates the scope of the inconsistency.
  • SKU indicates the product with the inconsistency.
  • Quantity sets the amount to enter for the reservation compensation.
  • Stock ID defines to scope for stock, which uses the reservations to calculate salable quantity.

Example responses:

Inconsistencies found on following entries:
Order 172:
- Product bike-123 should be compensated by +2.000000 for stock 1
172:bike-123:+2.000000:1

Create compensations command

The create-compensations command creates compensation reservations using the returned list of inconsistencies. Depending on the issue, new reservations are created to either place or release a hold on salable quantity. When these are generated, the metadata in the database indicates these are "event_type":"manual_compensation".

You can run both commands by piping list-inconsistencies and create-compensations to check and immediately create compensations. If not, you will need to provide the compensations using the format <ORDER_INCREMENT_ID>:<SKU>:<QUANTITY>:<STOCK-ID> such as 172:bike-123:+2.000000:1.

bin/magento inventory:reservation:create-compensations

Command options:

  • -c, --complete-orders - Creates reservations for only completed order inconsistencies.
  • -i, --incomplete-orders - Creates reservations for only incomplete order inconsistencies.
  • -r, --raw - Raw output.
  • -d, --dry-run - Simulates the reservation creation without affecting reservations. Use this option to get a test run of potential reservation compensations.

Requested compendations must be provided using this format: <ORDER_INCREMENT_ID>:<SKU>:<QUANTITY>:<STOCK-ID>.

If the format of the request is incorrect, the following message displays: A list of compensations needs to be defined as argument or STDIN.

As reservations are entered, messages display indicating the updates by SKU, order, and stock.

To check and resolve reservation inconsistencies

Check reservation inconsistencies for all orders and create compensations by piping these commands together:

bin/magento inventory:reservation:list-inconsistencies -r | bin/magento inventory:reservation:create-compensations

Example response:

Following reservations were created:
- Product bike-123 was compensated by +2.000000 for stock 1
- Product bikehat-456 was compensated by +1.000000 for stock 1

After updates complete, run the list command to verify:

bin/magento inventory:reservation:list-inconsistencies -r

If no other issues are found, this message displays:

No order inconsistencies were found.

Import geocodes

Inventory Management provides the Distance Priority algorithm, which helps determine the best option for shipping a full or partial order. The algorithm uses GPS information or geocodes to calculate the distance between the source (a warehouse or other physical location) of each item in an order and the shipping address. Based on those results, the algorithm recommends which source should be used to ship out each item in the order.

The merchant selects the provider of the GPS or geocode data required to calculate distances:

  • Google MAP uses Google Maps Platform services to calculate the distance and time between the shipping destination address and source locations. This option requires a Google billing plan and may incur charges through Google.

  • Offline calculation calculates the distance using data downloaded from geonames.org and imported into Magento with a command. This option is free of charge.

Import geocodes for offline calculation

Enter the following command with a space-separated list of ISO-3166 alpha2 country codes:

bin/magento inventory-geonames:import <country code> <country code> ...

For example:

bin/magento inventory-geonames:import us ca gb de

The system downloads and imports the geocodes data to your database, then displays the message Importing <country code>: OK.

MSI Documentation:

  1. Technical Vision. Catalog Inventory
  2. Installation Guide
  3. List of Inventory APIs and their legacy analogs
  4. MSI Roadmap
  5. Known Issues in Order Lifecycle
  6. MSI User Guide
  7. DevDocs Documentation
  8. User Stories
  9. User Scenarios:
  10. Technical Designs:
  11. Admin UI
  12. MFTF Extension Tests
  13. Weekly MSI Demos
  14. Tutorials
Clone this wiki locally