Magento 2: Application initialization and bootstrap

This process can be used to create cron file for the required operation like insertion and display data of Magento like customer, product, category. We can create file in the root of the website and write the script to process the custom script.

I have created a file called test.php in the root of my Magento instance. In this file, you can write any code of Magento to display or insert data.


	ini_set('display_errors', 1);

	// Change path according to your import file
	require __DIR__ . '/app/bootstrap.php';

	use Magento\Framework\App\Bootstrap;

	$bootstrap = Bootstrap::create(BP, $_SERVER);
	$objectManager = $bootstrap->getObjectManager();

	$state = $objectManager->get('Magento\Framework\App\State');

	try {   

		$productId = 1;
		$product = $objectManager->get('Magento\Catalog\Model\ProductRepository')

		echo '<pre>';
		echo '</pre>';

	} // end of try
	catch(Exception $e) {