1

I've a form in which I'm using ajax to get product sku and quantity from user.

I successfully got those entered data in form to my custom module's controller.

Now I need to verify that user's entered value with actual product sku in my site.

How can I do that inside my controller's execute() function?

1 Answer 1

1

Use below code in your controller class :

protected $_product;

public function __construct(
        \Magento\Catalog\Model\Product $product
) {
    $this->_product = $product;
}

public function execute()
{ 
   $sku = 'your_sku';
   if($this->_product->getIdBySku($sku)) {
     echo 'product exist';    
   }
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.