How to get a product by its SKU programmatically?

Interface

Use the get() method of the [Magento\Catalog\Api\ProductRepositoryInterface] (https://github.com/magento/magento2/blob/cf7df72/app/code/Magento/Catalog/Api/ProductRepositoryInterface.php) interface:

It throws a \Magento\Framework\Exception\NoSuchEntityException exception if a product with the given SKU is not found.

Implementation

Usage

Example 1

Example 2

Example 3

Example 4

Example 5

Example 6

Example 7

https://github.com/magento/magento2/blob/cf7df72/app/code/Magento/Catalog/Model/CategoryLinkManagement.php#L105-L105

Example 8

https://github.com/magento/magento2/blob/cf7df72/app/code/Magento/Catalog/Model/CategoryLinkRepository.php#L42-L42

Example 9

Example 10

https://github.com/magento/magento2/blob/cf7df72/app/code/Magento/Catalog/Model/Product/Gallery/GalleryManagement.php#L56-L56

See also: