Restrict Magento customer to Stores

Restrict Magento customer to Stores

September 14, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Restrict Magento customer to Stores

Restricting Magento Customers to Specific Stores

As a Magento developer, I often encounter clients who want to create separate, interconnected storefronts for different business units or locations while maintaining customer isolation between them. This is particularly useful when each store has its own inventory, pricing structure, and customer base managed by independent teams.

The default Magento setup allows customers created in one store to access all other stores in the same installation. However, it’s possible to restrict this behavior using a combination of core configuration changes and custom code.

Understanding Customer Group Management

In Magento, customers are grouped based on their role and permissions. By default, there is only one customer group: “General”. To achieve store-level customer restriction, we need to create multiple customer groups, each corresponding to a specific store.

  1. Navigate to the Admin panel of your Magento installation.
  2. Go to Stores > Customers > Customer Groups.
  3. Click on “Add New Customer Group”.
  4. Enter a name for the group (e.g., “Store1 Customers”) and save it.

Repeat this process for each store in your setup, creating a unique customer group for every store.

Creating Custom Customer Registration Logic

By default, Magento allows customers to register in any store within the same installation. To restrict registration to only one specific store:

// app/code/LaravelCompany/RestrictCustomers/etc/frontend/di.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Customer\Model\ResourceModel\Customer">
        <arguments>
            <argument name="isCustomerGroupCreationAllowed" xsi:type="string">false</argument>
        </arguments>
    </type>
</config>

This code snippet prevents the creation of new customer groups, ensuring that all customers are assigned to the default “General” group when they register.

Implementing Store-Specific Customer Access

To restrict logged-in customers from accessing stores other than their own:

  1. Create a custom plugin for the Magento\Customer\Model\Session class.
  2. Override the start() method to check if the customer is authorized to access the current store.
  3. If the customer does not belong to the appropriate customer group (based on the desired store), redirect them back to their assigned store.

Here’s a high-level example using Magento 2 plugin system:

// app/code/LaravelCompany/RestrictCustomers/etc/frontend/di.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Customer\Model\Session">
        <plugin name="restrict_customers_to_stores" type="LaravelCompany\RestrictCustomers\Plugin\CustomerSession" sortOrder="10"/>
    </type>
</config>

Implement the start() method in your custom plugin:

public function afterStart(CustomerSession $subject)
{
    if (!$subject->isLoggedIn()) {
        return;
    }

    $customerGroupId = $subject->getCustomer()->getGroupId();
    $storeId = $subject->getStore();

    // Check if the customer belongs to the appropriate group for this store
    if ($customerGroupId !== $this->checkAllowedGroup($storeId)) {
        // Redirect the customer back to their assigned store or show an error message
        return $subject;
    }

    return null; // Proceed with normal session processing
}

Conclusion

Restricting Magento customers to specific stores requires a combination of configuration changes and custom code to manage customer groups effectively. By creating separate customer groups for each store, implementing custom registration logic, and validating access through plugins, you can ensure that customers can only access the stores relevant to their account.

Remember that this solution assumes you have access to modify your Magento installation’s core files and use the plugin system. Always consult with a knowledgeable developer or follow best practices for extending Magento when implementing custom functionality.

For more information on Magento extensions and store configuration, visit Laravel Company.

Security API Admin Configuration

Our network