Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Call to a member function toOptionArray() on a non-object
 
bedford_ch
Jr. Member
 
Total Posts:  27
Joined:  2012-10-01
 

Hi,

I’ve this code in a module I’ve just installed but I have no support on this code anymore (company is gone)

$status_options Mage::getModel("sales/order_status")->getCollection()
                                                    ->
toOptionArray();

I’ve this error message:
Fatal error: Call to a member function toOptionArray() on a non-object in /home/...../Helper/Import/Paymentmethods.php on line 82

I’ve seen on this page http://magentodocs.org/1.7.0.2/d4/d79/class_mage___sales___model___resource___order___status___collection.php and created the file on the server in magento/app/code/core/Mage/Sales/Model/Resource/Order/Status/Collection.php since in my Magento version (1.4.1.1) this file doesn’t exists.
Unfortunately this doesn’t fix the problem, I’ve still the same fatal error.
Since I’m a newbie in Magento (second week on it) but I’ve a little knowledge on Zend Framework, I don’t know how to get it to work. Do I have to add this module in a config.xml or somewhere else so Magento will use it ?
Thank you for your help.

Kind Regards

Gabriel

 
Magento Community Magento Community
Magento Community
Magento Community
 
tmp2000
Jr. Member
 
Total Posts:  9
Joined:  2011-07-14
 

It should be Mage::getResourceModel(’sales/order_status_collection’)->toOptionArray() in 1.7
But I am not sure about it should be states or status.

 
Magento Community Magento Community
Magento Community
Magento Community
 
TutorialMagento
Sr. Member
 
Avatar
Total Posts:  133
Joined:  2013-10-02
 

Hi, you may try this solution to solve this error, I follow this tutorial and successfully solve this error.
How to solve Magento Fatal error: Call to a member function toOptionArray() on a non-object
1. Open app/code/core/Mage/Adminhtml/Block/System/Config/Form.php and you will see

if ($e->source_model{
$sourceModel 
Mage::getSingleton((string)$e->source_model);
if (
$sourceModel instanceof Varien_Object{
$sourceModel
->setPath($path);
}
$field
->setValues($sourceModel->toOptionArray($fieldType == \'multiselect\'));
}
2. Replace above code with below:
if ($e->source_model{
$sourceModel 
Mage::getSingleton((string)$e->source_model);
if (
$sourceModel instanceof Varien_Object{
$sourceModel
->setPath($path);
}
if(is_object($sourceModel)){
$field
->setValues($sourceModel->toOptionArray($fieldType == \'multiselect\'));
else {
Mage
::log($e->source_model);
}
}
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top