Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Magento 2 - get product collection count via runtime
try {
require __DIR__ . '/app/bootstrap.php';
} catch (\Exception $e) {
echo $e->getMessage() . PHP_EOL;
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
/** @var \Magento\Framework\App\Http $app */
$app = $bootstrap->createApplication('Magento\Framework\App\Http');
$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
You can’t perform that action at this time.