Sometimes we need to perform some quick action for get data or update data in magento database then this root script help. Root script is easy to create and use. sometimes it’s save lots time of developer and client.
We can create root script for different reasons. For example, if you want to get the list of product which contain attribute x value y and update those product attribute a value b.
We can use root script for multiple reason. Another example, If client need a list of order which is shipped last month. then you can create script and give them data.
Create a script at root directory. Here is simple script.
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
ini_set('memory_limit', '5G');
error_reporting(E_ALL);
use Magento\Framework\App\Bootstrap;
require 'app/bootstrap.php';
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('Magento\Framework\App\State');
$state->setAreaCode('global');
# you can write your logic here
If your project root path is pub folder then above script in bootstrap.php path should be require '../app/bootstrap.php';
Here is another blog for delete database entries using script. I hope you like it.
https://www.magedad.com/how-to-create-root-script-to-delete-database-table-entries-in-magento2/
I hope this blog is useful for create root script in magento2. In case, I missed anything or need to add some more information, Don’t heisted to leave a comment in this blog, I’ll get back with some positive approach. Thank you ❤️
Keep loving ❤️ Keep inspiring 🤩 Keep liking 👍 No sharing 😄