scriptbaker / magento2-ship-out-of-stock-items
This Magento 2 module allows the creation of shipments for orders containing items that are out of stock. In default Magento, attempting to create a shipment for an order with out-of-stock items results in the error: "Not all of your products are available in the requested quantity." This module rem
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 0
Open Issues: 0
Type:magento2-module
Requires
- php: ^7.1|^8.0
- magento/framework: >=103
This package is not auto-updated.
Last update: 2025-04-19 19:32:47 UTC
README
Overview
The Scriptbaker_ShipOutOfStockItems
module for Magento 2 allows the creation of shipments for orders containing items that are out of stock. In default Magento, attempting to create a shipment for an order with out-of-stock items results in the error: "Not all of your products are available in the requested quantity." This module remedies that problem by adjusting the stock quantities to ensure the shipment can be processed.
Features
- Enables shipment creation for out-of-stock items.
- Automatically adjusts stock quantities to allow for shipment processing.
- Seamlessly integrates with Magento's Multi-Source Inventory (MSI) system.
Installation
-
Download the Module: Download the module package or clone the repository into the
app/code/Scriptbaker/ShipOutOfStockItems
directory. -
Enable the Module:
bin/magento module:enable Scriptbaker_ShipOutOfStockItems
-
Run Setup Upgrade:
bin/magento setup:upgrade
-
Clear Cache:
bin/magento cache:clean
Usage
Once the module is installed and enabled, it will automatically adjust stock quantities to allow for the creation of shipments for out-of-stock items. No additional configuration is necessary.
Implementation Details
The module listens to two key events and adjusts the stock quantities accordingly:
sales_order_shipment_save_before
:- Adjusts stock quantities before the shipment is created to ensure it can be processed without errors.
sales_order_shipment_save_after
:- Updates stock quantities after the shipment is saved to reflect the accurate inventory levels.
Files Included
registration.php
: Registers the module with Magento.etc/module.xml
: Declares the module and its version.etc/events.xml
: Registers the observers for thesales_order_shipment_save_before
andsales_order_shipment_save_after
events.Observer/AlwaysShipOrder.php
: Contains the logic for adjusting stock quantities before shipment creation.Observer/UpdateStockAfterShipment.php
: Contains the logic for updating stock quantities after the shipment is saved.
Observer Logic
AlwaysShipOrder
The AlwaysShipOrder
observer performs the following actions:
- Retrieves all items in the shipment.
- For each item, checks the available stock quantity.
- If the stock quantity is less than the requested shipment quantity, it adjusts the stock quantity to meet the shipment requirement.
- Saves the updated stock quantity using the
SourceItemsSaveInterface
.
UpdateStockAfterShipment
The UpdateStockAfterShipment
observer performs the following actions:
- Retrieves all items in the shipment.
- Updates the stock quantities after the shipment is saved to reflect accurate inventory levels.
- Ensures that the inventory system is up-to-date with the changes caused by the shipment.
Contributing
If you wish to contribute to this module, please fork the repository and submit a pull request with your changes. All contributions are welcome.
Support
If you encounter any issues or have any questions regarding the module, please open an issue on the repository or contact us at [hello@scriptbaker.com].
License
This module is open-source and licensed under the MIT License.
Thank you for using Scriptbaker_ShipOutOfStockItems
. We hope it helps improve your Magento 2 experience.