Add Phone Number column in sales order grid
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
I am trying to add phone number column in my order grid.
I have added new column through sales_order_grid.xml
in my ui_component
directory. Code is below:
<?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="telephone">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">text</item>
<item name="label" xsi:type="string" translate="true">Phone Number</item>
<item name="sortOrder" xsi:type="number">6</item>
</item>
</argument>
</column>
</columns>
</listing>
What should I do in collection to get phone number?
magento2 order-grid sales-order-grid
add a comment |
I am trying to add phone number column in my order grid.
I have added new column through sales_order_grid.xml
in my ui_component
directory. Code is below:
<?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="telephone">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">text</item>
<item name="label" xsi:type="string" translate="true">Phone Number</item>
<item name="sortOrder" xsi:type="number">6</item>
</item>
</argument>
</column>
</columns>
</listing>
What should I do in collection to get phone number?
magento2 order-grid sales-order-grid
add a comment |
I am trying to add phone number column in my order grid.
I have added new column through sales_order_grid.xml
in my ui_component
directory. Code is below:
<?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="telephone">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">text</item>
<item name="label" xsi:type="string" translate="true">Phone Number</item>
<item name="sortOrder" xsi:type="number">6</item>
</item>
</argument>
</column>
</columns>
</listing>
What should I do in collection to get phone number?
magento2 order-grid sales-order-grid
I am trying to add phone number column in my order grid.
I have added new column through sales_order_grid.xml
in my ui_component
directory. Code is below:
<?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="telephone">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">text</item>
<item name="label" xsi:type="string" translate="true">Phone Number</item>
<item name="sortOrder" xsi:type="number">6</item>
</item>
</argument>
</column>
</columns>
</listing>
What should I do in collection to get phone number?
magento2 order-grid sales-order-grid
magento2 order-grid sales-order-grid
edited 14 hours ago
Shoaib Munir
asked Feb 11 at 9:40
Shoaib MunirShoaib Munir
2,4462930
2,4462930
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
You added the column in ui_component correctly
Just replace the _renderFiltersBefore function with my function in your module collection class
Path should be Vendor/Yourmodule/Model/ResourceModel/Order/Grid/Collection.php
protected function _renderFiltersBefore()
{
$joinTable = $this->getTable('sales_order_address');
$this->getSelect()->joinLeft($joinTable, 'main_table.entity_id =
sales_order_address.parent_id AND sales_order_address.address_type = "shipping"',
['telephone']);
parent::_renderFiltersBefore();
}
In Case if you miss it don't forgot to add this argument in your dependency injection di.xml
<argument name="collections" xsi:type="array">
<item name="sales_order_grid_data_source" xsi:type="string">VendorYourmoduleModelResourceModelOrderGridCollection</item>
</argument>
I hope this will help
This criteria is pretty much easy and it worked for me. Thanks!
– Shoaib Munir
Feb 11 at 10:24
add a comment |
Please add ui component class for your column as per below.
<?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="telephone" class="VendorModuleUiComponentListingColumnTelephone">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">text</item>
<item name="label" xsi:type="string" translate="true">Phone Number</item>
<item name="sortOrder" xsi:type="number">6</item>
</item>
</argument>
</column>
</columns>
</listing>
Now please add Telephone.php as below
namespace VendorModuleUiComponentListingColumn;
use MagentoSalesApiOrderRepositoryInterface;
use MagentoFrameworkViewElementUiComponentContextInterface;
use MagentoFrameworkViewElementUiComponentFactory;
use MagentoUiComponentListingColumnsColumn;
use MagentoFrameworkApiSearchCriteriaBuilder;
class Telephone extends Column
{
protected $_orderRepository;
protected $_searchCriteria;
public function __construct(ContextInterface $context, UiComponentFactory $uiComponentFactory, OrderRepositoryInterface $orderRepository, SearchCriteriaBuilder $criteria, array $components = , array $data = )
{
$this->_orderRepository = $orderRepository;
$this->_searchCriteria = $criteria;
parent::__construct($context, $uiComponentFactory, $components, $data);
}
public function prepareDataSource(array $dataSource)
{
if (isset($dataSource['data']['items'])) {
foreach ($dataSource['data']['items'] as & $item) {
$order = $this->_orderRepository->get($item["entity_id"]);
$telephone = $order->getBillingAddress()->getTelephone();
// $this->getData('name') returns the name of the column so in this case it would return export_status
$item[$this->getData('name')] = $telephone;
}
}
return $dataSource;
}
}
Please check and let me know if any issue.
Thanks you for taking time in answering my question +1
– Shoaib Munir
Feb 11 at 10:25
2
@ShoaibMunir appreciated, yes accepted ans is much easier and better then mine :)
– Aasim Goriya
Feb 11 at 10:31
@AasimGoriya with the above solution I am not able to filter orders using phone number.
– Sufyan Khot
Mar 13 at 10:43
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%2f261204%2fadd-phone-number-column-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
You added the column in ui_component correctly
Just replace the _renderFiltersBefore function with my function in your module collection class
Path should be Vendor/Yourmodule/Model/ResourceModel/Order/Grid/Collection.php
protected function _renderFiltersBefore()
{
$joinTable = $this->getTable('sales_order_address');
$this->getSelect()->joinLeft($joinTable, 'main_table.entity_id =
sales_order_address.parent_id AND sales_order_address.address_type = "shipping"',
['telephone']);
parent::_renderFiltersBefore();
}
In Case if you miss it don't forgot to add this argument in your dependency injection di.xml
<argument name="collections" xsi:type="array">
<item name="sales_order_grid_data_source" xsi:type="string">VendorYourmoduleModelResourceModelOrderGridCollection</item>
</argument>
I hope this will help
This criteria is pretty much easy and it worked for me. Thanks!
– Shoaib Munir
Feb 11 at 10:24
add a comment |
You added the column in ui_component correctly
Just replace the _renderFiltersBefore function with my function in your module collection class
Path should be Vendor/Yourmodule/Model/ResourceModel/Order/Grid/Collection.php
protected function _renderFiltersBefore()
{
$joinTable = $this->getTable('sales_order_address');
$this->getSelect()->joinLeft($joinTable, 'main_table.entity_id =
sales_order_address.parent_id AND sales_order_address.address_type = "shipping"',
['telephone']);
parent::_renderFiltersBefore();
}
In Case if you miss it don't forgot to add this argument in your dependency injection di.xml
<argument name="collections" xsi:type="array">
<item name="sales_order_grid_data_source" xsi:type="string">VendorYourmoduleModelResourceModelOrderGridCollection</item>
</argument>
I hope this will help
This criteria is pretty much easy and it worked for me. Thanks!
– Shoaib Munir
Feb 11 at 10:24
add a comment |
You added the column in ui_component correctly
Just replace the _renderFiltersBefore function with my function in your module collection class
Path should be Vendor/Yourmodule/Model/ResourceModel/Order/Grid/Collection.php
protected function _renderFiltersBefore()
{
$joinTable = $this->getTable('sales_order_address');
$this->getSelect()->joinLeft($joinTable, 'main_table.entity_id =
sales_order_address.parent_id AND sales_order_address.address_type = "shipping"',
['telephone']);
parent::_renderFiltersBefore();
}
In Case if you miss it don't forgot to add this argument in your dependency injection di.xml
<argument name="collections" xsi:type="array">
<item name="sales_order_grid_data_source" xsi:type="string">VendorYourmoduleModelResourceModelOrderGridCollection</item>
</argument>
I hope this will help
You added the column in ui_component correctly
Just replace the _renderFiltersBefore function with my function in your module collection class
Path should be Vendor/Yourmodule/Model/ResourceModel/Order/Grid/Collection.php
protected function _renderFiltersBefore()
{
$joinTable = $this->getTable('sales_order_address');
$this->getSelect()->joinLeft($joinTable, 'main_table.entity_id =
sales_order_address.parent_id AND sales_order_address.address_type = "shipping"',
['telephone']);
parent::_renderFiltersBefore();
}
In Case if you miss it don't forgot to add this argument in your dependency injection di.xml
<argument name="collections" xsi:type="array">
<item name="sales_order_grid_data_source" xsi:type="string">VendorYourmoduleModelResourceModelOrderGridCollection</item>
</argument>
I hope this will help
edited Feb 25 at 6:51
answered Feb 11 at 10:17
Muhammad HashamMuhammad Hasham
2,8162831
2,8162831
This criteria is pretty much easy and it worked for me. Thanks!
– Shoaib Munir
Feb 11 at 10:24
add a comment |
This criteria is pretty much easy and it worked for me. Thanks!
– Shoaib Munir
Feb 11 at 10:24
This criteria is pretty much easy and it worked for me. Thanks!
– Shoaib Munir
Feb 11 at 10:24
This criteria is pretty much easy and it worked for me. Thanks!
– Shoaib Munir
Feb 11 at 10:24
add a comment |
Please add ui component class for your column as per below.
<?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="telephone" class="VendorModuleUiComponentListingColumnTelephone">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">text</item>
<item name="label" xsi:type="string" translate="true">Phone Number</item>
<item name="sortOrder" xsi:type="number">6</item>
</item>
</argument>
</column>
</columns>
</listing>
Now please add Telephone.php as below
namespace VendorModuleUiComponentListingColumn;
use MagentoSalesApiOrderRepositoryInterface;
use MagentoFrameworkViewElementUiComponentContextInterface;
use MagentoFrameworkViewElementUiComponentFactory;
use MagentoUiComponentListingColumnsColumn;
use MagentoFrameworkApiSearchCriteriaBuilder;
class Telephone extends Column
{
protected $_orderRepository;
protected $_searchCriteria;
public function __construct(ContextInterface $context, UiComponentFactory $uiComponentFactory, OrderRepositoryInterface $orderRepository, SearchCriteriaBuilder $criteria, array $components = , array $data = )
{
$this->_orderRepository = $orderRepository;
$this->_searchCriteria = $criteria;
parent::__construct($context, $uiComponentFactory, $components, $data);
}
public function prepareDataSource(array $dataSource)
{
if (isset($dataSource['data']['items'])) {
foreach ($dataSource['data']['items'] as & $item) {
$order = $this->_orderRepository->get($item["entity_id"]);
$telephone = $order->getBillingAddress()->getTelephone();
// $this->getData('name') returns the name of the column so in this case it would return export_status
$item[$this->getData('name')] = $telephone;
}
}
return $dataSource;
}
}
Please check and let me know if any issue.
Thanks you for taking time in answering my question +1
– Shoaib Munir
Feb 11 at 10:25
2
@ShoaibMunir appreciated, yes accepted ans is much easier and better then mine :)
– Aasim Goriya
Feb 11 at 10:31
@AasimGoriya with the above solution I am not able to filter orders using phone number.
– Sufyan Khot
Mar 13 at 10:43
add a comment |
Please add ui component class for your column as per below.
<?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="telephone" class="VendorModuleUiComponentListingColumnTelephone">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">text</item>
<item name="label" xsi:type="string" translate="true">Phone Number</item>
<item name="sortOrder" xsi:type="number">6</item>
</item>
</argument>
</column>
</columns>
</listing>
Now please add Telephone.php as below
namespace VendorModuleUiComponentListingColumn;
use MagentoSalesApiOrderRepositoryInterface;
use MagentoFrameworkViewElementUiComponentContextInterface;
use MagentoFrameworkViewElementUiComponentFactory;
use MagentoUiComponentListingColumnsColumn;
use MagentoFrameworkApiSearchCriteriaBuilder;
class Telephone extends Column
{
protected $_orderRepository;
protected $_searchCriteria;
public function __construct(ContextInterface $context, UiComponentFactory $uiComponentFactory, OrderRepositoryInterface $orderRepository, SearchCriteriaBuilder $criteria, array $components = , array $data = )
{
$this->_orderRepository = $orderRepository;
$this->_searchCriteria = $criteria;
parent::__construct($context, $uiComponentFactory, $components, $data);
}
public function prepareDataSource(array $dataSource)
{
if (isset($dataSource['data']['items'])) {
foreach ($dataSource['data']['items'] as & $item) {
$order = $this->_orderRepository->get($item["entity_id"]);
$telephone = $order->getBillingAddress()->getTelephone();
// $this->getData('name') returns the name of the column so in this case it would return export_status
$item[$this->getData('name')] = $telephone;
}
}
return $dataSource;
}
}
Please check and let me know if any issue.
Thanks you for taking time in answering my question +1
– Shoaib Munir
Feb 11 at 10:25
2
@ShoaibMunir appreciated, yes accepted ans is much easier and better then mine :)
– Aasim Goriya
Feb 11 at 10:31
@AasimGoriya with the above solution I am not able to filter orders using phone number.
– Sufyan Khot
Mar 13 at 10:43
add a comment |
Please add ui component class for your column as per below.
<?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="telephone" class="VendorModuleUiComponentListingColumnTelephone">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">text</item>
<item name="label" xsi:type="string" translate="true">Phone Number</item>
<item name="sortOrder" xsi:type="number">6</item>
</item>
</argument>
</column>
</columns>
</listing>
Now please add Telephone.php as below
namespace VendorModuleUiComponentListingColumn;
use MagentoSalesApiOrderRepositoryInterface;
use MagentoFrameworkViewElementUiComponentContextInterface;
use MagentoFrameworkViewElementUiComponentFactory;
use MagentoUiComponentListingColumnsColumn;
use MagentoFrameworkApiSearchCriteriaBuilder;
class Telephone extends Column
{
protected $_orderRepository;
protected $_searchCriteria;
public function __construct(ContextInterface $context, UiComponentFactory $uiComponentFactory, OrderRepositoryInterface $orderRepository, SearchCriteriaBuilder $criteria, array $components = , array $data = )
{
$this->_orderRepository = $orderRepository;
$this->_searchCriteria = $criteria;
parent::__construct($context, $uiComponentFactory, $components, $data);
}
public function prepareDataSource(array $dataSource)
{
if (isset($dataSource['data']['items'])) {
foreach ($dataSource['data']['items'] as & $item) {
$order = $this->_orderRepository->get($item["entity_id"]);
$telephone = $order->getBillingAddress()->getTelephone();
// $this->getData('name') returns the name of the column so in this case it would return export_status
$item[$this->getData('name')] = $telephone;
}
}
return $dataSource;
}
}
Please check and let me know if any issue.
Please add ui component class for your column as per below.
<?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="telephone" class="VendorModuleUiComponentListingColumnTelephone">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">text</item>
<item name="label" xsi:type="string" translate="true">Phone Number</item>
<item name="sortOrder" xsi:type="number">6</item>
</item>
</argument>
</column>
</columns>
</listing>
Now please add Telephone.php as below
namespace VendorModuleUiComponentListingColumn;
use MagentoSalesApiOrderRepositoryInterface;
use MagentoFrameworkViewElementUiComponentContextInterface;
use MagentoFrameworkViewElementUiComponentFactory;
use MagentoUiComponentListingColumnsColumn;
use MagentoFrameworkApiSearchCriteriaBuilder;
class Telephone extends Column
{
protected $_orderRepository;
protected $_searchCriteria;
public function __construct(ContextInterface $context, UiComponentFactory $uiComponentFactory, OrderRepositoryInterface $orderRepository, SearchCriteriaBuilder $criteria, array $components = , array $data = )
{
$this->_orderRepository = $orderRepository;
$this->_searchCriteria = $criteria;
parent::__construct($context, $uiComponentFactory, $components, $data);
}
public function prepareDataSource(array $dataSource)
{
if (isset($dataSource['data']['items'])) {
foreach ($dataSource['data']['items'] as & $item) {
$order = $this->_orderRepository->get($item["entity_id"]);
$telephone = $order->getBillingAddress()->getTelephone();
// $this->getData('name') returns the name of the column so in this case it would return export_status
$item[$this->getData('name')] = $telephone;
}
}
return $dataSource;
}
}
Please check and let me know if any issue.
answered Feb 11 at 9:52
Aasim GoriyaAasim Goriya
2,92611039
2,92611039
Thanks you for taking time in answering my question +1
– Shoaib Munir
Feb 11 at 10:25
2
@ShoaibMunir appreciated, yes accepted ans is much easier and better then mine :)
– Aasim Goriya
Feb 11 at 10:31
@AasimGoriya with the above solution I am not able to filter orders using phone number.
– Sufyan Khot
Mar 13 at 10:43
add a comment |
Thanks you for taking time in answering my question +1
– Shoaib Munir
Feb 11 at 10:25
2
@ShoaibMunir appreciated, yes accepted ans is much easier and better then mine :)
– Aasim Goriya
Feb 11 at 10:31
@AasimGoriya with the above solution I am not able to filter orders using phone number.
– Sufyan Khot
Mar 13 at 10:43
Thanks you for taking time in answering my question +1
– Shoaib Munir
Feb 11 at 10:25
Thanks you for taking time in answering my question +1
– Shoaib Munir
Feb 11 at 10:25
2
2
@ShoaibMunir appreciated, yes accepted ans is much easier and better then mine :)
– Aasim Goriya
Feb 11 at 10:31
@ShoaibMunir appreciated, yes accepted ans is much easier and better then mine :)
– Aasim Goriya
Feb 11 at 10:31
@AasimGoriya with the above solution I am not able to filter orders using phone number.
– Sufyan Khot
Mar 13 at 10:43
@AasimGoriya with the above solution I am not able to filter orders using phone number.
– Sufyan Khot
Mar 13 at 10:43
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%2f261204%2fadd-phone-number-column-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