I have to add two fields to the customer's address grid, for this I have to add a left join to the Magento collection. I have created the following custom module:




<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Vendor_Module" setup_version="1.0.0">
            <module name="Magento_Customer"/>


<?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_address_columns">
        <column name="first_field">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="sortOrder" xsi:type="number">11</item>
                    <item name="label" xsi:type="string" translate="true">First Field</item>
        <column name="second_field">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="sortOrder" xsi:type="number">12</item>
                    <item name="label" xsi:type="string" translate="true">Second Field</item>


<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    <type name="Magento\Customer\Model\ResourceModel\Address\Grid\Collection">
        <plugin name="customer_address_grid_collection" type="\Vendor\Module\Model\Plugin\ResourceModel\Address\Collection"/>


namespace Vendor\Module\Model\Plugin\ResourceModel\Address; 
class Collection
    public static $table = 'customer_address_entity';
    public static $leftJoinTable = 'customer_address_entity_varchar'; 

    public function beforeLoad($intercepter, $collection)
        if ($collection->getMainTable() === $collection->getConnection()->getTableName(self::$table)) {
            $leftJoinTableName = $collection->getConnection()->getTableName(self::$leftJoinTable);
                    'main_table.entity_id = first_field_table.entity_id and first_field_table.attribute_id=188',
                    'main_table.entity_id = second_field_table.entity_id and second_field_table.attribute_id=189',
            $where = $collection->getSelect()->getPart(\Magento\Framework\DB\Select::WHERE);
            $collection->getSelect()->setPart(\Magento\Framework\DB\Select::WHERE, $where)->group('main_table.entity_id');
            echo $collection->getSelect()->__toString();die;
        return $collection;

The columns appear in the grid but do not include any fields. I have put a logger in my Collection.php class but it does not run, I have also tried removing a semicolon from this class so that it breaks but nothing happens, therefore it is not going through the class at any time.

If anyone can help me I would really appreciate it. I am using Magento version 2.3.5-p1

1 Answer 1


I don't see anything wrong with your module's di.xml. The plugin gets loaded just fine for me on 2.3.4. Is your module properly enabled?

php bin/magento module:enable Vendor_Module

And did you clean cache/generated after enabling?

After making sure that is done. Your beforeLoad should also be changed. This is the function signature from Magento\Framework\Data\Collection\AbstractDb:

public function load($printQuery = false, $logQuery = false)

So your beforeLoad should return these parameters instead of $collection:

public function beforeLoad($collection, $printQuery = false, $logQuery = false)
        if (...) {

        return [$printQuery, $logQuery];

If your plugin is still not loaded after enabling the module and clearing generated, then there might be another module interfering or overriding Magento\Customer\Model\ResourceModel\Address\Grid\Collection.

  • Works! The error was in the parameters of the function and the return, I have modified it as you say in your answer and it already works perfectly. Thank you very much.
    – Noty
    Commented Apr 16, 2021 at 23:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.