{"id":673,"date":"2019-11-12T19:40:39","date_gmt":"2019-11-12T19:40:39","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/2019\/11\/12\/load-products-by-sku-in-magento-2\/"},"modified":"2025-05-22T15:24:25","modified_gmt":"2025-05-22T09:54:25","slug":"load-products-by-sku-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/load-products-by-sku-in-magento-2\/","title":{"rendered":"How To Load Products by SKU in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Earlier, I posted a solution to <a href=\"https:\/\/meetanshi.com\/blog\/get-product-collection-by-category-id-in-magento-2\/\" target=\"_blank\" rel=\"noreferrer noopener\">get product collection by category ID in Magento 2<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The idea was to get the product information in Magento 2.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With a similar idea, but a different approach, I&#8217;ve come up with a solution to get product information by SKU in Magento 2 store.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can <em><strong>load products by SKU in Magento 2<\/strong><\/em> and then use the details for either developing an SKU based feature or fulfill crazy client requirements!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Method To Load Products by SKU in Magento 2:<\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\nnamespace Vendor\\Module\\Helper;\nuse Magento\\Framework\\App\\Helper\\Context;\nuse Magento\\Catalog\\Model\\ProductRepository;\nclass Data extends AbstractHelper\n{\n    protected $productRepository;\n    public function __construct(Context $context, ProductRepository $productRepository)\n    {\n        $this->productRepository = $productRepository;\n        parent::__construct($context);\n    }\n    public function getProductData($sku)\n    {\n        if ($this->productRepository->get($sku)) \n        {\n            $product = $this->productRepository->get($sku);\n            $id = $product->getEntityId();\n            $name = $product->getName();\n            print_r($product->getData()); \/\/ for all data       \n        }\n    }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s it. Easy peasy, isn\u2019t it? You can also use <a href=\"https:\/\/meetanshi.com\/blog\/magento-2-api-get-product-by-sku\/\" target=\"_blank\" rel=\"noreferrer noopener\">Magento 2 API to get products by SKU<\/a> by calling a GET request.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Do share the post with fellow developers via social media.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thanks.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Earlier, I posted a solution to get product collection by category ID in Magento 2. The idea was to get the product information in Magento&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-673","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/673","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=673"}],"version-history":[{"count":3,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/673\/revisions"}],"predecessor-version":[{"id":15188,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/673\/revisions\/15188"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=673"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=673"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=673"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}