3

I am trying to display quote id of an order in the sales order grid. New field is getting displayed in the grid. However the value of the quote id is not getting populated in the grid against each order.

How to show the quote id from the sales. I believe di.xml needs to be added for it work. I am not sure how the di.xml needs to be.

Here is the code view\adminhtml\ui_component\sales_order_grid.xml

<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Ui/etc/ui_configuration.xsd">
<columns name="sales_order_columns">
 <column name="quote_id">
 <argument name="data" xsi:type="array">
 <item name="config" xsi:type="array">
 <item name="label" xsi:type="string" translate="true">Quote Id</item>
 </item>
 </argument>
 </column>
</columns>
</listing>
Khoa Truong
32.5k11 gold badges91 silver badges159 bronze badges
asked Aug 25, 2016 at 7:03
2
  • 1
    Which version you have tried? Commented Aug 25, 2016 at 7:14
  • Magento version 2.0.0 Commented Aug 25, 2016 at 7:16

1 Answer 1

6

Add sequence tag inside module.xml

<sequence>
 <module name="Magento_Sales"/>
</sequence>

Create Vendor/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">
 <type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
 <arguments>
 <argument name="collections" xsi:type="array">
 <item name="sales_order_grid_data_source" xsi:type="string">Vendor\Module\Model\ResourceModel\Order\Grid\Collection</item>
 </argument>
 </arguments>
 </type>
 <virtualType name="Vendor\Module\Model\ResourceModel\Order\Grid\Collection">
 <arguments>
 <argument name="mainTable" xsi:type="string">sales_order_grid</argument>
 <argument name="resourceModel" xsi:type="string">Magento\Sales\Model\ResourceModel\Order</argument>
 </arguments>
 </virtualType>
</config>

Create Vendor/Module/Model/ResourceModel/Order/Grid/Collection.php

namespace Vendor\Module\Model\ResourceModel\Order\Grid;
use Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult;
class Collection extends SearchResult
{
 protected function _initSelect()
 {
 parent::_initSelect();
 $this->join(
 [$this->getTable('sales_order')],
 'main_table.entity_id = '.$this->getTable('sales_order').'.entity_id',
 array('quote_id')
 );
 return $this;
 }
}

Run following command and clear cache

php bin/magento setup:upgrade
answered Aug 25, 2016 at 9:10
10
  • Does it differ for Magento 2.1.x? Commented Aug 25, 2016 at 9:11
  • For M2.1 grid collection class already exist. So in that case you can do it using overwrite. Commented Aug 25, 2016 at 9:14
  • if you can provide information on how to add for 2.1 that would be helpful because I need it for both versions Commented Aug 25, 2016 at 9:16
  • good news is, it's also works with M2.1 Commented Aug 25, 2016 at 9:19
  • this answer is good, but without ui component config, for it check here magento.stackexchange.com/a/134890/23344 Commented Feb 26, 2018 at 9:50

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.