#StackBounty: #module #uicomponent #plugin #system.xml #magento-2.2.5 Custom Module for Custom Column using Plugin Yes/No option

Bounty: 50

I have been digging all day trying to figure out a way to enable/disable the plugins of my custom module with system configuration yes/no. Basically, I have a custom module that adds the Company Column to all Admin Order Grids as well as Customer Grids.

I have created the system.xml file to display the options on the backend, including an option to disable the entire module or just certain Order Grids (Order, Invoice, Shipment, etc).


    <tab id="trucatch" translate="label" sortOrder="500">
    <section id="companycolumn" translate="label" type="text" sortOrder="140" showInDefault="1" showInWebsite="1" showInStore="1">
        <label><![CDATA[Company Column]]></label>
        <group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
            <field id="enabled" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
                <comment><![CDATA[Enable to allow Company Column on Sales Grids]]></comment>
            <field id="order_grid_enabled" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
                <label>Show on Order Grid</label><source_model>MagentoConfigModelConfigSourceYesno</source_model>
                    <field id="*/*/enabled">1</field>



di.xml is calling all the plugins.


<type name="MagentoFrameworkViewElementUiComponentDataProviderCollectionFactory">

I have also created a HelperData.php file to check, but I have not been able to associate that with the actual plugin file. Or am I looking in the wrong place and this needs to be implemented in the layout/ui_component files?


namespace TrucatchCompanyColumnHelper;

use MagentoFrameworkAppHelperAbstractHelper;
use MagentoFrameworkAppConfigScopeConfigInterface;
use MagentoFrameworkAppHelperContext
use MagentoStoreModelScopeInterface;

class Data extends AbstractHelper
 * Config path to enable/disable module
const CONFIG_PATH_GENERAL_ENABLE_MODULE = 'companycolumn/general/enabled';

 * Config path to enable/disable module
const CONFIG_PATH_GENERAL_ORDER_GRID = 'companycolumn/general/order_grid_enabled';

protected $_scopeConfig;

public function __construct(
    Context $context,
    MagentoBackendModelUrlInterface $backendUrl,
    ScopeConfigInterface $scopeConfig
) {
    $this->_backendUrl = $backendUrl;
    $this->_scopeConfig = $scopeConfig;

public function isEnabled()
    return $this->scopeConfig->getValue(

public function isOrderGridEnabled()
    return (bool) $this->getConfigValue(



namespace TrucatchCompanyColumnPlugin;

class AddColumnsSalesOrderGridCollection
private $resource;

public function __construct(
    MagentoFrameworkAppResourceConnection $resource
) {
    $this->resource = $resource;

public function aroundGetReport(
    MagentoFrameworkViewElementUiComponentDataProviderCollectionFactory $subject,
    Closure $proceed,
) {
    $result = $proceed($requestName);
    if ($requestName == 'sales_order_grid_data_source') {
        if ($result instanceof MagentoSalesModelResourceModelOrderGridCollection) {
            $select = $result->getSelect();
                ['soa1' => $this->resource->getTableName('sales_order_address')],
                'main_table.entity_id = soa1.parent_id AND soa1.address_type = "billing"',
                ['billing_company' => 'company']
                ['soa2' => $this->resource->getTableName('sales_order_address')],
                'main_table.entity_id = soa2.parent_id AND soa2.address_type = "shipping"',
                ['shipping_company' => 'company']
    return $result;

And Lastly the sales_order_grid.xml:

<!-- "sales_order_grid_data_source" -->
<columns name="sales_order_columns">

    <!-- sales_order_address billing_company -->
    <column name="billing_company">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="label" xsi:type="string" translate="true">Bill-to Company</item>
                <item name="sortOrder" xsi:type="number">4</item>
                <item name="align" xsi:type="string">left</item>
                <item name="filter" xsi:type="string">text</item>
                <item name="visible" xsi:type="boolean">true</item>

    <!-- sales_order_address shipping_company -->
    <column name="shipping_company">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="label" xsi:type="string" translate="true">Ship-to Company</item>
                <item name="sortOrder" xsi:type="number">6</item>
                <item name="align" xsi:type="string">left</item>
                <item name="filter" xsi:type="string">text</item>
                <item name="visible" xsi:type="boolean">true</item>


I am looking to be able to enable/disable certains aspects of this module. For instance you could disable the Company Column from the Sales Order Grid (all information associated with that is above). But I can’t seem to grasp how to implement it into my plugins, if it is even possible.

I do understand that you can hide columns and such in Magento2 but I thought this would be an easy way to implement it as well. This way it would not load them for Filters also, but I am still working on getting the Filtering to work.

Please let me know if you need anything else to better assist me.


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.