Skip to content

Instantly share code, notes, and snippets.

@ananth-iyer
Last active September 24, 2020 11:00
Show Gist options
  • Save ananth-iyer/dcdc0fb3ceed3c965503bd59b54b2f62 to your computer and use it in GitHub Desktop.
Save ananth-iyer/dcdc0fb3ceed3c965503bd59b54b2f62 to your computer and use it in GitHub Desktop.
Magento 2 External script
<?php
use Magento\Framework\App\Bootstrap;
require __DIR__ . '/app/bootstrap.php';
$bootstrap = Bootstrap::create(BP, $_SERVER);
$obj = $bootstrap->getObjectManager();
// set frontend scope - necessary
/** @var \Magento\Framework\App\State $state */
$state = $obj->get(\Magento\Framework\App\State::class);
$state->setAreaCode('adminhtml'); // others: frontend, crontab
/** @var \Magento\Store\Model\StoreManagerInterface $store */
$store = $obj->get(\Magento\Store\Model\StoreManagerInterface::class);
$store->setCurrentStore(0);
echo "Start...";
/** @var \class_path $_curl */
$class = $obj->create(<class path>::class);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment