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?

  • Are you sure there are no white spaces in your product SKU – John Mar 17 '17 at 10:38
  • There are no whitespaces anywhere in the database, on admin and in the code, in the sku. – Vladimir Despotovic Mar 17 '17 at 10:44
  • Why are you approaching with a direct SQL access? You should use "ProductRepositoryInterface". – Phoenix128_RiccardoT Mar 17 '17 at 11:35
  • This is a task that I have to do, given to me. – Vladimir Despotovic Mar 17 '17 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). – Vladimir Despotovic Mar 17 '17 at 13:52
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, privacy policy and cookie policy

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