Call to a member function getModelInstance() on null
Getting products from curl request from other store but unable to save data in magento. I'm getting getModelInstance()
fatal error. Here is my code
<?php
$mageFilename = '../app/Mage.php';
require_once $mageFilename;
Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
umask(0);
$curl = curl_init();
$API_ID = "3";
$API_URL = "http://magento.com/component/controller.php";
$App_key = "03254254";
$Functionname = "get_product_list_by_category_id_and_or_vendor_id";
$data = "data";
$product_id='product_id';
$name='name';
$description='description';
$meta_title='meta_title';
$meta_description='meta_description';
$meta_keyword='meta_keyword';
$tag='tag';
$model='model';
$sku='sku';
$upc='upc';
$ean='ean';
$jan='jan';
$isbn='isbn';
$mpn='mpn';
$location='location';
$quantity='quantity';
curl_setopt_array($curl, array(
CURLOPT_URL => $API_URL,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Appid: 3",
"Appkey: 03254254",
"Cache-control: no-cache",
"Categoryid: 101,102,103,104,105",
"Functionname: get_product_list_by_category_id_and_or_vendor_id",
"Limit: 1000",
"Postman-token: 7e0cbcb4-ad69-7f38-de10-f2387f8477ee",
"Start: 0",
"Vendorid: 1474614118"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
$data = json_decode($response);
$data = $data->data;
// var_dump($data);
foreach ($data->get_product_list_by_category_id_and_or_vendor_id as $item) {
$product = Mage::getModel('catalog/product');
if ($item->product_id) {
$product->load($item->product_id);
}
$product->setSku($item->sku)
->setEan($item->ean)
->setProductId($item->product_id)
->setName($item->name)
->setDescription($item->description)
->setKeyword($item->keyword)
->setPrice($item->Price)
->setQtr($item->Quantity)
->setS_descriotion($item->S_description)
->setStatus($item->Status)
->setVisibility($item->Visibility)
->SetWeight($item->Weight)
// Continue setting all other attribute values
->save();
$stockItem = $product->getStockItem();
$stockItem->setQty($item->quantity)
->setIsInStock($item->quantity > 0)
->save();
/*$result =array(
'id' => $product->setId()->setData,
'sku' => $product->setSku()->setData,
'name' => $product->setName()->setData,
'Status' => $product->setStatus()->setData,
'description' => $product->setDescription()->setData,
'weight' => $product->setWeight()->setData,
'created at' => $product->setCreatedAt()->setData,
/*'Price' => Mage::helper('core')->currency($product->setPrice(), true, false), //." ".$currencyCode,
'Special_Price' => Mage::helper('core')->currency($product->setSpecialPrice(), true, false), //." ".$currencyCode,
'Stock' => $product->setQty()->setData,
'hasOptions' => $product->isConfigurable()->setData,
'image' => $product->setImageUrl()->setData,
'category' => $product->setCategoryIds()->setData,
'meta_title' => $product->setMetaTitle()->setData,
'meta_desc' => $product->setMetaDescription()->setData,
'meta_keyword' => $product->setMetaKeyword()->setData,
'Reviews' => $product->setReviewsSummaryHtml()->setData,
'categories' => $product->setCategoryNames()->setData,
'Made-in' => $product->setCountryOfManufacture()->setData,
'brand' => $product->setBrand()->setData,
);*/
}
}
magento-1.9 products curl
bumped to the homepage by Community♦ yesterday
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
Getting products from curl request from other store but unable to save data in magento. I'm getting getModelInstance()
fatal error. Here is my code
<?php
$mageFilename = '../app/Mage.php';
require_once $mageFilename;
Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
umask(0);
$curl = curl_init();
$API_ID = "3";
$API_URL = "http://magento.com/component/controller.php";
$App_key = "03254254";
$Functionname = "get_product_list_by_category_id_and_or_vendor_id";
$data = "data";
$product_id='product_id';
$name='name';
$description='description';
$meta_title='meta_title';
$meta_description='meta_description';
$meta_keyword='meta_keyword';
$tag='tag';
$model='model';
$sku='sku';
$upc='upc';
$ean='ean';
$jan='jan';
$isbn='isbn';
$mpn='mpn';
$location='location';
$quantity='quantity';
curl_setopt_array($curl, array(
CURLOPT_URL => $API_URL,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Appid: 3",
"Appkey: 03254254",
"Cache-control: no-cache",
"Categoryid: 101,102,103,104,105",
"Functionname: get_product_list_by_category_id_and_or_vendor_id",
"Limit: 1000",
"Postman-token: 7e0cbcb4-ad69-7f38-de10-f2387f8477ee",
"Start: 0",
"Vendorid: 1474614118"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
$data = json_decode($response);
$data = $data->data;
// var_dump($data);
foreach ($data->get_product_list_by_category_id_and_or_vendor_id as $item) {
$product = Mage::getModel('catalog/product');
if ($item->product_id) {
$product->load($item->product_id);
}
$product->setSku($item->sku)
->setEan($item->ean)
->setProductId($item->product_id)
->setName($item->name)
->setDescription($item->description)
->setKeyword($item->keyword)
->setPrice($item->Price)
->setQtr($item->Quantity)
->setS_descriotion($item->S_description)
->setStatus($item->Status)
->setVisibility($item->Visibility)
->SetWeight($item->Weight)
// Continue setting all other attribute values
->save();
$stockItem = $product->getStockItem();
$stockItem->setQty($item->quantity)
->setIsInStock($item->quantity > 0)
->save();
/*$result =array(
'id' => $product->setId()->setData,
'sku' => $product->setSku()->setData,
'name' => $product->setName()->setData,
'Status' => $product->setStatus()->setData,
'description' => $product->setDescription()->setData,
'weight' => $product->setWeight()->setData,
'created at' => $product->setCreatedAt()->setData,
/*'Price' => Mage::helper('core')->currency($product->setPrice(), true, false), //." ".$currencyCode,
'Special_Price' => Mage::helper('core')->currency($product->setSpecialPrice(), true, false), //." ".$currencyCode,
'Stock' => $product->setQty()->setData,
'hasOptions' => $product->isConfigurable()->setData,
'image' => $product->setImageUrl()->setData,
'category' => $product->setCategoryIds()->setData,
'meta_title' => $product->setMetaTitle()->setData,
'meta_desc' => $product->setMetaDescription()->setData,
'meta_keyword' => $product->setMetaKeyword()->setData,
'Reviews' => $product->setReviewsSummaryHtml()->setData,
'categories' => $product->setCategoryNames()->setData,
'Made-in' => $product->setCountryOfManufacture()->setData,
'brand' => $product->setBrand()->setData,
);*/
}
}
magento-1.9 products curl
bumped to the homepage by Community♦ yesterday
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
Getting products from curl request from other store but unable to save data in magento. I'm getting getModelInstance()
fatal error. Here is my code
<?php
$mageFilename = '../app/Mage.php';
require_once $mageFilename;
Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
umask(0);
$curl = curl_init();
$API_ID = "3";
$API_URL = "http://magento.com/component/controller.php";
$App_key = "03254254";
$Functionname = "get_product_list_by_category_id_and_or_vendor_id";
$data = "data";
$product_id='product_id';
$name='name';
$description='description';
$meta_title='meta_title';
$meta_description='meta_description';
$meta_keyword='meta_keyword';
$tag='tag';
$model='model';
$sku='sku';
$upc='upc';
$ean='ean';
$jan='jan';
$isbn='isbn';
$mpn='mpn';
$location='location';
$quantity='quantity';
curl_setopt_array($curl, array(
CURLOPT_URL => $API_URL,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Appid: 3",
"Appkey: 03254254",
"Cache-control: no-cache",
"Categoryid: 101,102,103,104,105",
"Functionname: get_product_list_by_category_id_and_or_vendor_id",
"Limit: 1000",
"Postman-token: 7e0cbcb4-ad69-7f38-de10-f2387f8477ee",
"Start: 0",
"Vendorid: 1474614118"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
$data = json_decode($response);
$data = $data->data;
// var_dump($data);
foreach ($data->get_product_list_by_category_id_and_or_vendor_id as $item) {
$product = Mage::getModel('catalog/product');
if ($item->product_id) {
$product->load($item->product_id);
}
$product->setSku($item->sku)
->setEan($item->ean)
->setProductId($item->product_id)
->setName($item->name)
->setDescription($item->description)
->setKeyword($item->keyword)
->setPrice($item->Price)
->setQtr($item->Quantity)
->setS_descriotion($item->S_description)
->setStatus($item->Status)
->setVisibility($item->Visibility)
->SetWeight($item->Weight)
// Continue setting all other attribute values
->save();
$stockItem = $product->getStockItem();
$stockItem->setQty($item->quantity)
->setIsInStock($item->quantity > 0)
->save();
/*$result =array(
'id' => $product->setId()->setData,
'sku' => $product->setSku()->setData,
'name' => $product->setName()->setData,
'Status' => $product->setStatus()->setData,
'description' => $product->setDescription()->setData,
'weight' => $product->setWeight()->setData,
'created at' => $product->setCreatedAt()->setData,
/*'Price' => Mage::helper('core')->currency($product->setPrice(), true, false), //." ".$currencyCode,
'Special_Price' => Mage::helper('core')->currency($product->setSpecialPrice(), true, false), //." ".$currencyCode,
'Stock' => $product->setQty()->setData,
'hasOptions' => $product->isConfigurable()->setData,
'image' => $product->setImageUrl()->setData,
'category' => $product->setCategoryIds()->setData,
'meta_title' => $product->setMetaTitle()->setData,
'meta_desc' => $product->setMetaDescription()->setData,
'meta_keyword' => $product->setMetaKeyword()->setData,
'Reviews' => $product->setReviewsSummaryHtml()->setData,
'categories' => $product->setCategoryNames()->setData,
'Made-in' => $product->setCountryOfManufacture()->setData,
'brand' => $product->setBrand()->setData,
);*/
}
}
magento-1.9 products curl
Getting products from curl request from other store but unable to save data in magento. I'm getting getModelInstance()
fatal error. Here is my code
<?php
$mageFilename = '../app/Mage.php';
require_once $mageFilename;
Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
umask(0);
$curl = curl_init();
$API_ID = "3";
$API_URL = "http://magento.com/component/controller.php";
$App_key = "03254254";
$Functionname = "get_product_list_by_category_id_and_or_vendor_id";
$data = "data";
$product_id='product_id';
$name='name';
$description='description';
$meta_title='meta_title';
$meta_description='meta_description';
$meta_keyword='meta_keyword';
$tag='tag';
$model='model';
$sku='sku';
$upc='upc';
$ean='ean';
$jan='jan';
$isbn='isbn';
$mpn='mpn';
$location='location';
$quantity='quantity';
curl_setopt_array($curl, array(
CURLOPT_URL => $API_URL,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Appid: 3",
"Appkey: 03254254",
"Cache-control: no-cache",
"Categoryid: 101,102,103,104,105",
"Functionname: get_product_list_by_category_id_and_or_vendor_id",
"Limit: 1000",
"Postman-token: 7e0cbcb4-ad69-7f38-de10-f2387f8477ee",
"Start: 0",
"Vendorid: 1474614118"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
$data = json_decode($response);
$data = $data->data;
// var_dump($data);
foreach ($data->get_product_list_by_category_id_and_or_vendor_id as $item) {
$product = Mage::getModel('catalog/product');
if ($item->product_id) {
$product->load($item->product_id);
}
$product->setSku($item->sku)
->setEan($item->ean)
->setProductId($item->product_id)
->setName($item->name)
->setDescription($item->description)
->setKeyword($item->keyword)
->setPrice($item->Price)
->setQtr($item->Quantity)
->setS_descriotion($item->S_description)
->setStatus($item->Status)
->setVisibility($item->Visibility)
->SetWeight($item->Weight)
// Continue setting all other attribute values
->save();
$stockItem = $product->getStockItem();
$stockItem->setQty($item->quantity)
->setIsInStock($item->quantity > 0)
->save();
/*$result =array(
'id' => $product->setId()->setData,
'sku' => $product->setSku()->setData,
'name' => $product->setName()->setData,
'Status' => $product->setStatus()->setData,
'description' => $product->setDescription()->setData,
'weight' => $product->setWeight()->setData,
'created at' => $product->setCreatedAt()->setData,
/*'Price' => Mage::helper('core')->currency($product->setPrice(), true, false), //." ".$currencyCode,
'Special_Price' => Mage::helper('core')->currency($product->setSpecialPrice(), true, false), //." ".$currencyCode,
'Stock' => $product->setQty()->setData,
'hasOptions' => $product->isConfigurable()->setData,
'image' => $product->setImageUrl()->setData,
'category' => $product->setCategoryIds()->setData,
'meta_title' => $product->setMetaTitle()->setData,
'meta_desc' => $product->setMetaDescription()->setData,
'meta_keyword' => $product->setMetaKeyword()->setData,
'Reviews' => $product->setReviewsSummaryHtml()->setData,
'categories' => $product->setCategoryNames()->setData,
'Made-in' => $product->setCountryOfManufacture()->setData,
'brand' => $product->setBrand()->setData,
);*/
}
}
magento-1.9 products curl
magento-1.9 products curl
edited Feb 24 '17 at 14:43
Marius♦
163k28311660
163k28311660
asked Feb 24 '17 at 14:32
rameez.hashmi
589
589
bumped to the homepage by Community♦ yesterday
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ yesterday
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Short answer.
Add after umask(0);
(or before it) this Mage::app()
;
Long answer (may help on future problems)
I've searched for the text getModelInstance
in the code and the only occurrence is in the Mage_Core_Model_Config
class.
It is used in 3 locations.
2 of them are called from inside the class itself with $this->getModelInstance()
. This cannot be the problem because you cannot have $this
to be null
if you are already inside the class.
The other place is when calling Mage::getModel()
and it is called like this self::getConfig()->getModelInstance($modelClass, $arguments);
.
This means that Mage::getConfig()
returns null
for some reason.
The method getConfig
only returns self::$_config
.
Checking where this config is initialized, you will see that you have to run Mage::app()
or Mage::init()
or Mage::run()
to make it have a value.
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%2f161661%2fcall-to-a-member-function-getmodelinstance-on-null%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
Short answer.
Add after umask(0);
(or before it) this Mage::app()
;
Long answer (may help on future problems)
I've searched for the text getModelInstance
in the code and the only occurrence is in the Mage_Core_Model_Config
class.
It is used in 3 locations.
2 of them are called from inside the class itself with $this->getModelInstance()
. This cannot be the problem because you cannot have $this
to be null
if you are already inside the class.
The other place is when calling Mage::getModel()
and it is called like this self::getConfig()->getModelInstance($modelClass, $arguments);
.
This means that Mage::getConfig()
returns null
for some reason.
The method getConfig
only returns self::$_config
.
Checking where this config is initialized, you will see that you have to run Mage::app()
or Mage::init()
or Mage::run()
to make it have a value.
add a comment |
Short answer.
Add after umask(0);
(or before it) this Mage::app()
;
Long answer (may help on future problems)
I've searched for the text getModelInstance
in the code and the only occurrence is in the Mage_Core_Model_Config
class.
It is used in 3 locations.
2 of them are called from inside the class itself with $this->getModelInstance()
. This cannot be the problem because you cannot have $this
to be null
if you are already inside the class.
The other place is when calling Mage::getModel()
and it is called like this self::getConfig()->getModelInstance($modelClass, $arguments);
.
This means that Mage::getConfig()
returns null
for some reason.
The method getConfig
only returns self::$_config
.
Checking where this config is initialized, you will see that you have to run Mage::app()
or Mage::init()
or Mage::run()
to make it have a value.
add a comment |
Short answer.
Add after umask(0);
(or before it) this Mage::app()
;
Long answer (may help on future problems)
I've searched for the text getModelInstance
in the code and the only occurrence is in the Mage_Core_Model_Config
class.
It is used in 3 locations.
2 of them are called from inside the class itself with $this->getModelInstance()
. This cannot be the problem because you cannot have $this
to be null
if you are already inside the class.
The other place is when calling Mage::getModel()
and it is called like this self::getConfig()->getModelInstance($modelClass, $arguments);
.
This means that Mage::getConfig()
returns null
for some reason.
The method getConfig
only returns self::$_config
.
Checking where this config is initialized, you will see that you have to run Mage::app()
or Mage::init()
or Mage::run()
to make it have a value.
Short answer.
Add after umask(0);
(or before it) this Mage::app()
;
Long answer (may help on future problems)
I've searched for the text getModelInstance
in the code and the only occurrence is in the Mage_Core_Model_Config
class.
It is used in 3 locations.
2 of them are called from inside the class itself with $this->getModelInstance()
. This cannot be the problem because you cannot have $this
to be null
if you are already inside the class.
The other place is when calling Mage::getModel()
and it is called like this self::getConfig()->getModelInstance($modelClass, $arguments);
.
This means that Mage::getConfig()
returns null
for some reason.
The method getConfig
only returns self::$_config
.
Checking where this config is initialized, you will see that you have to run Mage::app()
or Mage::init()
or Mage::run()
to make it have a value.
answered Feb 24 '17 at 14:42
Marius♦
163k28311660
163k28311660
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f161661%2fcall-to-a-member-function-getmodelinstance-on-null%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