1

I have a module:

Model/SelectType.php

class NAME_CustomField_Model_SelectType
{
  public function toOptionArray()
  {
    return array(
      array('value' => '1', 'label' => '1'),
      array('value' => '2', 'label' => '2'),
      array('value' => '3', 'label' => '3'),
    );
  }
}

in my etc/config.xml I have:

<config>
    <modules>
        <NAME_CustomField>
            <version>0.1.1</version>
        </NAME_CustomField>
    </modules>
    <global>
        <models>
            <customfield>
                <class>NAME_CustomField_Model</class>
            </customfield>
        </models>
    </global>
...

Now, if I set in the DB (table: eav_attribute) source_model to: customfield/selectType it gives an error: Source model "customfield/selectType" not found.

UPDATE: I've moved my file to: "code/core/Mage/Customer/Model/Customer/Attribute/Source" (for testing ofcourse) and changed the resource model to: customer/customer_attribute_source_selecttype This works, so I think there is something in my /etc/*.xml that is wrong, but I can't seem to find what it would be... :-S

3
  • I'm really surprised that this would work in any place. I think that EAV source models are expected to implement Mage_Eav_Model_Entity_Attribute_Source_Interface and/or subclass Mage_Eav_Model_Entity_Attribute_Source_Abstract.
    – benmarks
    Sep 11 '13 at 10:10
  • Check in the backend System > Config > Advanced whether your module is in the list, if it is, then the Module_Xml.xml in app/etc/modules is loaded. Next check: make a typo in your config.xml if display_errors and developer mode is on, then you should see an error, if not config.xml is not loaded. If this all works, I have no idea, why the source model is not found. Nov 10 '13 at 22:38
  • Did you solve your problem? Please share the solution with us. Mar 10 '14 at 20:50
2

Your XML looks correct — although if Magento's loading the class from the Mage namespace that may be because your XML hasn't been loaded into the global configuration tree (cached XML, incorrect app/etc/modules file).

Your best bet is to debug things at the point where Magento looks into the configuration for your new class name

#File: app/code/core/Mage/Core/Model/Config.php
public function getGroupedClassName($groupType, $classId, $groupRootNode=null)
{
    //..
    $config = $this->_xml->global->{$groupType.'s'}->{$group};
    $className = null;
    if (isset($config->rewrite->$class)) {
        $className = (string)$config->rewrite->$class;
    } else {
    //..
}

Figure out why Magento can't find your base classname in the XML configuration, and you'll have your problem solved.

5
  • thanks for your answer I will definitely try this, if the answer to my problem is worth mentioning I will mention it here. Aug 12 '13 at 8:38
  • @bvl Also, I generally avoid camel casing and inter-casing classnames like that (SelectType). To easy for the autoloader to get confused about w/r/t to class case.
    – Alan Storm
    Aug 12 '13 at 16:08
  • @bvl Any luck here?
    – Alan Storm
    Aug 14 '13 at 3:29
  • 1
    no, not yet, but I actually think the camel casing is the issue... Aug 14 '13 at 16:21
  • @bvl Based on what you've posted, you have the correct information in place to make the camel-cased class work (correct class argument, correct filename).
    – benmarks
    Sep 11 '13 at 10:06
1

I guess the problem is here "DB (table: eav_attribute) source_model to: customfield/selectType"
It should be customField/selectType

1
  • This is wrong. The module before the / must be the same as the node in the xml, so customfield is correct. Nov 10 '13 at 22:36

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.