Tạo test scipt đơn giản với magento 2?

Tạo test scipt đơn giản với magento 2?

Tạo test scipt đơn giản với magento 2?

Magento test script thường được sử dụng để debug, import data hay viết 1 số test function trước mà ko cần tốn quá nhiều thời gian tạo module mới.

use Magento\Framework\App\Bootstrap;
include('app/bootstrap.php');
$bootstrap = Bootstrap::create(BP, $_SERVER);
ob_start();
$objectManager = $bootstrap->getObjectManager();


$state = $objectManager->get('Magento\Framework\App\State');
$state->setAreaCode('adminhtml');
$registry = $objectManager->get('\Magento\Framework\Registry');
$registry->register('isSecureArea', true);
echo "Start";

// Your test script

echo "Done";

Ngoài ra script cần được bảo vệ và dc thực thi bởi người viết, ko cho người khác truy cập. Đầu tiên cầu chuyển vào thử mục “scripts/test.php”. Sau đó dùng .htaccess bảo vệ script bằng chặn theo IP hay đặt htpaswd

order deny,allow
allow from 192.168.1.23 #Enter your ip address