Skip to content

[Magento 2] Run PHP code externally

here example to load sales order data externally in magento 2, for example you’re going to use this url
http://yourmagento2url/test.php

<?php 

use Magento\Framework\App\Bootstrap;
require __DIR__ . '/../app/bootstrap.php';

$bootstrap = Bootstrap::create(BP, $_SERVER);

$obj = $bootstrap->getObjectManager();

$state = $obj->get('Magento\Framework\App\State');
$state->setAreaCode('frontend');

echo '<pre>';

$_order = $obj->get('\Magento\Sales\Model\Order')->load(1);


print_r($_order->getData());

/* get store config */

$konfig = $obj->get('\Magento\Framework\App\Config\ScopeConfigInterface');
$konfig = $konfig->getValue('payment/mypaymentgateway/api_url',\Magento\Store\Model\ScopeInterface::SCOPE_STORE);

echo 'config value "payment/mypaymentgateway/api_url" : '.$konfig;


?>

 

Share

Comments are closed.