Managing Customers by Company Name in Magento
In B2B environments, it’s crucial for e-commerce platforms like Magento to allow businesses to manage their customers primarily by company name rather than individual contact names. This is especially important when sending out automated emails or generating reports.
Understanding Customer Entities in Magento
Magento 2 has two primary customer entities: customer_entity and company_entity. The customer_entity table stores information about individual contacts, while the company_entity table maintains data about associated companies.
By default, Magento sends emails using the first name and last name of the contact. However, for B2B purposes, it’s more appropriate to use the company name in communications. This requires customizing the email templates and possibly the customer grid view in the admin panel.
Modifying Email Templates
To change the name displayed in outgoing emails from individual names to the company name, you’ll need to modify the relevant email templates. Here’s a step-by-step guide:
- Navigate to
app/code/Magento/Company/etc/config.xmland add the following XML configuration:
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/config.xsd">
<default>
<company>
<email_templates>
<template_id>4</template_id>
<field_name>company_name</field_name>
</email_templates>
</company>
</default>
</config>
- Next, modify the relevant email template files in
app/code/Magento/Company/view/frontend emails. For example, to change the name used in the “New Account Confirmation” email:
<company_name>{{var customer.company_name}}</company_name>
Customizing the Admin Grid View
To view and manage customers by company name in the admin panel, you’ll need to customize the customer_grid view. This involves extending the Magento core module and overriding the grid block.
-
Create a new custom module following Magento’s best practices for extension development: https://laravelcompany.com/magento-extension-development
-
In your module’s
app/code/YourVendor/Company/etc/adminhtml/di.xmlfile, add the following block override:
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/config.xsd">
<type name="Magento\Customer\Block\Adminhtml\Customer\Grid">
<arguments>
<argument name="columns" xsi:type="array">
<item name="company_name" xsi:type="string">Company Name</item>
...
</argument>
</arguments>
</type>
</config>
- In your module’s
app/code/YourVendor/Company/view/adminhtml/templates/customer/grid/columns.phtmlfile, replace the default code with the following:
<?php
$block = $this->getLayout()->createBlock('Magento\Customer\Block\Adminhtml\Customer')
->setData('area', 'adminhtml')
->setTemplate('Magento_Customer::customer/grid/columns.phtml');
echo $block->toHtml();
?>
Conclusion
To summarize, Magento allows you to manage customers by company name for B2B purposes through a combination of email template customization and admin grid view modification. By following the steps outlined above, you can ensure that your business partners are addressed appropriately in all automated communications.
Remember, it’s always recommended to follow Magento’s extension development best practices when making such modifications: https://laravelcompany.com/magento-extension-development
This approach ensures code maintainability and compatibility with future Magento updates. If you have any further questions or need assistance with a specific implementation, feel free to reach out to our support team at Laravel Company.
Happy coding!