2

I have created an extension to show Customer Company Name in Order grid. But when is creating a new order, it is not showing in order grid. Here are codes:

1) Vendor\CompanyName\etc\adminhtml\di.xml

<virtualType name="Magento\Sales\Model\ResourceModel\Order\Grid" type="Magento\Sales\Model\ResourceModel\Grid">
    <arguments>
        <argument name="joins" xsi:type="array">
             <item name="customer_grid_flat" xsi:type="array">
                <item name="table" xsi:type="string">customer_grid_flat</item>
                <item name="origin_column" xsi:type="string">customer_id</item>
                <item name="target_column" xsi:type="string">entity_id</item>
            </item>
        </argument>
        <argument name="columns" xsi:type="array">
            <item name="billing_company" xsi:type="string">customer_grid_flat.billing_company</item>                
        </argument>
    </arguments>
</virtualType>

2) Vendor\CompanyName\view\adminhtml\ui_component\sales_order_grid.xml

<columns name="sales_order_columns">
<column name="billing_company">
    <argument name="data" xsi:type="array">                
         <item name="js_config" xsi:type="array">
            <item name="component" xsi:type="string">Magento_Ui/js/grid/columns/column</item>
        </item>
        <item name="config" xsi:type="array">
            <item name="visible" xsi:type="boolean">true</item>
            <item name="dataType" xsi:type="string">select</item>
            <item name="align" xsi:type="string">left</item>
            <item name="filter" xsi:type="string">select</item>
            <item name="label" xsi:type="string" translate="true">Company Name</item>
        </item>
    </argument>
</column>

3)Vendor\CompanyName\Setup\UpgradeSchema.php

   namespace Cis\Customercompany\Setup;

   use Magento\Framework\Setup\ModuleContextInterface;
   use Magento\Framework\Setup\SchemaSetupInterface;
   use Magento\Framework\DB\Ddl\Table;
   use Magento\Framework\Setup\UpgradeSchemaInterface;
   use Magento\Framework\DB\Adapter\AdapterInterface;

 class UpgradeSchema implements UpgradeSchemaInterface
 {

   /**
    * {@inheritdoc}
    * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
   */
   public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
   {

       $installer = $setup;
       $installer->startSetup();

       $installer->getConnection()->addColumn(
            $installer->getTable('sales_order_grid'),
            'billing_company',
            [
                'type'     => Table::TYPE_TEXT,
                'nullable' => true,
                'comment'  => 'Company Name',
            ]
        );

       $setup->endSetup();
  }
}

4)Vendor\CompanyName\Setup\UpgradeData.php

namespace Cis\Customercompany\Setup;

use Magento\Framework\Setup\UpgradeDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;

class UpgradeData implements UpgradeDataInterface
{

    public function __construct()
    {

    }

    public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
    {
        $setup->startSetup();

    if (version_compare($context->getVersion(), '1.0.1', 'getConnection();
        $grid = $setup->getTable('sales_order_grid');
        $source = $setup->getTable('customer_grid_flat');

        $connection->query(
            $connection->updateFromSelect(
                $connection->select()
                    ->join(
                        $source,
                        sprintf('%s.customer_id = %s.entity_id', $grid, $source),
                        'billing_company'
                    ),
                $grid
            )
        );
    }

    $setup->endSetup();
    }
}

Can anyone help me what is wrong with my codes and please correct it so that Customer Company Name will be shown in order grid.

  • Did you resolve it? – 3CE Dec 27 '17 at 15:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.