How to display a custom column in Customer Table

My client wants a new column “customerNumber” in the system, to uniquely identify his customers (no, id’s won’t work, he wants to be able to change it).

Here’s what I have so far:

etc/di.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <virtualType name="MagentoCustomerModelResourceModelGrid"> <arguments> <argument name="columns" xsi:type="array"> <item name="customer_number" xsi:type="string">customer_entity.customer_number</item> </argument> </arguments> </virtualType> </config> 

etc/module.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> <module name="NxtLvl_CustomerNumber" setup_version="1.0.2"> <sequence> <module name="Magento_Checkout"/> <module name="Magento_Customer"/> </sequence> </module> </config> 

Setup/InstallSchema.php

<?php namespace NxtLvlCustomerNumberSetup; use MagentoFrameworkDBDdlTable; use MagentoFrameworkSetupSchemaSetupInterface; use MagentoFrameworkSetupModuleContextInterface; class InstallSchema implements MagentoFrameworkSetupInstallSchemaInterface { public function install(SchemaSetupInterface $setup, ModuleContextInterface $context) { $setup->startSetup(); $setup->getConnection()->addColumn( $setup->getTable('customer_entity'), 'customer_number', [ 'type' => Table::TYPE_TEXT, 'nullable' => true, 'comment' => 'Custom Customer Number', ] ); $setup->endSetup(); } } 

view/adminhtml/ui_component/customer_listing.xml

<?xml version="1.0" encoding="UTF-8"?> <listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd"> <columns name="customer_columns" class="MagentoCustomerUiComponentListingColumns"> <column name="customer_number" sortOrder="20"> <settings> <filter>textRange</filter> <label translate="true">Customer Number</label> <sorting>asc</sorting> </settings> </column> </columns> </listing> 

Now using this I’ve managed to add the column to my DB, and I get the column to display in the interface – but without any data.

My suspicion is that I need to change the Customer Model class to also reflect this new column? If so, how do I do that?

What am I missing? I’m a total newcomer to Magento, so any pointers are greatly appreciated.

submitted by /u/Your_Friendly_Nerd
[link] [comments]