Skip to content

Instantly share code, notes, and snippets.

@freestream
Last active April 28, 2020 11:27
Show Gist options
  • Save freestream/80f115879939e984489f55cce74072a2 to your computer and use it in GitHub Desktop.
Save freestream/80f115879939e984489f55cce74072a2 to your computer and use it in GitHub Desktop.
Bootstrap Magento 2
<?php
/**
*
* This script will load the Magento 2 Object Manager, after which you
* can execute anything you want. "One time" scripts, just to fool
* around with Magento's functionality or to debug stuff.
*
* Place this file in the root folder of the Magento instance and execute:
* php magento2-bootstrap.php
*
*/
// Bootstrapping Magento 2.. 🚀
use Magento\Framework\App\Bootstrap;
include('app/bootstrap.php');
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('Magento\Framework\App\State');
$state->setAreaCode(\Magento\Framework\App\Area::AREA_GLOBAL);
// Let's code! 💪
/////////////////////////////////////////////////////////////
/**
* Or grab one of these examples ❤
*/
// Retrieve order by entity_id
//
//$orderRepository = $objectManager->get('Magento\Sales\Api\OrderRepositoryInterface');
//$orderRepository->get(1);
//// Encrypt value through Magento 2 encryption interface
//$encryptor = $objectManager->get('Magento\Framework\Encryption\EncryptorInterface');
//$encryptedAccessToken = $encryptor->encrypt("Super secret token");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment