Loki_CompanyAccountAutomaticAssignment

PHP 8.2 - 8.5
Magento 2.4.6 - 2.4.9
CSP Yes
PHPStan 1
Magento PHPCS 10
License OSL-3.0
Latest Release none

Installation

Install this package via composer:

composer require loki/magento2-company-account-automatic-assignment

Next, enable this module:

bin/magento module:enable Loki_CompanyAccountAutomaticAssignment

Features

This module automatically assigns customers to a company of Loki_CompanyAccounts. When a customer registers, is saved (frontend, Admin Panel, API) or logs in, all assignment rules are checked. The first rule that returns a company wins and the customer is added to that company with the configured role. Customers that already belong to a company are never moved to another company.

Configuration is found under Stores > Configuration > Customers > Company Accounts > Automatic Assignment:

  • Enabled: Enable or disable the automatic assignment
  • Role: The company role given to automatically assigned customers (default: Buyer)

Email domain rule

Each company has a field Email domains (database column loki_company.email_domain), which contains a comma-separated list of domains (for instance example.com, example.org). When the domain of a customer email matches one of these domains (case-insensitive), the customer is added to that company. Only active companies are matched.

Adding your own rules

Create a class implementing Loki\CompanyAccountAutomaticAssignment\Rule\RuleInterface and add it to the rule listing via etc/di.xml:

<type name="Loki\CompanyAccountAutomaticAssignment\Rule\RuleListing">
    <arguments>
        <argument name="rules" xsi:type="array">
            <item name="my_rule" xsi:type="object">Vendor\Module\Rule\MyRule</item>
        </argument>
    </arguments>
</type>

Current status

pipeline failed
WARNING: This module has no releases yet. If you want to use it, make sure to add the version @dev to the composer command.

Support

For getting support, create an Issue under the following project URL:

https://gitlab.yireo.com/loki-extensions/Loki_CompanyAccountAutomaticAssignment.git

Configuration Options

The following options of this module can be configured via the Store Configuration:

Company Accounts > Automatic Assignment > Enabled
loki_company_accounts/automatic_assignment/enabled
Automatically assign customers to a company based on the assignment rules
Company Accounts > Automatic Assignment > Role
loki_company_accounts/automatic_assignment/role
Company role given to automatically assigned customers
Module Dependencies

The following dependencies are declared in the module its `etc/module.xml` file:

Magento_Customer Magento_Store Loki_CompanyAccounts
Composer details
Magento module name
Loki_CompanyAccountAutomaticAssignment
Composer name
loki/magento2-company-account-automatic-assignment
Composer version
No release yet
Default branch
main
Requirements
loki/magento2-company-accounts: *
magento/framework: ^103.0
magento/module-customer: ^103.0
magento/module-store: ^101.0
php: >=8.2 <8.6
psr/log: *
Releases
Changelog

Added

  • Dependency on Loki_CompanyAccounts
  • DI-based assignment rules (RuleListing with RuleInterface implementations)
  • Email domain rule: assign customers whose email domain matches the company email domains
  • Automatic assignment on customer registration, customer save and customer login
  • Configuration for enabling the automatic assignment and choosing the assigned role
  • Unit and integration tests

Last modified: October 26, 2026