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

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

August 21, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How can I change a customer store_id in Magento or set the "created_from" attribute when creating a new customer

Changing Customer Store Association on Magento Account Creation

As an e-commerce administrator, you may find yourself needing fine-grained control over which store new customers are associated with when their accounts are created. By default, Magento associates all newly created customer accounts with the default website and doesn’t provide a straightforward way to change this during account creation.

The Challenge: Overriding Core Files

One approach some developers take is to override core files in order to expose additional options for store association during customer creation. However, as you’ve experienced, this method can be tricky due to Magento’s complex form handling using Zend Framework components.

You attempted to modify the Mage/Adminhtml/Block/Customer/Edit/Tab/Account.php file by commenting out the disabling of the ‘created_in’ and ‘website_id’ fields. This did successfully expose these fields, but you found that entering a store ID in the ‘Created From’ field didn’t save correctly.

Why Control Customer Store Association?

Before we dive into solving your issue, let’s first understand why you need to control which store each customer is associated with:

  • Store-Specific Access: You want customers to be redirected to their associated store upon successful login.
  • Access Restriction: Only customers associated with a specific store should have access to that store.
  • Customer Segmentation: Associating customers with stores allows for targeted marketing and promotional campaigns.

A Better Approach: Extending the Customer Form

Instead of overriding core files, which can lead to headaches in future updates and conflicts with extensions, I recommend creating an extension that extends the customer form. This approach provides a cleaner separation between your custom logic and Magento’s core functionality.

Here are the steps to implement this:

  1. Create a New Module: Use Magento’s module creator script (you can find it under magento-root-dir/bin/magento/setup:module:create) to generate a new module, let’s call it YourCompany_CustomCustomer.

  2. Override the Customer Form: In your module’s app/code/YourCompany/CustomCustomer/view/adminhtml/ui_component/customer_form.xml file, you’ll find the form definition for the customer creation page.

  3. Add a New Select Field: Add a new select field to represent the store selection option:

<field name="custom_store_id" sortOrder="10">
    <argument name="data" xsi:type="array">
        <item name="config" xsi:type="array">
            <item name="sortOrder" xsi:type="number">45</item>
            <item name="label" xsi:type="string" translate="true">Associated Store</item>
            <item name="visible" xsi:type="boolean">true</item>
            <item name="dataType" xsi:type="string">text</item>
        </item>
    </argument>
    <settings>
        <referenceGroup name="sales_customer_account_create">
            <group name="account_information">
                <field name="custom_store_id">
                    <argument name="data" xsi:type="array">
                        <item name="config" xsi:type="array">
                            <item name="source" xsi:type="string">stores</item>
                        </item>
                    </argument>
                </field>
            </group>
        </referenceGroup>
    </settings>
</field>
  1. Save the Store Association: When a customer is created or updated, you need to save the selected store ID as their associated store.

    In your module’s app/code/YourCompany/CustomCustomer/Model/Customer.php file, override the save() method:

public function save()
{
    $storeId = (int)$this->getData('custom_store_id');
    if ($storeId) {
        $this->setData('website_id', $storeId);
    }

    return parent::save();
}
  1. Clean Up: Remove any old overrides of core files to prevent conflicts.

Conclusion

By following the approach outlined above, you’ll have a clean, maintainable solution for controlling which store each new customer is associated with during account creation in Magento. This method provides better separation and avoids potential issues that can arise from directly overriding core files.

Remember, always test your changes thoroughly before deploying them to a production environment. If you find yourself needing further assistance or customization, consider reaching out to professionals like those at Laravel Company.

Happy coding!

API Admin Orders Customers

Our network