---
title: "How To Check If Product With SKU Exists In Magento 2?"
url: "https://magecomp.com/blog/check-if-product-with-sku-exists-magento-2/"
date: "2021-08-07T10:00:09+00:00"
modified: "2025-01-29T11:21:01+00:00"
author:
  name: "Dhiren Vasoya"
  url: "https://magecomp.com/"
categories:
  - "Magento Tutorials"
word_count: 348
reading_time: "2 min read"
summary: "Hello, Magento Buddies!"
description: "Programmatic Way To Check If Product With SKU Exists In Magento 2. $helper = $this->helper('Vendor\Extension\Helper\Data');"
keywords: "Magento Tutorials"
language: "en"
schema_type: "Article"
related_posts:
  - title: "How to Protect Your Magento 2 Images and Source Code from Stealing?"
    url: "https://magecomp.com/blog/protect-magento-2-images-source-code-from-stealing/"
  - title: "How to Get Rid Of Non-used Product Images from Database of your Magento 2"
    url: "https://magecomp.com/blog/get-rid-of-non-used-product-images-magento-2/"
  - title: "How to Add Custom Fields to Checkout Page in Magento 2?"
    url: "https://magecomp.com/blog/add-custom-fields-to-checkout-page-magento-2/"
---

# How To Check If Product With SKU Exists In Magento 2?

_Published: August 7, 2021_  
_Author: Dhiren Vasoya_  

![How To Check If Product With SKU Exists In Magento 2](https://magecomp.com/blog/wp-content/uploads/2021/08/How-To-Check-If-Product-With-SKU-Exists-In-Magento-2-1024x512.webp)

**Hello, Magento Buddies!**

Are you facing the same challenge as many developers today? Developing an entire functionality of a product using its ID only to find at the end that the product has gone to meet the maker? The product is no more in your store?
But, as the saying goes, every problem comes with a solution too! And so, here I am today with a solution for all of you facing the aforementioned problem. It is imperative to recheck once if the product exists or not in your Magento 2 store before using the SKU for any purpose elsewhere.
## Programmatic Way To Check If Product With SKU Exists In Magento 2
**Step 1:** Create a file named **Data.php** in the below-given path.
**app\code\Vendor\Extension\Helper\**

Now, add the below code in the file.
```
<?php

namespace VendorExtensionHelper;

use MagentoFrameworkAppHelperContext;

use MagentoCatalogModelProduct;

use MagentoFrameworkAppHelperAbstractHelper;

class Data extends AbstractHelper

{

    protected $product;

    public function __construct(Context $context,Product $product)

    {

        $this->product = $product;

        parent::__construct($context);

    }

    public function Checkproductexist($product_sku)

    {

        if ($this->product->getIdBySku($product_sku))

      $this->_logger->info('Product is Exist');

        else

  $this->_logger->info('Product is not Exist');

    }

}
```

**Step 2:** Next, add the below-given code in **module phtml** file:
```
<?php

$helper = $this->helper('VendorExtensionHelperData');

$product_sku = "product_sku"; // add your sku here

$helper->Checkproductexist($product_sku);

?>
```

After you have added the above code, check whether the product exists or not in the **system.log (var/log/system.log)** file.
## Summing It Up!
That was one quick solution. Add this code properly and you will surely get the desired results. Also, it is quite important as checking whether the product exists or not is crucial before using its SKU anywhere.
To get your Magento store custom-developed, [**Hire a Dedicated Magento Developer**](https://magecomp.com/hire-magento-developer.html) and we will create your store just as you require it to be! Also, share this solution with your Magento friends. Catch you later. Till then, have a G’day!
**Happy Coding!**


---

_View the original post at: [https://magecomp.com/blog/check-if-product-with-sku-exists-magento-2/](https://magecomp.com/blog/check-if-product-with-sku-exists-magento-2/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-08-05 17:37:29 UTC_  
