1

When I click Export Button

enter image description here

Vendor\Module\etc\adminhtml\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="Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Pool">
    <arguments>
        <argument name="modifiers" xsi:type="array">
            <item name="grid" xsi:type="array">
                <item name="class" xsi:type="string">Vendor\Module\Ui\DataProvider\Product\Modifier\RelatedOrderGrid</item>
                <item name="sortOrder" xsi:type="number">200</item>
            </item>
        </argument>
    </arguments>
</virtualType>
</config>

Vendor\Module\Ui\DataProvider\Product\Modifier\RelatedOrderGrid.php

<?php

namespace Vendor\Module\Ui\DataProvider\Product\Modifier;

use Magento\Catalog\Model\Locator\LocatorInterface;
use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier;
use Magento\Ui\Component\Form;
use Magento\Framework\UrlInterface;
use Magento\Framework\Module\Manager as ModuleManager;
use Magento\Framework\App\ObjectManager;

class RelatedOrderGrid extends AbstractModifier
{
const GROUP_REVIEW = 'order';
const GROUP_CONTENT = 'content';
const DATA_SCOPE_REVIEW = 'grouped';
const SORT_ORDER = 20;
const LINK_TYPE = 'associated';

protected $locator;

protected $urlBuilder;

private $moduleManager;

public function __construct(
    LocatorInterface $locator,
    UrlInterface $urlBuilder
) {
    $this->locator = $locator;
    $this->urlBuilder = $urlBuilder;
}

public function modifyMeta(array $meta)
{
    if (!$this->locator->getProduct()->getId() || !$this->getModuleManager()->isOutputEnabled('Magento_Review')) {
        return $meta;
    }

    $meta[static::GROUP_REVIEW] = [
        'children' => [
            'order_listing' => [
                'arguments' => [
                    'data' => [
                        'config' => [
                            'autoRender' => true,
                            'componentType' => 'insertListing',
                            'dataScope' => 'order_listing',
                            'externalProvider' => 'order_listing.order_listing_data_source',
                            'selectionsProvider' => 'order_listing.order_listing.product_columns.ids',
                            'ns' => 'order_listing',
                            'render_url' => $this->urlBuilder->getUrl('mui/index/render'),
                            'realTimeLink' => false,
                            'behaviourType' => 'simple',
                            'externalFilterMode' => true,
                            'imports' => [
                                'productId' => '${ $.provider }:data.product.current_product_id'
                            ],
                            'exports' => [
                                'productId' => '${ $.externalProvider }:params.current_product_id'
                            ],
                        ],
                    ],
                ],
            ],
        ],
        'arguments' => [
            'data' => [
                'config' => [
                    'label' => __('Order History'),
                    'collapsible' => true,
                    'opened' => false,
                    'componentType' => Form\Fieldset::NAME,
                    'sortOrder' =>
                        $this->getNextGroupSortOrder(
                            $meta,
                            static::GROUP_CONTENT,
                            static::SORT_ORDER
                        ),
                ],
            ],
        ],
    ];

    return $meta;
}

public function modifyData(array $data)
{
    $productId = $this->locator->getProduct()->getId();

    $data[$productId][self::DATA_SOURCE_DEFAULT]['current_product_id'] = $productId;

    return $data;
}

private function getModuleManager()
{
    if ($this->moduleManager === null) {
        $this->moduleManager = ObjectManager::getInstance()->get(ModuleManager::class);
    }
    return $this->moduleManager;
}
}

Vendor\Module\view\adminhtml\ui_component\order_listing.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">
<argument name="data" xsi:type="array">
    <item name="js_config" xsi:type="array">
        <item name="provider" xsi:type="string">order_listing.order_listing_data_source</item>
    </item>
</argument>
<settings>
    <spinner>order_columns</spinner>
    <deps>
        <dep>order_listing.order_listing_data_source</dep>
    </deps>
</settings>
<dataSource name="order_listing_data_source" component="Magento_Ui/js/grid/provider">
    <settings>
        <storageConfig>
            <param name="cacheRequests" xsi:type="boolean">false</param>
        </storageConfig>
        <updateUrl path="mui/index/render"/>
    </settings>
    <aclResource>Meetanshi_OrderHistory::orders_all</aclResource>
    <dataProvider class="Vendor\Module\Ui\DataProvider\Product\Modifier\RelatedOrderData" name="order_listing_data_source">
        <settings>
            <requestFieldName>entity_id</requestFieldName>
            <primaryFieldName>review_id</primaryFieldName>
        </settings>
    </dataProvider>
</dataSource>
<listingToolbar name="listing_top">
    <exportButton name="export_button"/>
    <filters name="listing_filters">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="params" xsi:type="array">
                    <item name="filters_modifier" xsi:type="array"/>
                </item>
            </item>
        </argument>
        <settings>
            <statefull>

            </statefull>
        </settings>
        <filterSelect name="store_id" provider="${ $.parentName }">
            <settings>
                <options class="Vendor\Module\Ui\Component\Listing\Column\Store\Options"/>
                <caption translate="true">Store Views</caption>
                <label translate="true">Purchased From</label>
                <dataScope>store_id</dataScope>
                <imports>
                    <link name="visible">ns = ${ $.ns }, componentType = column, index = ${ $.index }:visible</link>
                </imports>
            </settings>
        </filterSelect>
    </filters>
    <paging name="listing_paging"/>
