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

♀尐吖头ヾ 提交于 2019-12-07 07:11:30

问题


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.


回答1:


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');


来源:https://stackoverflow.com/questions/5424423/how-can-i-change-a-customer-store-id-in-magento-or-set-the-created-from-attrib

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!