Here are the following steps which help you to Change Shippable Order Item Qty in Magento 2:
Step 1: Create new columns on sales_order_item table
Step 2: Define plugin in di.xml
Step 3: Rewrite getSimplyQtyTo Ship() function
Step 1: Create new columns on sales_order_item table
In this step we will create qty_preapreship column in sales_order_item table
File directory:
app/code/Magestore/OrderSuccess/Setup/InstallSchema.php
namespace Magestore\OrderSuccess\Setup; use Magento\Framework\Setup\InstallSchemaInterface; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\SchemaSetupInterface; class InstallSchema implements InstallSchemaInterface { /** * @param SchemaSetupInterface $setup * @param ModuleContextInterface $context * @return $this * @throws \Zend_Db_Exception */ public function install(SchemaSetupInterface $setup, ModuleContextInterface $context) { $installer = $setup; $installer->startSetup(); $setup->getConnection()->dropTable($setup->getTable('os_ordersuccess_batch')); $installer->getConnection()->addColumn( $installer->getTable('sales_order_item'), 'qty_prepareship', array( 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, 'nullable' => false, 'length' => '12,4', 'default' => 0, 'comment' => 'Qty Prepareship' ) ); $installer->endSetup(); return $this; } } namespace Magestore\OrderSuccess\Setup; use Magento\Framework\Setup\InstallSchemaInterface; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\SchemaSetupInterface; class InstallSchema implements InstallSchemaInterface { /** * @param SchemaSetupInterface $setup * @param ModuleContextInterface $context * @return $this * @throws \Zend_Db_Exception */ public function install(SchemaSetupInterface $setup, ModuleContextInterface $context) { $installer = $setup; $installer->startSetup(); $setup->getConnection()->dropTable($setup->getTable('os_ordersuccess_batch')); $installer->getConnection()->addColumn( $installer->getTable('sales_order_item'), 'qty_prepareship', array( 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, 'nullable' => false, 'length' => '12,4', 'default' => 0, 'comment' => 'Qty Prepareship' ) ); $installer->endSetup(); return $this; } }
Step 2: Define plug-in in di.xml
File directory:
app/code/Magestore/OrderSuccess/etc/di.xml
<?xml version="1.0" encoding="UTF-8"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <type name="Magento\Sales\Model\Order\Item"> <plugin name="AfterGetSimpleQtyToShip" type="Magestore\OrderSuccess\Plugin\Item\AfterGetSimpleQtyToShip" sortOrder="1" disabled="false"/> </type> </config>
Step 3: Rewrite getSimplyQtyTo Ship() function
File directory:
app/code/Magestore/OrderSuccess/Plugin/AfterGetSimpleQty
namespace Magestore\OrderSuccess\Plugin\Item; class AfterGetSimpleQtyToShip{ public function afterGetSimpleQtyToShip(\Magento\Sales\Model\Order\Item $item) { $qty = $item->getQtyOrdered() - $item->getQtyShipped() - $item->getQtyRefunded() - $item->getQtyCanceled() - $item->getQtyBackordered() - $item->getQtyPrepareship(); return max($qty, 0); } }
The following steps I mentioned above is the simple process for you to Change Shippable Order Item Qty in Magento 2. With this guideline, you can handle the Shippable Order Item Qty in Magento 2 easily. All stores has a Shippable Order Item Qty in Magento 2 with many elements.
Leave a Reply