Skip to content

Instantly share code, notes, and snippets.

@aleron75
Created June 10, 2016 21:03
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aleron75/648624e22744d5ed88037b6ac56ddf54 to your computer and use it in GitHub Desktop.
Save aleron75/648624e22744d5ed88037b6ac56ddf54 to your computer and use it in GitHub Desktop.
Magento 2 - get product collection count via runtime
<?php
try {
require __DIR__ . '/app/bootstrap.php';
} catch (\Exception $e) {
echo $e->getMessage() . PHP_EOL;
exit(1);
}
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
/** @var \Magento\Framework\App\Http $app */
$app = $bootstrap->createApplication('Magento\Framework\App\Http');
$app->launch();
$objectManager = $bootstrap->getObjectManager();
$productFactory = $objectManager->create('Magento\Catalog\Model\ProductFactory');
$collection = $productFactory->create()->getCollection();
echo 'Total products:', $collection->count(), PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment