Get source item data by source code and SKU Multi Source Inventory(MSI) Magento 2

We can use \Magento\InventoryApi\Api\SourceItemRepositoryInterface class with \Magento\Framework\Api\SearchCriteriaBuilder to get source item data by source code and product SKU. Here are the sample model class <?php namespace Mageprince\Testing\Model; class SourceItemModel { private $searchCriteriaBuilder; private $sourceItemRepository; public function __construct( ... \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder, \Magento\InventoryApi\Api\SourceItemRepositoryInterface $sourceItemRepository ... ) { $this->searchCriteriaBuilder = $searchCriteriaBuilder; $this->sourceRepository = $sourceRepository; } public function getSourcesItems($souceCode,…

Continue Reading Get source item data by source code and SKU Multi Source Inventory(MSI) Magento 2

Get source item data by source code Multi Source Inventory(MSI) in Magento 2

We can use \Magento\InventoryApi\Api\SourceItemRepositoryInterface class to get source items Here are the sample model class to get the sources item by source code <?php namespace Mageprince\Testing\Model; class SourceItemModel { private $searchCriteriaBuilder; private $sourceItemRepository; public function __construct( ... \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder, \Magento\InventoryApi\Api\SourceItemRepositoryInterface $sourceItemRepository ... ) { $this->searchCriteriaBuilder = $searchCriteriaBuilder; $this->sourceRepository = $sourceRepository; } public function getSourcesItems($souceCode) {…

Continue Reading Get source item data by source code Multi Source Inventory(MSI) in Magento 2

Get source item data by SKU Multi Source Inventory(MSI) Magento 2

You can get sources item by product SKU by class \Magento\InventoryApi\Api\GetSourceItemsBySkuInterface You can get source_item_id, source_code, sku, quantity and status I have created a sample model to show you how can you get sources item by SKU <?php namespace Mageprince\Testing\Model; class SourceListModel { private $sourceItemsBySku; public function __construct( ... \Magento\InventoryApi\Api\GetSourceItemsBySkuInterface $sourceItemsBySku, ... ) { $this->sourceItemsBySku…

Continue Reading Get source item data by SKU Multi Source Inventory(MSI) Magento 2

How to get list of sources Multi Source Inventory (MSI) programmatically in Magento 2

With the Magento version, 2.3 Multi-source inventory (MSI) Was Introduced. With the default Magento MSI, you can create multiple sources which contain stores data. like source_code, name, warehouse_id, latitude, longitude, etc. You can get all sources which are added by Magento admin by class Magento\InventoryApi\Api\SourceRepositoryInterface Here is the source collection factory class: Magento\Inventory\Model\ResourceModel\Source\CollectionFactory Here are…

Continue Reading How to get list of sources Multi Source Inventory (MSI) programmatically in Magento 2

Get admin URL in Magento 2

We can use \Magento\Backend\Helper\Data class to get Admin Url. /** * @var Magento\Backend\Helper\Data */ private $backendHelper; public function __construct( ... \Magento\Backend\Helper\Data $backendHelper ... ) { ... $this->backendHelper = $backendHelper; ... } public function getAdminUrl() { retrun $this->backendHelper->getHomePageUrl(); } You can get admin URL by getHomePageUrl() function of backend helper class Here you will get admin…

Continue Reading Get admin URL in Magento 2

Add a module in the composer with GitHub repository Magento 2

In this article, I will show you how we can add -magento 2 module in the composer. Composer is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you. Read more 1. Add module repository into Github First of…

Continue Reading Add a module in the composer with GitHub repository Magento 2

Get Module’s directory path in Magento 2

Sometimes we need to get module's directory path mainly when we working with libraries. In this article, I will show how we can get the module's directory path. Check this article for Get root directory path in Magento 2 Use Magento\Framework\Module\Dir class to get the module's directory paths. namespace MagePrince\Testing\Model; class Directories { private $directory;…

Continue Reading Get Module’s directory path in Magento 2

Notice: unserialize(); Error at offset in Magento 2.2

In this article, I will show how we can solve unserialize error in Magento 2. As per Magento 2.2 release note, Magento removes serialize/unserialize from most the code to improve protection against remote code execution attacks. Magento 2.2 Release Note: In general, we’ve removed serialize/unserialize from most the code to improve protection against remote code…

Continue Reading Notice: unserialize(); Error at offset in Magento 2.2

Get order id by increment id Magento 2

In this article, I will show you how you can load order by increment id in Magento 2 We can use the order interface Magento\Sales\Api\Data\OrderInterface to load order by increment id. By Object Manager: $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $incrementId = "100009633"; $orderInterface = $objectManager->create('Magento\Sales\Api\Data\OrderInterface'); $order = $orderInterface->loadByIncrementId($incrementId); // Print Order Object print_r($order->debug()); // Get Order Id…

Continue Reading Get order id by increment id Magento 2

Create dynamically link in customer account navigation in Magento 2

We can create custom customer account link with reference block customer_account_navigation with a custom block class 1) Add block class in customer_account.xml File: app/code/Vendor/Module/view/frontend/layout/customer_account.xml <?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <body> <referenceBlock name="customer_account_navigation"> <block class="{vendor}\{Module}\Block\Customer\Link" name="customer-account-navigation-new-product-link" after="-"> <arguments> <argument name="label" xsi:type="string">Some link</argument> <argument name="path" xsi:type="string">customer/somelink/index</argument> </arguments> </block> </referenceBlock> </body> </page> 2) Now create Link.php namespace Vendor\Module\Block\Customer;…

Continue Reading Create dynamically link in customer account navigation in Magento 2