Hello Magento Friends,
In this blog, I will explain How to Get Product Multi Source Inventory (MSI) Programmatically in Magento 2.
First, let’s understand what is Multi Source Inventory (MSI ) in Magento 2.
Contents
Multi Source Inventory helps to manage inventory by location. Merchants can link inventories to one or multiple websites without third-party extensions or platforms. MSI improves inventory management irrespective of customer or warehouse location, product type or sales channel.
Let’s get back to the point and find out the method to Get Product Multi Source Inventory (MSI) Programmatically in Magento 2.
Step 1: We are getting data in the root script. Move to the below file path.
magento_root_directory\sourceinventory.php
Now add the code as follows.
<?php use Magento\Framework\App\Bootstrap; use Magento\Store\Model\ScopeInterface; require './app/bootstrap.php'; $bootstrap = Bootstrap::create(BP, $_SERVER); $objectManager = $bootstrap->getObjectManager(); $resource = $objectManager->get('Magento\Framework\App\ResourceConnection'); $connection = $resource->getConnection(); $state = $objectManager->get('Magento\Framework\App\State'); $state->setAreaCode('frontend'); try { $sku = 'simple product'; // item sku $sourceinventorys = $objectManager->get('\Magento\InventoryCatalogAdminUi\Model\GetSourceItemsDataBySku'); $data = $sourceinventorys->execute($sku); foreach ($data as $source) { echo "<pre>"; print_r($source); echo "<pre>"; } }catch(\Exception $e) { print_r($e->getMessage()); }
Output:
Hence, this way, you can Get Product Multi Source Inventory (MSI) Programmatically in Magento 2. If you have any doubts, let me know through the comment box and share the article with your friends. See you in the next tutorial; till then, stay with us!
Happy Coding!
E-commerce has transformed the way consumers shop for products and services and interact with businesses.…
The e-commerce world is constantly in flux. New tech and strategies emerge daily to help…
Hello Magento Friends, In today’s blog, we will discuss adding a header and footer to…
Hello React Native Friends, Building a visually appealing and responsive mobile app is crucial in…
We're thrilled to announce the release of Hyvä Themes 1.3.6 and 1.3.7! These latest updates…
Your e-commerce platform is surging - orders are rolling in, traffic spikes are becoming the…