Magento 2.1 - Load Product in External Script The 2019 Stack Overflow Developer Survey Results Are In Unicorn Meta Zoo #1: Why another podcast? Announcing the arrival of Valued Associate #679: Cesar ManaraI created a custom module ,but getting error, not able to figure out what the error is about. How to get out of this error?Magento2 - create new/update category programmatically for specific storeView not workingPrice not getting updated for second product…Magento 2.1 Create a filter in the product grid by new attributeMagentoVaultApiDataPaymentTokenInterfaceFactory throws an exception during CheckoutList Products of CategoryMagento 2 : Custom module plugin is not workingError on editing categories in Magento 2Form is not displayed on panel admin Magento 2Magento 2 load external script in my custom page
Is there a way to generate uniformly distributed points on a sphere from a fixed amount of random real numbers per point?
Did the UK government pay "millions and millions of dollars" to try to snag Julian Assange?
One-dimensional Japanese puzzle
"... to apply for a visa" or "... and applied for a visa"?
Homework question about an engine pulling a train
Single author papers against my advisor's will?
Is there a writing software that you can sort scenes like slides in PowerPoint?
Simulating Exploding Dice
What to do when moving next to a bird sanctuary with a loosely-domesticated cat?
What is the padding with red substance inside of steak packaging?
Why can't devices on different VLANs, but on the same subnet, communicate?
Make it rain characters
Is it ethical to upload a automatically generated paper to a non peer-reviewed site as part of a larger research?
Can I visit the Trinity College (Cambridge) library and see some of their rare books
Button changing its text & action. Good or terrible?
Solving overdetermined system by QR decomposition
Is this wall load bearing? Blueprints and photos attached
Nested ellipses in tikzpicture: Chomsky hierarchy
What can I do if neighbor is blocking my solar panels intentionally?
How do you keep chess fun when your opponent constantly beats you?
Student Loan from years ago pops up and is taking my salary
Why did Peik Lin say, "I'm not an animal"?
For what reasons would an animal species NOT cross a *horizontal* land bridge?
Does Parliament hold absolute power in the UK?
Magento 2.1 - Load Product in External Script
The 2019 Stack Overflow Developer Survey Results Are In
Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar ManaraI created a custom module ,but getting error, not able to figure out what the error is about. How to get out of this error?Magento2 - create new/update category programmatically for specific storeView not workingPrice not getting updated for second product…Magento 2.1 Create a filter in the product grid by new attributeMagentoVaultApiDataPaymentTokenInterfaceFactory throws an exception during CheckoutList Products of CategoryMagento 2 : Custom module plugin is not workingError on editing categories in Magento 2Form is not displayed on panel admin Magento 2Magento 2 load external script in my custom page
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I'm porting over a little web service developed by a previous developer that pulled product data from an older Magento 1.9 install and spits it out as a json response.
They bootstrapped Magento 1.9 with this:
$_SERVER['MAGE_IS_DEVELOPER_MODE'] = true;
require_once $_SERVER['DOCUMENT_ROOT'].'/app/Mage.php';
umask(0);
Mage::app('default');
And they loaded product data with:
$productHelper = Mage::getModel('catalog/product');
$product = $productHelper->load($product_id);
With Magento 2.1 I'm bootstrapping with:
require getenv('MAGENTO_PATH') . 'app/bootstrap.php';
$bootstrap = MagentoFrameworkAppBootstrap::create(BP, $_SERVER);
$app = $bootstrap->createApplication('MagentoApp');
$bootstrap->run($app);
return $app->getObjectManager();
Here's the MagentoApp code:
class MagentoApp extends MagentoFrameworkAppHttp implements MagentoFrameworkAppInterface
protected $objectManager;
public function launch()
$this->_state->setAreaCode('frontend');
return $this->_response;
public function catchException(MagentoFrameworkAppBootstrap $bootstrap, Exception $exception)
return false;
public function getObjectManager()
return $this->_objectManager;
When I go to get the Magento Product in the little web service's product model, I'm using
$objectManager = $app->getObjectManager();
$product = $objectManager
->get('MagentoCatalogModelProductRepository')
->getById($product_id);
and getting the error Call to a member function get() on null (referring to the $objectManager as null) . What's weird is if I exit(var_dump($product->getData()) after that method call, I get the actual product data just fine.
If anyone could shed any light on this, it would be much appreciated.
Thanks very much.
magento-2.1 external
add a comment |
I'm porting over a little web service developed by a previous developer that pulled product data from an older Magento 1.9 install and spits it out as a json response.
They bootstrapped Magento 1.9 with this:
$_SERVER['MAGE_IS_DEVELOPER_MODE'] = true;
require_once $_SERVER['DOCUMENT_ROOT'].'/app/Mage.php';
umask(0);
Mage::app('default');
And they loaded product data with:
$productHelper = Mage::getModel('catalog/product');
$product = $productHelper->load($product_id);
With Magento 2.1 I'm bootstrapping with:
require getenv('MAGENTO_PATH') . 'app/bootstrap.php';
$bootstrap = MagentoFrameworkAppBootstrap::create(BP, $_SERVER);
$app = $bootstrap->createApplication('MagentoApp');
$bootstrap->run($app);
return $app->getObjectManager();
Here's the MagentoApp code:
class MagentoApp extends MagentoFrameworkAppHttp implements MagentoFrameworkAppInterface
protected $objectManager;
public function launch()
$this->_state->setAreaCode('frontend');
return $this->_response;
public function catchException(MagentoFrameworkAppBootstrap $bootstrap, Exception $exception)
return false;
public function getObjectManager()
return $this->_objectManager;
When I go to get the Magento Product in the little web service's product model, I'm using
$objectManager = $app->getObjectManager();
$product = $objectManager
->get('MagentoCatalogModelProductRepository')
->getById($product_id);
and getting the error Call to a member function get() on null (referring to the $objectManager as null) . What's weird is if I exit(var_dump($product->getData()) after that method call, I get the actual product data just fine.
If anyone could shed any light on this, it would be much appreciated.
Thanks very much.
magento-2.1 external
add a comment |
I'm porting over a little web service developed by a previous developer that pulled product data from an older Magento 1.9 install and spits it out as a json response.
They bootstrapped Magento 1.9 with this:
$_SERVER['MAGE_IS_DEVELOPER_MODE'] = true;
require_once $_SERVER['DOCUMENT_ROOT'].'/app/Mage.php';
umask(0);
Mage::app('default');
And they loaded product data with:
$productHelper = Mage::getModel('catalog/product');
$product = $productHelper->load($product_id);
With Magento 2.1 I'm bootstrapping with:
require getenv('MAGENTO_PATH') . 'app/bootstrap.php';
$bootstrap = MagentoFrameworkAppBootstrap::create(BP, $_SERVER);
$app = $bootstrap->createApplication('MagentoApp');
$bootstrap->run($app);
return $app->getObjectManager();
Here's the MagentoApp code:
class MagentoApp extends MagentoFrameworkAppHttp implements MagentoFrameworkAppInterface
protected $objectManager;
public function launch()
$this->_state->setAreaCode('frontend');
return $this->_response;
public function catchException(MagentoFrameworkAppBootstrap $bootstrap, Exception $exception)
return false;
public function getObjectManager()
return $this->_objectManager;
When I go to get the Magento Product in the little web service's product model, I'm using
$objectManager = $app->getObjectManager();
$product = $objectManager
->get('MagentoCatalogModelProductRepository')
->getById($product_id);
and getting the error Call to a member function get() on null (referring to the $objectManager as null) . What's weird is if I exit(var_dump($product->getData()) after that method call, I get the actual product data just fine.
If anyone could shed any light on this, it would be much appreciated.
Thanks very much.
magento-2.1 external
I'm porting over a little web service developed by a previous developer that pulled product data from an older Magento 1.9 install and spits it out as a json response.
They bootstrapped Magento 1.9 with this:
$_SERVER['MAGE_IS_DEVELOPER_MODE'] = true;
require_once $_SERVER['DOCUMENT_ROOT'].'/app/Mage.php';
umask(0);
Mage::app('default');
And they loaded product data with:
$productHelper = Mage::getModel('catalog/product');
$product = $productHelper->load($product_id);
With Magento 2.1 I'm bootstrapping with:
require getenv('MAGENTO_PATH') . 'app/bootstrap.php';
$bootstrap = MagentoFrameworkAppBootstrap::create(BP, $_SERVER);
$app = $bootstrap->createApplication('MagentoApp');
$bootstrap->run($app);
return $app->getObjectManager();
Here's the MagentoApp code:
class MagentoApp extends MagentoFrameworkAppHttp implements MagentoFrameworkAppInterface
protected $objectManager;
public function launch()
$this->_state->setAreaCode('frontend');
return $this->_response;
public function catchException(MagentoFrameworkAppBootstrap $bootstrap, Exception $exception)
return false;
public function getObjectManager()
return $this->_objectManager;
When I go to get the Magento Product in the little web service's product model, I'm using
$objectManager = $app->getObjectManager();
$product = $objectManager
->get('MagentoCatalogModelProductRepository')
->getById($product_id);
and getting the error Call to a member function get() on null (referring to the $objectManager as null) . What's weird is if I exit(var_dump($product->getData()) after that method call, I get the actual product data just fine.
If anyone could shed any light on this, it would be much appreciated.
Thanks very much.
magento-2.1 external
magento-2.1 external
edited Apr 9 at 6:04
Muhammad Anas
607318
607318
asked May 8 '17 at 21:29
chantronchantron
84
84
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I managed to get it working with this (ignore weird static stuff, I didn't have time to rework that class)
ProductModel.php
...
public static function getDataByID($product_id)
Config::boostrap();
Config::setProductId($product_id);
return Config::run();
Config.php
public static function boostrap()
if (!self::$enviroment_loaded)
require getenv('MAGENTO_PATH') . 'app/bootstrap.php';
self::$bootstrap = MagentoFrameworkAppBootstrap::create(BP, $_SERVER);
self::$app = self::$bootstrap->createApplication('MagentoApp');
public static function run()
if (!self::$enviroment_loaded)
self::$bootstrap->run(self::$app);
self::$enviroment_loaded = true;
return self::$app->getProductById();
public static function setProductId($id)
self::$app->setProductId($id);
MagentoApp.php
class MagentoApp extends MagentoFrameworkAppHttp implements MagentoFrameworkAppInterface
{
protected $productId;
public function launch()
$this->_state->setAreaCode('frontend');
return $this->_response;
public function catchException(MagentoFrameworkAppBootstrap $bootstrap, Exception $exception)
return false;
public function getProductById($id = null)
if (!$id)
$id = $this->getProductId();
$product = $this->_objectManager
->get('MagentoCatalogModelProductRepository')
->getById($id);
$store = $this->_objectManager->get('MagentoStoreModelStoreManagerInterface')->getStore();
$imageUrl = $store
->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA) .
'catalog/product' .
$product->getImage();
return [
'productID' => $id,
'productName' => $product->getName(),
'link' => $product->getProductUrl(),
'image' => $imageUrl
];
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f173521%2fmagento-2-1-load-product-in-external-script%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I managed to get it working with this (ignore weird static stuff, I didn't have time to rework that class)
ProductModel.php
...
public static function getDataByID($product_id)
Config::boostrap();
Config::setProductId($product_id);
return Config::run();
Config.php
public static function boostrap()
if (!self::$enviroment_loaded)
require getenv('MAGENTO_PATH') . 'app/bootstrap.php';
self::$bootstrap = MagentoFrameworkAppBootstrap::create(BP, $_SERVER);
self::$app = self::$bootstrap->createApplication('MagentoApp');
public static function run()
if (!self::$enviroment_loaded)
self::$bootstrap->run(self::$app);
self::$enviroment_loaded = true;
return self::$app->getProductById();
public static function setProductId($id)
self::$app->setProductId($id);
MagentoApp.php
class MagentoApp extends MagentoFrameworkAppHttp implements MagentoFrameworkAppInterface
{
protected $productId;
public function launch()
$this->_state->setAreaCode('frontend');
return $this->_response;
public function catchException(MagentoFrameworkAppBootstrap $bootstrap, Exception $exception)
return false;
public function getProductById($id = null)
if (!$id)
$id = $this->getProductId();
$product = $this->_objectManager
->get('MagentoCatalogModelProductRepository')
->getById($id);
$store = $this->_objectManager->get('MagentoStoreModelStoreManagerInterface')->getStore();
$imageUrl = $store
->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA) .
'catalog/product' .
$product->getImage();
return [
'productID' => $id,
'productName' => $product->getName(),
'link' => $product->getProductUrl(),
'image' => $imageUrl
];
add a comment |
I managed to get it working with this (ignore weird static stuff, I didn't have time to rework that class)
ProductModel.php
...
public static function getDataByID($product_id)
Config::boostrap();
Config::setProductId($product_id);
return Config::run();
Config.php
public static function boostrap()
if (!self::$enviroment_loaded)
require getenv('MAGENTO_PATH') . 'app/bootstrap.php';
self::$bootstrap = MagentoFrameworkAppBootstrap::create(BP, $_SERVER);
self::$app = self::$bootstrap->createApplication('MagentoApp');
public static function run()
if (!self::$enviroment_loaded)
self::$bootstrap->run(self::$app);
self::$enviroment_loaded = true;
return self::$app->getProductById();
public static function setProductId($id)
self::$app->setProductId($id);
MagentoApp.php
class MagentoApp extends MagentoFrameworkAppHttp implements MagentoFrameworkAppInterface
{
protected $productId;
public function launch()
$this->_state->setAreaCode('frontend');
return $this->_response;
public function catchException(MagentoFrameworkAppBootstrap $bootstrap, Exception $exception)
return false;
public function getProductById($id = null)
if (!$id)
$id = $this->getProductId();
$product = $this->_objectManager
->get('MagentoCatalogModelProductRepository')
->getById($id);
$store = $this->_objectManager->get('MagentoStoreModelStoreManagerInterface')->getStore();
$imageUrl = $store
->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA) .
'catalog/product' .
$product->getImage();
return [
'productID' => $id,
'productName' => $product->getName(),
'link' => $product->getProductUrl(),
'image' => $imageUrl
];
add a comment |
I managed to get it working with this (ignore weird static stuff, I didn't have time to rework that class)
ProductModel.php
...
public static function getDataByID($product_id)
Config::boostrap();
Config::setProductId($product_id);
return Config::run();
Config.php
public static function boostrap()
if (!self::$enviroment_loaded)
require getenv('MAGENTO_PATH') . 'app/bootstrap.php';
self::$bootstrap = MagentoFrameworkAppBootstrap::create(BP, $_SERVER);
self::$app = self::$bootstrap->createApplication('MagentoApp');
public static function run()
if (!self::$enviroment_loaded)
self::$bootstrap->run(self::$app);
self::$enviroment_loaded = true;
return self::$app->getProductById();
public static function setProductId($id)
self::$app->setProductId($id);
MagentoApp.php
class MagentoApp extends MagentoFrameworkAppHttp implements MagentoFrameworkAppInterface
{
protected $productId;
public function launch()
$this->_state->setAreaCode('frontend');
return $this->_response;
public function catchException(MagentoFrameworkAppBootstrap $bootstrap, Exception $exception)
return false;
public function getProductById($id = null)
if (!$id)
$id = $this->getProductId();
$product = $this->_objectManager
->get('MagentoCatalogModelProductRepository')
->getById($id);
$store = $this->_objectManager->get('MagentoStoreModelStoreManagerInterface')->getStore();
$imageUrl = $store
->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA) .
'catalog/product' .
$product->getImage();
return [
'productID' => $id,
'productName' => $product->getName(),
'link' => $product->getProductUrl(),
'image' => $imageUrl
];
I managed to get it working with this (ignore weird static stuff, I didn't have time to rework that class)
ProductModel.php
...
public static function getDataByID($product_id)
Config::boostrap();
Config::setProductId($product_id);
return Config::run();
Config.php
public static function boostrap()
if (!self::$enviroment_loaded)
require getenv('MAGENTO_PATH') . 'app/bootstrap.php';
self::$bootstrap = MagentoFrameworkAppBootstrap::create(BP, $_SERVER);
self::$app = self::$bootstrap->createApplication('MagentoApp');
public static function run()
if (!self::$enviroment_loaded)
self::$bootstrap->run(self::$app);
self::$enviroment_loaded = true;
return self::$app->getProductById();
public static function setProductId($id)
self::$app->setProductId($id);
MagentoApp.php
class MagentoApp extends MagentoFrameworkAppHttp implements MagentoFrameworkAppInterface
{
protected $productId;
public function launch()
$this->_state->setAreaCode('frontend');
return $this->_response;
public function catchException(MagentoFrameworkAppBootstrap $bootstrap, Exception $exception)
return false;
public function getProductById($id = null)
if (!$id)
$id = $this->getProductId();
$product = $this->_objectManager
->get('MagentoCatalogModelProductRepository')
->getById($id);
$store = $this->_objectManager->get('MagentoStoreModelStoreManagerInterface')->getStore();
$imageUrl = $store
->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA) .
'catalog/product' .
$product->getImage();
return [
'productID' => $id,
'productName' => $product->getName(),
'link' => $product->getProductUrl(),
'image' => $imageUrl
];
answered May 9 '17 at 14:54
chantronchantron
84
84
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f173521%2fmagento-2-1-load-product-in-external-script%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown