Skip to content

Commit

Permalink
Merge pull request #134 from fredden/feature/remove-legacy-stock-rese…
Browse files Browse the repository at this point in the history
…rvations

Automatically truncate the `inventory_reservation` table upon module installation
  • Loading branch information
tr33m4n authored Feb 19, 2024
2 parents d8db36b + 197295b commit 04e1a34
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@

[![Build Status](https://app.travis-ci.com/AmpersandHQ/magento2-disable-stock-reservation.svg?branch=master)](https://app.travis-ci.com/AmpersandHQ/magento2-disable-stock-reservation)

This module disables the inventory reservation logic introduced as part of MSI in Magento 2.3.3 - see
This module disables the inventory reservation logic introduced as part of MSI in Magento 2.3.3 - see
https://github.com/magento/inventory/issues/2269 for more information about the way MSI was implemented, and the issues
that can happen with external WMS integrations.

## The Problem

During the order placement and fulfilment processes, Magento's MSI implementation will not decrement stock on order
During the order placement and fulfilment processes, Magento's MSI implementation will not decrement stock on order
placement - it will only do so on order shipment and refund.

## Our Approach

This module will:

* Prevent all writes to the inventory_reservations table. It does so by using an `around` plugin on `PlaceReservationsForSalesEventInterface`
* Prevent all writes to the `inventory_reservation` table. It does so by using an `around` plugin on `PlaceReservationsForSalesEventInterface`
* Trigger stock deductions on order placement. See `inventory_sales_source_deduction_processor` plugin on `Magento\Sales\Model\Service\OrderService`.
* Prevent stock deductions on order shipment. See disabled `inventory_sales_source_deduction_processor` observer on `sales_order_shipment_save_after` event.
* Replenish stock for cancelled order items. See `inventory` observer on `sales_order_item_cancel` event.
* Replenish stock when a credit memo is issued. See `src/Observer/RestoreSourceItemQuantityOnRefundObserver.php`
* Requires that "Back to stock" is checked or "Automatically Return Credit Memo Item to Stock" is configured
* https://docs.magento.com/user-guide/configuration/catalog/inventory.html#product-stock-options
* Truncate (ie, remove all historic entries from) the `inventory_reservation` table upon installation.

## Additional Notes

* Make sure to truncate any existing reservations after installing this module, see https://github.com/AmpersandHQ/magento2-disable-stock-reservation/issues/41
* Both the `inventory` and `cataloginventory_stock` should be on the same mode (`Update on Save` or `Schedule`) for this module to work as expected. If you are running this on `Schedule` you should have crons activated.
47 changes: 47 additions & 0 deletions src/Setup/Patch/Schema/RemoveExistingReservations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Ampersand\DisableStockReservation\Setup\Patch\Schema;

use Magento\Framework\Setup\SchemaSetupInterface;
use Magento\Framework\Setup\Patch\SchemaPatchInterface;

class RemoveExistingReservations implements SchemaPatchInterface
{
private const INVENTORY_RESERVATION_TABLE_NAME = 'inventory_reservation';
private $setup;

public function __construct(
SchemaSetupInterface $setup
) {
$this->setup = $setup;
}

/**
* {@inheritdoc}
*/
public function apply()
{
$connection = $this->setup->getConnection();
$tableName = $connection->getTableName(self::INVENTORY_RESERVATION_TABLE_NAME);

if ($connection->isTableExists($tableName)) {
$connection->truncateTable($tableName);
}
}

/**
* {@inheritdoc}
*/
public static function getDependencies(): array
{
return [];
}

/**
* {@inheritdoc}
*/
public function getAliases(): array
{
return [];
}
}

0 comments on commit 04e1a34

Please sign in to comment.