Having a bit of an issue with this one, I managed to get a working interface to Magento by including the following code, which in turn includes the Magento 2 bootstrap.php
use Magento\Framework\App\Bootstrap;
require_once("../app/bootstrap.php");
$params = $_SERVER;
$bootstrap = Bootstrap::create(BP, $params);
$obj = $bootstrap->getObjectManager();
$state = $obj->get('Magento\Framework\App\State');
$state->setAreaCode('adminhtml');
return $obj;
which returns an object that has the callable Magento methods. I've been trying to convert this into a callable class, so that I can call new magento() and have the same functionality, but in more compact code.
use Magento\Framework\App\Bootstrap;
require_once("../app/bootstrap.php");
class magento extends Bootstrap {
public $params;
private $bootstrap;
public $obj;
private $state;
public function __construct() {
$this->params = $_SERVER;
$this->bootstrap = Bootstrap::create(BP, $this->params);
$this->obj = $this->bootstrap->getObjectManager();
$this->state = $this->obj->get('Magento\Framework\App\State');
$this->state->setAreaCode('adminhtml');
return $this->obj;
}
}
However, when running this class, the subsquent code
$product = $obj->get('Magento\Catalog\Model\ProductRepository')->getById( $entity_id );
the get function is being called from the magento class, not the $object
Fatal error: Uncaught Error: Call to undefined method magento::get()
I think I'm missing something obvious, but can't quite get my head around it.
$app = $bootstrap->createApplication('MyClass'); $bootstrap->run($app);
And try this link magento.stackexchange.com/questions/39981/…