Get the Source Full name from the source code in Magento 2 MSI

We can use Repository \Magento\InventoryApi\Api\SourceRepositoryInterface to get the source by code

when we have a source code with us if we want to get the source name we may call a block function to load the source name with the source Id

Block Code


constructor:

    \Magento\InventoryApi\Api\SourceRepositoryInterface $sourceRepository


       $this->sourceRepository = $sourceRepository;


-------------------------------------------------------------------------

public function getSourceName($sourceCode)
    {
        $sourceData = $this->sourceRepository->get($sourceCode);
        $sourename = $sourceData->getName();

    return $sourename;
    }

Phtml File

$sourename = $dealerData->getSourceName($sourceCode); ?>
<span>WareHouse : <span class="method"><?= $sourename."<br>";?></span></span>

Leave a comment

Your email address will not be published. Required fields are marked *