Question

I am new to magento and want to set the store view after login depending on the user. The user can select a store view at registration and this is stored as an EAV attribute in the database.

My install script:

<?php
$installer = $this;
$installer->startSetup();
$setup = Mage::getModel('customer/entity_setup', 'core_setup');
$setup->addAttribute('customer', 'default_store_view_code', array(
    'type' => 'varchar',
    'input' => 'select',
    'label' => 'Default Store View',
    'global' => 1,
    'visible' => 1,
    'required' => 1,
    'user_defined' => 1,
    'default' => '',
    'visible_on_front' => 1,
    'source' => 'ModuleName/source_storeViewCode'
));


Mage::getSingleton('eav/config')
    ->getAttribute('customer', 'default_store_view_code')
    ->setData('used_in_forms', array('adminhtml_customer','customer_account_create','customer_account_edit','checkout_register'))
    ->save();

$installer->endSetup();
?>

used_in_forms isn't configured right now. My Problem: When I try to show the details of my customer in the magento backend I get the error:

Warning: include(Mage/ModuleName/Model/Source/StoreViewCode.php): failed to open stream: No such file or directory

'source' => 'NameSpace/ModuleName/source_storeViewCode'

and

'source' => 'NameSpace_ModuleName/source_storeViewCode'

didn't work either. It tries to load from the Mage NameSpace. How can I set it to my namespace?

My source_model is located in local/NameSpace/ModuleName/Model/Source/StoreViewCode.php.

PS: my config.xml of my module

<?xml version="1.0"?>
<config>
    <modules>
        <NameSpace_ModuleName>
            <version>1.0.0</version>
        </NameSpace_ModuleName>
    </modules>

    <global>
        <blocks>
            <customer>
                <rewrite>
                    <form_register>NameSpace_ModuleName_Block_Form_Register</form_register>
                </rewrite>
            </customer>
        </blocks>
        <resources>
            <ModuleName_setup>
                <setup>
                    <module>NameSpace_ModuleName</module>
                    <class>NameSpace_ModuleName_Model_Resource_Setup</class>
                </setup>
            </ModuleName_setup>
        </resources>
    </global>

    <frontend>
        <routers>
            <customer>
                <args>
                    <modules>
                        <moduleName before="Mage_Customer">NameSpace_ModuleName</moduleName>
                    </modules>
                </args>
            </customer>
        </routers>
    </frontend>
</config>
Was it helpful?

Solution

You are missing this in config.xml on the same level as <blocks>

<models>
    <modulename>
        <class>Namespace_Modulename_Model</class>
    </modulename>
<models>

Then create the class Namespace_Modulename_Model_Source_StoreViewCode with the method toOptionArray inside it. That method should return an array with the available options.

In your install script the source should look like this:

'source' => 'modulename/source_storeViewCode'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top