Magento – How to change a customer store_id in Magento or set the “created_from” attribute when creating a new customer

magentostore

I want to be able to choose what store to associate a new customer with when I create their account as administrator. I found that by overriding this file:

app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Account.php

Changing this:

if ($customer->getId()) {
        $form->getElement('website_id')->setDisabled('disabled');
        $form->getElement('created_in')->setDisabled('disabled');
    } else {
        $fieldset->removeField('created_in');
    }

To This:

if ($customer->getId()) {
        $form->getElement('website_id');//->setDisabled('disabled');
        $form->getElement('created_in');//->setDisabled('disabled');
    } else {
        //$fieldset->removeField('created_in');
    }

This gives me a text input with the label "Created From" but it deosn't save the id I enter into it. I want it to save this information and also to show me a drop down list of stores to choose from instead of an empty text input. The way that the Magento developers have implemented their forms using zend is really confusing. Please help!

edit:

Here's why I need to control what store a customer is associated with: I have multiple stores and need customers to be redirected upon successful login to the store associated with their account. Accounts can only be created by an admin. Stores other than the default may only be accessed by users who are logged in and associated with that store.

Best Answer

is this is what You are looking for :?

Put this after if that You mentioned in Your question.

$fieldset->removeField('created_in');
$fieldset->addField('created_in', 'select', array(
   'name'      => 'created_in',
   'label'     => Mage::helper('adminhtml')->__('Created In'),
   'id'        => 'created_in',
   'title'     => Mage::helper('adminhtml')->__('Created In'),
   'class'     => 'input-select',
   'style'     => 'width: 80px',
   'options'   => array(
   //Put here list of websites || stores || store views
      'key_1' => 'VALUE_1', 
      'key_2' => 'VALUE_2'
   ),
), 'website_id');
Related Topic