Skip to content

Grid export issue task 25963 #26046

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,21 @@
use Magento\Framework\Data\Collection\Db\FetchStrategyInterface as FetchStrategy;
use Magento\Framework\Data\Collection\EntityFactoryInterface as EntityFactory;
use Magento\Framework\Event\ManagerInterface as EventManager;
use Magento\Framework\Exception\LocalizedException;
use Magento\Sales\Ui\Component\DataProvider\Order\Document;
use Psr\Log\LoggerInterface as Logger;

/**
* Order grid collection
*/
class Collection extends \Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult
{

/**
* @inheritdoc
*/
protected $document = Document::class;

/**
* Initialize dependencies.
*
Expand All @@ -24,6 +32,7 @@ class Collection extends \Magento\Framework\View\Element\UiComponent\DataProvide
* @param EventManager $eventManager
* @param string $mainTable
* @param string $resourceModel
* @throws LocalizedException
*/
public function __construct(
EntityFactory $entityFactory,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Sales\Ui\Component\DataProvider\Order;

use Magento\Customer\Api\GroupRepositoryInterface;
use Magento\Framework\Api\AttributeValueFactory;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;

/**
* Class Document
*/
class Document extends \Magento\Framework\View\Element\UiComponent\DataProvider\Document
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import class with alias.

{

/**
* @var string
*/
private static $customerGroupAttributeCode = 'customer_group';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use private const CUSTOMER_GROUP_ATTRIBUTE_CODE instead.


/**
* @var GroupRepositoryInterface
*/
private $groupRepository;

/**
* Document constructor.
*
* @param AttributeValueFactory $attributeValueFactory
* @param GroupRepositoryInterface $groupRepository
*/
public function __construct(
AttributeValueFactory $attributeValueFactory,
GroupRepositoryInterface $groupRepository
) {
parent::__construct($attributeValueFactory);
$this->groupRepository = $groupRepository;
}

/**
* @inheritdoc
* @throws LocalizedException
*/
public function getCustomAttribute($attributeCode)
{
if (self::$customerGroupAttributeCode === $attributeCode) {
$this->setCustomerGroupValue();
}
return parent::getCustomAttribute($attributeCode);
}

/**
* Method set group code instead id value
*
* @return void
* @throws LocalizedException
*/
private function setCustomerGroupValue()
{
$value = $this->getData(self::$customerGroupAttributeCode);
try {
$group = $this->groupRepository->getById($value);
$this->setCustomAttribute(self::$customerGroupAttributeCode, $group->getCode());
} catch (NoSuchEntityException $e) {
$this->setCustomAttribute(self::$customerGroupAttributeCode, 'N/A');
}
}
}