From 22a5890c4a26f7a953c57e2cf35f6139d5053346 Mon Sep 17 00:00:00 2001 From: konarshankar07 Date: Sat, 14 Dec 2019 20:15:22 +0530 Subject: [PATCH 1/3] Fixed grid rendered issue --- .../ResourceModel/Order/Grid/Collection.php | 7 ++ .../Component/DataProvider/Order/Document.php | 68 +++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 app/code/Magento/Sales/Ui/Component/DataProvider/Order/Document.php diff --git a/app/code/Magento/Sales/Model/ResourceModel/Order/Grid/Collection.php b/app/code/Magento/Sales/Model/ResourceModel/Order/Grid/Collection.php index 82c612c1a781d..c6f087f3b9e2c 100644 --- a/app/code/Magento/Sales/Model/ResourceModel/Order/Grid/Collection.php +++ b/app/code/Magento/Sales/Model/ResourceModel/Order/Grid/Collection.php @@ -8,6 +8,7 @@ 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\Sales\Ui\Component\DataProvider\Order\Document; use Psr\Log\LoggerInterface as Logger; /** @@ -15,6 +16,12 @@ */ class Collection extends \Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult { + + /** + * @inheritdoc + */ + protected $document = Document::class; + /** * Initialize dependencies. * diff --git a/app/code/Magento/Sales/Ui/Component/DataProvider/Order/Document.php b/app/code/Magento/Sales/Ui/Component/DataProvider/Order/Document.php new file mode 100644 index 0000000000000..ba1ddc7e3d8db --- /dev/null +++ b/app/code/Magento/Sales/Ui/Component/DataProvider/Order/Document.php @@ -0,0 +1,68 @@ +groupRepository = $groupRepository; + } + + /** + * @inheritdoc + */ + public function getCustomAttribute($attributeCode) + { + switch ($attributeCode) { + case self::$customerGroupAttributeCode: + $this->setCustomerGroupValue(); + break; + } + return parent::getCustomAttribute($attributeCode); + } + /** + * Update customer group value + * Method set group code instead id value + * @return void + */ + 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'); + } + } +} From e1653e41a90336c0652a0e3365aa3f3239db73d0 Mon Sep 17 00:00:00 2001 From: konarshankar07 Date: Sat, 14 Dec 2019 20:21:00 +0530 Subject: [PATCH 2/3] refactoring --- .../Sales/Ui/Component/DataProvider/Order/Document.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Sales/Ui/Component/DataProvider/Order/Document.php b/app/code/Magento/Sales/Ui/Component/DataProvider/Order/Document.php index ba1ddc7e3d8db..d1d9413883935 100644 --- a/app/code/Magento/Sales/Ui/Component/DataProvider/Order/Document.php +++ b/app/code/Magento/Sales/Ui/Component/DataProvider/Order/Document.php @@ -5,9 +5,9 @@ */ namespace Magento\Sales\Ui\Component\DataProvider\Order; -use Magento\Framework\Exception\NoSuchEntityException; use Magento\Customer\Api\GroupRepositoryInterface; use Magento\Framework\Api\AttributeValueFactory; +use Magento\Framework\Exception\NoSuchEntityException; /** * Class Document @@ -43,10 +43,8 @@ public function __construct( */ public function getCustomAttribute($attributeCode) { - switch ($attributeCode) { - case self::$customerGroupAttributeCode: - $this->setCustomerGroupValue(); - break; + if (self::$customerGroupAttributeCode === $attributeCode) { + $this->setCustomerGroupValue(); } return parent::getCustomAttribute($attributeCode); } From 44d330a5d355fec46c771263da0c637cf22c6415 Mon Sep 17 00:00:00 2001 From: konarshankar07 Date: Sun, 15 Dec 2019 11:37:22 +0530 Subject: [PATCH 3/3] Fixed static test --- .../Sales/Model/ResourceModel/Order/Grid/Collection.php | 2 ++ .../Sales/Ui/Component/DataProvider/Order/Document.php | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Sales/Model/ResourceModel/Order/Grid/Collection.php b/app/code/Magento/Sales/Model/ResourceModel/Order/Grid/Collection.php index c6f087f3b9e2c..9f274de129289 100644 --- a/app/code/Magento/Sales/Model/ResourceModel/Order/Grid/Collection.php +++ b/app/code/Magento/Sales/Model/ResourceModel/Order/Grid/Collection.php @@ -8,6 +8,7 @@ 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; @@ -31,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, diff --git a/app/code/Magento/Sales/Ui/Component/DataProvider/Order/Document.php b/app/code/Magento/Sales/Ui/Component/DataProvider/Order/Document.php index d1d9413883935..5d37c6bb3a32d 100644 --- a/app/code/Magento/Sales/Ui/Component/DataProvider/Order/Document.php +++ b/app/code/Magento/Sales/Ui/Component/DataProvider/Order/Document.php @@ -7,6 +7,7 @@ use Magento\Customer\Api\GroupRepositoryInterface; use Magento\Framework\Api\AttributeValueFactory; +use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Exception\NoSuchEntityException; /** @@ -27,6 +28,7 @@ class Document extends \Magento\Framework\View\Element\UiComponent\DataProvider\ /** * Document constructor. + * * @param AttributeValueFactory $attributeValueFactory * @param GroupRepositoryInterface $groupRepository */ @@ -40,6 +42,7 @@ public function __construct( /** * @inheritdoc + * @throws LocalizedException */ public function getCustomAttribute($attributeCode) { @@ -48,10 +51,12 @@ public function getCustomAttribute($attributeCode) } return parent::getCustomAttribute($attributeCode); } + /** - * Update customer group value * Method set group code instead id value + * * @return void + * @throws LocalizedException */ private function setCustomerGroupValue() {