Magento2 : Add sales_order column coupon_code in sales order gridHow can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2: admin sales grid, filter column from sales_order tableMagento2 : sales order grid add new column with it's valuesMagento 2.2.5: Overriding Admin Controller sales/orderGrid action column custom callback with multiple params in magento2Magento2 : Add custom column in sales order gridMagento 2.2.5: Add, Update and Delete existing products Custom Options
Password maker in c#
During copyediting, journal disagrees about spelling of paper's main topic
Is an acid a salt or not?
Credit union holding car note, refuses to provide details of how payments have been applied
What are the steps/action plan to introduce Test Automation in a company?
Is purchasing foreign currency before going abroad a losing proposition?
Are there any intersection of Theory A and Theory B?
Where is the USB2 OTG port on the RPi 4 Model B located?
How can one write good dialogue in a story without sounding wooden?
Bronze Age Underwater Civilization
What is temperature on a quantum level
Correct use of ergeben?
Email about missed connecting flight compensation 5 months after flight, is there a point?
Why is dry soil hydrophobic? Bad gardener paradox
Is Prophet from Facebook any different from a linear regression?
Are randomly-generated passwords starting with "a" less secure?
Why do players in the past play much longer tournaments than today's top players?
Why are they 'nude photos'?
Is it rude to tell recruiters I would only change jobs for a better salary?
QGIS Welcome page: What is 'pin to list' for?
Can I use "candidate" as a verb?
How the name "craqueuhhe" is read
As a DM, how to avoid unconscious metagaming when dealing with a high AC character?
Is it possible for thermophilic viruses to infect humans?
Magento2 : Add sales_order column coupon_code in sales order grid
How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2: admin sales grid, filter column from sales_order tableMagento2 : sales order grid add new column with it's valuesMagento 2.2.5: Overriding Admin Controller sales/orderGrid action column custom callback with multiple params in magento2Magento2 : Add custom column in sales order gridMagento 2.2.5: Add, Update and Delete existing products Custom Options
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
In sales_order table we have a column coupon_code. I need to show it in sales order grid.
I have added the column coupon code by overriding sales_order_grid.xml file. The column is being shown. Now I need to show the values of sales_order.coupon_code.
sales_order_grid.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="sales_order_columns">
<column name="coupon_code">
<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">text</item>
<item name="align" xsi:type="string">left</item>
<item name="label" xsi:type="string" translate="true">Coupon Code</item>
</item>
</argument>
</column>
</columns>
</listing>
Module/etc/di.xml:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<virtualType name="MagentoSalesModelResourceModelOrderGrid" type="MagentoSalesModelResourceModelGrid">
<arguments>
<argument name="columns" xsi:type="array">
<item name="coupon_code" xsi:type="string">sales_order.coupon_code</item>
</argument>
</arguments>
</virtualType>
</config>
magento2 sales-order sales-order-grid
|
show 2 more comments
In sales_order table we have a column coupon_code. I need to show it in sales order grid.
I have added the column coupon code by overriding sales_order_grid.xml file. The column is being shown. Now I need to show the values of sales_order.coupon_code.
sales_order_grid.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="sales_order_columns">
<column name="coupon_code">
<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">text</item>
<item name="align" xsi:type="string">left</item>
<item name="label" xsi:type="string" translate="true">Coupon Code</item>
</item>
</argument>
</column>
</columns>
</listing>
Module/etc/di.xml:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<virtualType name="MagentoSalesModelResourceModelOrderGrid" type="MagentoSalesModelResourceModelGrid">
<arguments>
<argument name="columns" xsi:type="array">
<item name="coupon_code" xsi:type="string">sales_order.coupon_code</item>
</argument>
</arguments>
</virtualType>
</config>
magento2 sales-order sales-order-grid
Given answer try it, and it will add the data when the next time it post data in sales_order and that will copy into sales_order_grid as well.
– Prathap Gunasekaran
Mar 5 at 12:31
sure I am trying your solution
– Sufyan Khot
Mar 5 at 12:34
1
the coupon code column is still empty
– Sufyan Khot
Mar 6 at 5:21
When the next time data is been posted to sales_order then it will get posted in sales_order_grid table as well. Getting it
– Prathap Gunasekaran
Mar 6 at 5:21
yes I placed a new order and used a coupon code but its not showing in grid. I have updated my question
– Sufyan Khot
Mar 6 at 5:23
|
show 2 more comments
In sales_order table we have a column coupon_code. I need to show it in sales order grid.
I have added the column coupon code by overriding sales_order_grid.xml file. The column is being shown. Now I need to show the values of sales_order.coupon_code.
sales_order_grid.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="sales_order_columns">
<column name="coupon_code">
<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">text</item>
<item name="align" xsi:type="string">left</item>
<item name="label" xsi:type="string" translate="true">Coupon Code</item>
</item>
</argument>
</column>
</columns>
</listing>
Module/etc/di.xml:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<virtualType name="MagentoSalesModelResourceModelOrderGrid" type="MagentoSalesModelResourceModelGrid">
<arguments>
<argument name="columns" xsi:type="array">
<item name="coupon_code" xsi:type="string">sales_order.coupon_code</item>
</argument>
</arguments>
</virtualType>
</config>
magento2 sales-order sales-order-grid
In sales_order table we have a column coupon_code. I need to show it in sales order grid.
I have added the column coupon code by overriding sales_order_grid.xml file. The column is being shown. Now I need to show the values of sales_order.coupon_code.
sales_order_grid.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="sales_order_columns">
<column name="coupon_code">
<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">text</item>
<item name="align" xsi:type="string">left</item>
<item name="label" xsi:type="string" translate="true">Coupon Code</item>
</item>
</argument>
</column>
</columns>
</listing>
Module/etc/di.xml:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<virtualType name="MagentoSalesModelResourceModelOrderGrid" type="MagentoSalesModelResourceModelGrid">
<arguments>
<argument name="columns" xsi:type="array">
<item name="coupon_code" xsi:type="string">sales_order.coupon_code</item>
</argument>
</arguments>
</virtualType>
</config>
magento2 sales-order sales-order-grid
magento2 sales-order sales-order-grid
edited Mar 6 at 6:26
Sufyan Khot
asked Mar 5 at 12:23
Sufyan KhotSufyan Khot
18713 bronze badges
18713 bronze badges
Given answer try it, and it will add the data when the next time it post data in sales_order and that will copy into sales_order_grid as well.
– Prathap Gunasekaran
Mar 5 at 12:31
sure I am trying your solution
– Sufyan Khot
Mar 5 at 12:34
1
the coupon code column is still empty
– Sufyan Khot
Mar 6 at 5:21
When the next time data is been posted to sales_order then it will get posted in sales_order_grid table as well. Getting it
– Prathap Gunasekaran
Mar 6 at 5:21
yes I placed a new order and used a coupon code but its not showing in grid. I have updated my question
– Sufyan Khot
Mar 6 at 5:23
|
show 2 more comments
Given answer try it, and it will add the data when the next time it post data in sales_order and that will copy into sales_order_grid as well.
– Prathap Gunasekaran
Mar 5 at 12:31
sure I am trying your solution
– Sufyan Khot
Mar 5 at 12:34
1
the coupon code column is still empty
– Sufyan Khot
Mar 6 at 5:21
When the next time data is been posted to sales_order then it will get posted in sales_order_grid table as well. Getting it
– Prathap Gunasekaran
Mar 6 at 5:21
yes I placed a new order and used a coupon code but its not showing in grid. I have updated my question
– Sufyan Khot
Mar 6 at 5:23
Given answer try it, and it will add the data when the next time it post data in sales_order and that will copy into sales_order_grid as well.
– Prathap Gunasekaran
Mar 5 at 12:31
Given answer try it, and it will add the data when the next time it post data in sales_order and that will copy into sales_order_grid as well.
– Prathap Gunasekaran
Mar 5 at 12:31
sure I am trying your solution
– Sufyan Khot
Mar 5 at 12:34
sure I am trying your solution
– Sufyan Khot
Mar 5 at 12:34
1
1
the coupon code column is still empty
– Sufyan Khot
Mar 6 at 5:21
the coupon code column is still empty
– Sufyan Khot
Mar 6 at 5:21
When the next time data is been posted to sales_order then it will get posted in sales_order_grid table as well. Getting it
– Prathap Gunasekaran
Mar 6 at 5:21
When the next time data is been posted to sales_order then it will get posted in sales_order_grid table as well. Getting it
– Prathap Gunasekaran
Mar 6 at 5:21
yes I placed a new order and used a coupon code but its not showing in grid. I have updated my question
– Sufyan Khot
Mar 6 at 5:23
yes I placed a new order and used a coupon code but its not showing in grid. I have updated my question
– Sufyan Khot
Mar 6 at 5:23
|
show 2 more comments
2 Answers
2
active
oldest
votes
EDIT:
Add in or add an InstallSchema.php from this path of your custom module:
Vendor/Module/Setup/InstallSchema.php
<?php
namespace vendormoduleSetup;
use MagentoFrameworkSetupInstallSchemaInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupSchemaSetupInterface;
class InstallSchema implements InstallSchemaInterface
/**
* @inheritdoc
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
$installer = $setup;
$installer->startSetup();
/* While module install, creates column in sales_order_grid table */
$eavTable = $installer->getTable('sales_order_grid');
$columns = [
'coupon_code' => [
'type' => MagentoFrameworkDBDdlTable::TYPE_TEXT,
'nullable' => true,
'comment' => 'Coupon Code',
],
];
$connection = $installer->getConnection();
foreach ($columns as $name => $definition)
$connection->addColumn($eavTable, $name, $definition);
$installer->endSetup();
Then after, you have to map the coupon_code column to sales_order column in your di.xml configuration:
<virtualType name="MagentoSalesModelResourceModelOrderGrid" type="MagentoSalesModelResourceModelGrid">
<arguments>
<argument name="columns" xsi:type="array">
<item name="coupon_code" xsi:type="string">sales_order.coupon_code</item>
</argument>
</arguments>
</virtualType>
Then in your sales_order_grid.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="sales_order_columns">
<column name="coupon_code">
<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">text</item>
<item name="align" xsi:type="string">left</item>
<item name="label" xsi:type="string" translate="true">Coupon Code</item>
</item>
</argument>
</column>
</columns>
</listing>
Note: make sure to run commands after performing changes above:
setup:upgrade
setup:static-content:deploy -f
@Sufyan, have you tried the above solution?
– fmsthird
Mar 6 at 5:37
Do I need to add coupon_code column in sales_order_grid table also?
– Sufyan Khot
Mar 6 at 6:23
no need , just try the code above and it should work
– fmsthird
Mar 6 at 6:24
The coupon code column is empty in grid. I have updated my question also.
– Sufyan Khot
Mar 6 at 6:24
using code above? have you tried to put data on coupon_code column in your schema?
– fmsthird
Mar 6 at 6:25
|
show 5 more comments
Try this,
Add di.xml in
app/code/vendor/module/etc/di.xml
add the below code in it
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<virtualType name="MagentoSalesModelResourceModelOrderGrid" type="MagentoSalesModelResourceModelGrid">
<arguments>
<argument name="columns">
<item name="salesperson" xsi:type="string">sales_order.coupon_code</item>
</argument>
</arguments>
</virtualType>
</config>
Hope this helps :)
this solution works only if sales_order_grid already has coupon_code column. You can update your answer.
– Sufyan Khot
Mar 6 at 7:39
That's what I was saying you need to have column, see the question is to show data in grid. Anyway you got it, finally after the code is been given
– Prathap Gunasekaran
Mar 6 at 8:13
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f264493%2fmagento2-add-sales-order-column-coupon-code-in-sales-order-grid%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
EDIT:
Add in or add an InstallSchema.php from this path of your custom module:
Vendor/Module/Setup/InstallSchema.php
<?php
namespace vendormoduleSetup;
use MagentoFrameworkSetupInstallSchemaInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupSchemaSetupInterface;
class InstallSchema implements InstallSchemaInterface
/**
* @inheritdoc
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
$installer = $setup;
$installer->startSetup();
/* While module install, creates column in sales_order_grid table */
$eavTable = $installer->getTable('sales_order_grid');
$columns = [
'coupon_code' => [
'type' => MagentoFrameworkDBDdlTable::TYPE_TEXT,
'nullable' => true,
'comment' => 'Coupon Code',
],
];
$connection = $installer->getConnection();
foreach ($columns as $name => $definition)
$connection->addColumn($eavTable, $name, $definition);
$installer->endSetup();
Then after, you have to map the coupon_code column to sales_order column in your di.xml configuration:
<virtualType name="MagentoSalesModelResourceModelOrderGrid" type="MagentoSalesModelResourceModelGrid">
<arguments>
<argument name="columns" xsi:type="array">
<item name="coupon_code" xsi:type="string">sales_order.coupon_code</item>
</argument>
</arguments>
</virtualType>
Then in your sales_order_grid.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="sales_order_columns">
<column name="coupon_code">
<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">text</item>
<item name="align" xsi:type="string">left</item>
<item name="label" xsi:type="string" translate="true">Coupon Code</item>
</item>
</argument>
</column>
</columns>
</listing>
Note: make sure to run commands after performing changes above:
setup:upgrade
setup:static-content:deploy -f
@Sufyan, have you tried the above solution?
– fmsthird
Mar 6 at 5:37
Do I need to add coupon_code column in sales_order_grid table also?
– Sufyan Khot
Mar 6 at 6:23
no need , just try the code above and it should work
– fmsthird
Mar 6 at 6:24
The coupon code column is empty in grid. I have updated my question also.
– Sufyan Khot
Mar 6 at 6:24
using code above? have you tried to put data on coupon_code column in your schema?
– fmsthird
Mar 6 at 6:25
|
show 5 more comments
EDIT:
Add in or add an InstallSchema.php from this path of your custom module:
Vendor/Module/Setup/InstallSchema.php
<?php
namespace vendormoduleSetup;
use MagentoFrameworkSetupInstallSchemaInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupSchemaSetupInterface;
class InstallSchema implements InstallSchemaInterface
/**
* @inheritdoc
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
$installer = $setup;
$installer->startSetup();
/* While module install, creates column in sales_order_grid table */
$eavTable = $installer->getTable('sales_order_grid');
$columns = [
'coupon_code' => [
'type' => MagentoFrameworkDBDdlTable::TYPE_TEXT,
'nullable' => true,
'comment' => 'Coupon Code',
],
];
$connection = $installer->getConnection();
foreach ($columns as $name => $definition)
$connection->addColumn($eavTable, $name, $definition);
$installer->endSetup();
Then after, you have to map the coupon_code column to sales_order column in your di.xml configuration:
<virtualType name="MagentoSalesModelResourceModelOrderGrid" type="MagentoSalesModelResourceModelGrid">
<arguments>
<argument name="columns" xsi:type="array">
<item name="coupon_code" xsi:type="string">sales_order.coupon_code</item>
</argument>
</arguments>
</virtualType>
Then in your sales_order_grid.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="sales_order_columns">
<column name="coupon_code">
<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">text</item>
<item name="align" xsi:type="string">left</item>
<item name="label" xsi:type="string" translate="true">Coupon Code</item>
</item>
</argument>
</column>
</columns>
</listing>
Note: make sure to run commands after performing changes above:
setup:upgrade
setup:static-content:deploy -f
@Sufyan, have you tried the above solution?
– fmsthird
Mar 6 at 5:37
Do I need to add coupon_code column in sales_order_grid table also?
– Sufyan Khot
Mar 6 at 6:23
no need , just try the code above and it should work
– fmsthird
Mar 6 at 6:24
The coupon code column is empty in grid. I have updated my question also.
– Sufyan Khot
Mar 6 at 6:24
using code above? have you tried to put data on coupon_code column in your schema?
– fmsthird
Mar 6 at 6:25
|
show 5 more comments
EDIT:
Add in or add an InstallSchema.php from this path of your custom module:
Vendor/Module/Setup/InstallSchema.php
<?php
namespace vendormoduleSetup;
use MagentoFrameworkSetupInstallSchemaInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupSchemaSetupInterface;
class InstallSchema implements InstallSchemaInterface
/**
* @inheritdoc
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
$installer = $setup;
$installer->startSetup();
/* While module install, creates column in sales_order_grid table */
$eavTable = $installer->getTable('sales_order_grid');
$columns = [
'coupon_code' => [
'type' => MagentoFrameworkDBDdlTable::TYPE_TEXT,
'nullable' => true,
'comment' => 'Coupon Code',
],
];
$connection = $installer->getConnection();
foreach ($columns as $name => $definition)
$connection->addColumn($eavTable, $name, $definition);
$installer->endSetup();
Then after, you have to map the coupon_code column to sales_order column in your di.xml configuration:
<virtualType name="MagentoSalesModelResourceModelOrderGrid" type="MagentoSalesModelResourceModelGrid">
<arguments>
<argument name="columns" xsi:type="array">
<item name="coupon_code" xsi:type="string">sales_order.coupon_code</item>
</argument>
</arguments>
</virtualType>
Then in your sales_order_grid.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="sales_order_columns">
<column name="coupon_code">
<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">text</item>
<item name="align" xsi:type="string">left</item>
<item name="label" xsi:type="string" translate="true">Coupon Code</item>
</item>
</argument>
</column>
</columns>
</listing>
Note: make sure to run commands after performing changes above:
setup:upgrade
setup:static-content:deploy -f
EDIT:
Add in or add an InstallSchema.php from this path of your custom module:
Vendor/Module/Setup/InstallSchema.php
<?php
namespace vendormoduleSetup;
use MagentoFrameworkSetupInstallSchemaInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupSchemaSetupInterface;
class InstallSchema implements InstallSchemaInterface
/**
* @inheritdoc
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
$installer = $setup;
$installer->startSetup();
/* While module install, creates column in sales_order_grid table */
$eavTable = $installer->getTable('sales_order_grid');
$columns = [
'coupon_code' => [
'type' => MagentoFrameworkDBDdlTable::TYPE_TEXT,
'nullable' => true,
'comment' => 'Coupon Code',
],
];
$connection = $installer->getConnection();
foreach ($columns as $name => $definition)
$connection->addColumn($eavTable, $name, $definition);
$installer->endSetup();
Then after, you have to map the coupon_code column to sales_order column in your di.xml configuration:
<virtualType name="MagentoSalesModelResourceModelOrderGrid" type="MagentoSalesModelResourceModelGrid">
<arguments>
<argument name="columns" xsi:type="array">
<item name="coupon_code" xsi:type="string">sales_order.coupon_code</item>
</argument>
</arguments>
</virtualType>
Then in your sales_order_grid.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="sales_order_columns">
<column name="coupon_code">
<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">text</item>
<item name="align" xsi:type="string">left</item>
<item name="label" xsi:type="string" translate="true">Coupon Code</item>
</item>
</argument>
</column>
</columns>
</listing>
Note: make sure to run commands after performing changes above:
setup:upgrade
setup:static-content:deploy -f
edited Mar 6 at 6:48
answered Mar 5 at 12:40
fmsthirdfmsthird
3,4994 gold badges7 silver badges31 bronze badges
3,4994 gold badges7 silver badges31 bronze badges
@Sufyan, have you tried the above solution?
– fmsthird
Mar 6 at 5:37
Do I need to add coupon_code column in sales_order_grid table also?
– Sufyan Khot
Mar 6 at 6:23
no need , just try the code above and it should work
– fmsthird
Mar 6 at 6:24
The coupon code column is empty in grid. I have updated my question also.
– Sufyan Khot
Mar 6 at 6:24
using code above? have you tried to put data on coupon_code column in your schema?
– fmsthird
Mar 6 at 6:25
|
show 5 more comments
@Sufyan, have you tried the above solution?
– fmsthird
Mar 6 at 5:37
Do I need to add coupon_code column in sales_order_grid table also?
– Sufyan Khot
Mar 6 at 6:23
no need , just try the code above and it should work
– fmsthird
Mar 6 at 6:24
The coupon code column is empty in grid. I have updated my question also.
– Sufyan Khot
Mar 6 at 6:24
using code above? have you tried to put data on coupon_code column in your schema?
– fmsthird
Mar 6 at 6:25
@Sufyan, have you tried the above solution?
– fmsthird
Mar 6 at 5:37
@Sufyan, have you tried the above solution?
– fmsthird
Mar 6 at 5:37
Do I need to add coupon_code column in sales_order_grid table also?
– Sufyan Khot
Mar 6 at 6:23
Do I need to add coupon_code column in sales_order_grid table also?
– Sufyan Khot
Mar 6 at 6:23
no need , just try the code above and it should work
– fmsthird
Mar 6 at 6:24
no need , just try the code above and it should work
– fmsthird
Mar 6 at 6:24
The coupon code column is empty in grid. I have updated my question also.
– Sufyan Khot
Mar 6 at 6:24
The coupon code column is empty in grid. I have updated my question also.
– Sufyan Khot
Mar 6 at 6:24
using code above? have you tried to put data on coupon_code column in your schema?
– fmsthird
Mar 6 at 6:25
using code above? have you tried to put data on coupon_code column in your schema?
– fmsthird
Mar 6 at 6:25
|
show 5 more comments
Try this,
Add di.xml in
app/code/vendor/module/etc/di.xml
add the below code in it
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<virtualType name="MagentoSalesModelResourceModelOrderGrid" type="MagentoSalesModelResourceModelGrid">
<arguments>
<argument name="columns">
<item name="salesperson" xsi:type="string">sales_order.coupon_code</item>
</argument>
</arguments>
</virtualType>
</config>
Hope this helps :)
this solution works only if sales_order_grid already has coupon_code column. You can update your answer.
– Sufyan Khot
Mar 6 at 7:39
That's what I was saying you need to have column, see the question is to show data in grid. Anyway you got it, finally after the code is been given
– Prathap Gunasekaran
Mar 6 at 8:13
add a comment |
Try this,
Add di.xml in
app/code/vendor/module/etc/di.xml
add the below code in it
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<virtualType name="MagentoSalesModelResourceModelOrderGrid" type="MagentoSalesModelResourceModelGrid">
<arguments>
<argument name="columns">
<item name="salesperson" xsi:type="string">sales_order.coupon_code</item>
</argument>
</arguments>
</virtualType>
</config>
Hope this helps :)
this solution works only if sales_order_grid already has coupon_code column. You can update your answer.
– Sufyan Khot
Mar 6 at 7:39
That's what I was saying you need to have column, see the question is to show data in grid. Anyway you got it, finally after the code is been given
– Prathap Gunasekaran
Mar 6 at 8:13
add a comment |
Try this,
Add di.xml in
app/code/vendor/module/etc/di.xml
add the below code in it
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<virtualType name="MagentoSalesModelResourceModelOrderGrid" type="MagentoSalesModelResourceModelGrid">
<arguments>
<argument name="columns">
<item name="salesperson" xsi:type="string">sales_order.coupon_code</item>
</argument>
</arguments>
</virtualType>
</config>
Hope this helps :)
Try this,
Add di.xml in
app/code/vendor/module/etc/di.xml
add the below code in it
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<virtualType name="MagentoSalesModelResourceModelOrderGrid" type="MagentoSalesModelResourceModelGrid">
<arguments>
<argument name="columns">
<item name="salesperson" xsi:type="string">sales_order.coupon_code</item>
</argument>
</arguments>
</virtualType>
</config>
Hope this helps :)
answered Mar 5 at 12:30
Prathap GunasekaranPrathap Gunasekaran
2,4471 gold badge7 silver badges22 bronze badges
2,4471 gold badge7 silver badges22 bronze badges
this solution works only if sales_order_grid already has coupon_code column. You can update your answer.
– Sufyan Khot
Mar 6 at 7:39
That's what I was saying you need to have column, see the question is to show data in grid. Anyway you got it, finally after the code is been given
– Prathap Gunasekaran
Mar 6 at 8:13
add a comment |
this solution works only if sales_order_grid already has coupon_code column. You can update your answer.
– Sufyan Khot
Mar 6 at 7:39
That's what I was saying you need to have column, see the question is to show data in grid. Anyway you got it, finally after the code is been given
– Prathap Gunasekaran
Mar 6 at 8:13
this solution works only if sales_order_grid already has coupon_code column. You can update your answer.
– Sufyan Khot
Mar 6 at 7:39
this solution works only if sales_order_grid already has coupon_code column. You can update your answer.
– Sufyan Khot
Mar 6 at 7:39
That's what I was saying you need to have column, see the question is to show data in grid. Anyway you got it, finally after the code is been given
– Prathap Gunasekaran
Mar 6 at 8:13
That's what I was saying you need to have column, see the question is to show data in grid. Anyway you got it, finally after the code is been given
– Prathap Gunasekaran
Mar 6 at 8:13
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f264493%2fmagento2-add-sales-order-column-coupon-code-in-sales-order-grid%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Given answer try it, and it will add the data when the next time it post data in sales_order and that will copy into sales_order_grid as well.
– Prathap Gunasekaran
Mar 5 at 12:31
sure I am trying your solution
– Sufyan Khot
Mar 5 at 12:34
1
the coupon code column is still empty
– Sufyan Khot
Mar 6 at 5:21
When the next time data is been posted to sales_order then it will get posted in sales_order_grid table as well. Getting it
– Prathap Gunasekaran
Mar 6 at 5:21
yes I placed a new order and used a coupon code but its not showing in grid. I have updated my question
– Sufyan Khot
Mar 6 at 5:23