1

I have added a Column to the New Order -> Customer Grid. I am having a really tough time getting the system config to disable this code if turned off. I was hoping I could use a simple ifconfig in the sales_order_create_customer_block.xml or the di.xml to check but it does not work. I have tried calling isNewOrderCustomerGridEnabled() as an if before but I get a cannot be null error.

In the other grids, I added the column with a Plugin and the ui_component xml. Which I was able to add a specific class Ui/Component/Listing/Column/Company.php which checks the Data.php and displays the information depending on the system config setting.

Here is some of the code. Please let me know if you need any more information.

sales_order_create_customer_block.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
    <referenceBlock name="adminhtml.customer.grid.container">
        <arguments>
            <argument name="dataSource" xsi:type="object">Trucatch\CompanyColumn\Model\ResourceModel\Order\Customer\Collection</argument>
        </arguments>
        <referenceBlock name="adminhtml.customer.grid.columnSet">
            <block class="Magento\Backend\Block\Widget\Grid\Column" as="billing_company" after="name">
                <arguments>
                    <argument name="header" xsi:type="string" translate="true">Company</argument>
                    <argument name="index" xsi:type="string">billing_company</argument>
                </arguments>
            </block>
        </referenceBlock>
    </referenceBlock>
</body>
</page>

di.xml

<preference for="Magento\Sales\Model\ResourceModel\Order\Customer\Collection" type="Trucatch\CompanyColumn\Model\ResourceModel\Order\Customer\Collection"/>

Data.php

const CONFIG_PATH_GENERAL_NEW_ORDER_CUSTOMER_GRID = 'companycolumn/general/new_order_customer_grid_enabled';

public function isNewOrderCustomerGridEnabled()
{
    return $this->scopeConfig->getValue(
        self::CONFIG_PATH_GENERAL_NEW_ORDER_CUSTOMER_GRID,
        \Magento\Store\Model\ScopeInterface::SCOPE_STORE
    );
}

Collection.php

protected function _initSelect()
{
    parent::_initSelect();
    $this->joinAttribute(
        'billing_company',
        'customer_address/company',
        'default_billing',
        null,
        'left'
    );
    return $this;
}

0

Your Answer

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