0

I have only one product in the catalog with sku "prodotto". The product is in the default category, it is also visible on frontend (I can see it and browse to it on frontend), it is in stock, it has positive quantity. It is set to be visible and set to display in Catalog, Search, and it is enabled. I can see it in the table catalog_product_entity. However, when I try to check for this product by its sku ("prodotto"), I am getting the message:

Product with Sku: prodotto not found in the catalog.

This is my code:

$connection = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER) -> getObjectManager() -> get("\Magento\Framework\App\ResourceConnection") -> getConnection();

$sql = "SELECT COUNT(*) AS count_no FROM " . _getTableName('catalog_product_entity') . " WHERE sku = ?";

try {
    $count = $connection -> fetchAll($sql, array('prodotto'));
} catch (PDOException $pdoe) {
    echo $pdoe;
} catch (Exception $e) {
    echo $e;
}

Why is this hapenning?

5
  • Are you sure there are no white spaces in your product SKU
    – John
    Commented Mar 17, 2017 at 10:38
  • There are no whitespaces anywhere in the database, on admin and in the code, in the sku. Commented Mar 17, 2017 at 10:44
  • Why are you approaching with a direct SQL access? You should use "ProductRepositoryInterface". Commented Mar 17, 2017 at 11:35
  • This is a task that I have to do, given to me. Commented Mar 17, 2017 at 11:36
  • It looks like I had some errors prior to the missing product method, and these I resolved with using the same PHP version in CLI as Magento 2 is using in web server (in the browser). Commented Mar 17, 2017 at 13:52

1 Answer 1

0

It looks like I had some errors prior to the missing product method, and these I resolved with using the same PHP version in CLI as Magento 2 is using in web server (in the browser).

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.