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

 $mageFilename = '../app/Mage.php';
  require_once $mageFilename;

   ini_set('display_errors', 1);


    $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";


    curl_setopt_array($curl, array(
        CURLOPT_URL => $API_URL,
        CURLOPT_ENCODING => "",
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 30,
        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);


    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) {

                // Continue setting all other attribute values

            $stockItem = $product->getStockItem();
                ->setIsInStock($item->quantity > 0)

            /*$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,




1 Answer 1


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.