@@ -229,6 +229,7 @@ protected function _getDependence()
229229 * @param Varien_Simplexml_Element $section
230230 * @param string $fieldPrefix
231231 * @param string $labelPrefix
232+ * @throw Mage_Core_Exception
232233 * @return $this
233234 */
234235 public function initFields ($ fieldset , $ group , $ section , $ fieldPrefix = '' , $ labelPrefix = '' )
@@ -425,21 +426,30 @@ public function initFields($fieldset, $group, $section, $fieldPrefix = '', $labe
425426 }
426427
427428 $ sourceModel = Mage::getSingleton ($ factoryName );
429+ if (!$ sourceModel ) {
430+ Mage::throwException ("Source model ' {$ factoryName }' is not found " );
431+ }
428432 if ($ sourceModel instanceof Varien_Object) {
429433 $ sourceModel ->setPath ($ path );
430434 }
435+
436+ $ optionArray = [];
431437 if ($ method ) {
432438 if ($ fieldType == 'multiselect ' ) {
433439 $ optionArray = $ sourceModel ->$ method ();
434440 } else {
435- $ optionArray = [];
436441 foreach ($ sourceModel ->$ method () as $ value => $ label ) {
437442 $ optionArray [] = ['label ' => $ label , 'value ' => $ value ];
438443 }
439444 }
440445 } else {
441- $ optionArray = $ sourceModel ->toOptionArray ($ fieldType == 'multiselect ' );
446+ if (method_exists ($ sourceModel , 'toOptionArray ' )) {
447+ $ optionArray = $ sourceModel ->toOptionArray ($ fieldType == 'multiselect ' );
448+ } else {
449+ Mage::throwException ("Missing method 'toOptionArray()' in source model ' {$ factoryName }' " );
450+ }
442451 }
452+
443453 $ field ->setValues ($ optionArray );
444454 }
445455 }
@@ -637,9 +647,9 @@ public function getScope()
637647 */
638648 public function getScopeLabel ($ element )
639649 {
640- if ($ element ->show_in_store == 1 ) {
650+ if (( int ) $ element ->show_in_store = == 1 ) {
641651 return $ this ->_scopeLabels [self ::SCOPE_STORES ];
642- } elseif ($ element ->show_in_website == 1 ) {
652+ } elseif (( int ) $ element ->show_in_website = == 1 ) {
643653 return $ this ->_scopeLabels [self ::SCOPE_WEBSITES ];
644654 }
645655 return $ this ->_scopeLabels [self ::SCOPE_DEFAULT ];
0 commit comments