请问使用Magento扩展命令行模式如何使用Mage :: getResourceModel

时间:2012-09-24 03:41:30

标签: magento command-line

我正在开发以内置cron.php为模型的命令行扩展操作 代码如下

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

执行,出现以下消息 “在非对象”

上调用成员函数getResourceModelInstance()

对应功能如下

应用程序/ Mage.php

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

显然,self :: getConfig() - > getResourceModelInstance()问题

我想问一下如何使用Command-Line Executive Mage :: getResourceModel吗?

1 个答案:

答案 0 :(得分:0)

Cron.php大部分代码副本都进来了,我将能够使用,虽然我不了解他的行动原理:P 该计划一般如下

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;