0

I'm developing the operation of the Command-Line Expansion, modeled on the built-in cron.php The code is as follows

expansion.php

require 'app/Mage.php';
$lowstockCollection = Mage::getResourceModel('reports/product_lowstock_collection')
->addAttributeToSelect('*')
->setStoreId($storeId)
->filterByIsQtyProductTypes()
->joinInventoryItem('qty')
->useManageStockFilter($storeId)
->useNotifyStockQtyFilter($storeId)
->setOrder('qty', Varien_Data_Collection::SORT_ORDER_ASC);

Execution, the following message appears "Call to a member function getResourceModelInstance() on a non-object"

Corresponding to the function as follows

app/Mage.php

public static function getResourceModel($modelClass, $arguments = array())
{
    return self::getConfig()->getResourceModelInstance($modelClass, $arguments);
}

Obviously, self :: getConfig () -> getResourceModelInstance () problem

I would like to ask how to use Command-Line Executive Mage :: getResourceModel it?

Maro Huang
  • 59
  • 9
  • You forgot to initialize Magento. See http://stackoverflow.com/questions/7145373/magento-fatal-error-call-to-a-member-function-getmodelinstance-on-a-non-obje/7145570#7145570 – Daniel Sloof Sep 24 '12 at 04:53

1 Answers1

0

Cron.php most of the code copies came in, I will be able to use, although I do not understand his action principle :P The program generally is as follows

function xxx(){...}

require 'app/Mage.php';

if (!Mage::isInstalled()) {
    echo "Application is not installed yet, please complete install wizard first.";
    exit;
}

// Only for urls
// Don't remove this
$_SERVER['SCRIPT_NAME'] = str_replace(basename(__FILE__), 'index.php', $_SERVER['SCRIPT_NAME']);
$_SERVER['SCRIPT_FILENAME'] = str_replace(basename(__FILE__), 'index.php', $_SERVER['SCRIPT_FILENAME']);

Mage::app('admin')->setUseSessionInUrl(false);

umask(0);

xxx;
Maro Huang
  • 59
  • 9