</listingToolbar>
<columns name="order_columns">
    <selectionsColumn name="ids">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="resizeEnabled" xsi:type="boolean">false</item>
                <item name="resizeDefaultWidth" xsi:type="string">55</item>
                <item name="indexField" xsi:type="string">entity_id</item>
            </item>
        </argument>
    </selectionsColumn>
    <column name="increment_id" sortOrder="1">
        <settings>
            <filter>text</filter>
            <sorting>asc</sorting>
            <label translate="true">Order Id</label>
        </settings>
    </column>
    <column name="status" sortOrder="2" component="Magento_Ui/js/grid/columns/select">
        <settings>
            <filter>select</filter>
            <options class="Vendor\Module\Ui\Component\Listing\Column\Status\Options"/>
            <dataType>select</dataType>
            <sorting>asc</sorting>
            <label translate="true">Status</label>
        </settings>
    </column>
    <column name="store_id" sortOrder="3" class="Magento\Store\Ui\Component\Listing\Column\Store">
        <settings>
            <label translate="true">Store View</label>
            <bodyTmpl>ui/grid/cells/html</bodyTmpl>
            <sortable>false</sortable>
        </settings>
    </column>
    <column name="created_at" sortOrder="4" component="Magento_Ui/js/grid/columns/date">
        <settings>
            <filter>dateRange</filter>
            <label translate="true">Purchase Date</label>
            <sortable>false</sortable>
        </settings>
    </column>
    <column name="customer_firstname" sortOrder="5">
        <settings>
            <filter>text</filter>
            <label translate="true">Customer FirstName</label>
        </settings>
    </column>
    <column name="customer_lastname" sortOrder="6">
        <settings>
            <filter>text</filter>
            <label translate="true">Customer LastName</label>
        </settings>
    </column>
    <column name="customer_email" sortOrder="7">
        <settings>
            <filter>text</filter>
            <label translate="true">Customer Email</label>
        </settings>
    </column>
    <column name="original_price" sortOrder="8" class="Vendor\Module\Ui\Component\Listing\Columns\GrandTotal">
        <settings>
            <filter>textRange</filter>
            <label translate="true">Original Price</label>
        </settings>
    </column>
    <column name="subtotal" sortOrder="9" class="Vendor\Module\Ui\Component\Listing\Columns\GrandTotal">
        <settings>
            <filter>textRange</filter>
            <label translate="true">Order Price</label>
        </settings>
    </column>
    <column name="grand_total" sortOrder="10" class="Vendor\Module\Ui\Component\Listing\Columns\GrandTotal">
        <settings>
            <filter>textRange</filter>
            <label translate="true">Order Total</label>
        </settings>
    </column>
    <actionsColumn name="actions" class="Vendor\Module\Ui\Component\Listing\Columns\ReviewActions">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="viewUrlPath" xsi:type="string">sales/order/view</item>
                <item name="urlEntityParamName" xsi:type="string">order_id</item>
            </item>
        </argument>
        <settings>
            <indexField>order_id</indexField>
        </settings>
    </actionsColumn>
</columns>
</listing>

Vendor\Module\Ui\DataProvider\Product\Modifier\RelatedOrderData.php

<?php

namespace Vendor\Module\Ui\DataProvider\Product\Modifier;

use Magento\Framework\App\RequestInterface;
use Magento\Ui\DataProvider\AbstractDataProvider;
use Magento\Sales\Model\ResourceModel\Order\CollectionFactory;
use Magento\Review\Model\ResourceModel\Review\Product\Collection;
use Magento\Review\Model\Review;

class RelatedOrderData extends AbstractDataProvider
{

protected $collectionFactory;

protected $request;

public function __construct(
    $name,
    $primaryFieldName,
    $requestFieldName,
    CollectionFactory $collectionFactory,
    RequestInterface $request,
    array $meta = [],
    array $data = []
) {
    parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
    $this->collectionFactory = $collectionFactory;
    $this->collection = $this->collectionFactory->create();
    $this->request = $request;
}

public function getData()
{
    $productid = $this->request->getParam('current_product_id', 0);


    $this->collection->getSelect()
        ->joinLeft(
            'sales_order_item',
            'main_table.entity_id = sales_order_item.order_id'
        )->where('sales_order_item.product_id = '.$productid);

    $arrItems = [
        'totalRecords' => $this->collection->getSize(),
        'items' => [],
    ];

    foreach ($this->getCollection() as $item) {
        $arrItems['items'][] = $item->toArray([]);
    }

    return $arrItems;
}

}
1
  • Have you fixed this ? Commented Jun 1, 2022 at 7:07

0

Your Answer

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

Browse other questions tagged or ask your own question.