Skip to content

Commit aefde2d

Browse files
author
Stanislav Idolov
authored
ENGCOM-1397: [Forwardport] Fix issue #13944. Show Store Views in Terms and Conditions grid. #14868
2 parents dec5266 + 578c251 commit aefde2d

File tree

2 files changed

+95
-2
lines changed
  • app/code/Magento/CheckoutAgreements

2 files changed

+95
-2
lines changed

app/code/Magento/CheckoutAgreements/Block/Adminhtml/Agreement/Grid.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,42 @@
55
*/
66
namespace Magento\CheckoutAgreements\Block\Adminhtml\Agreement;
77

8+
use Magento\Framework\App\ObjectManager;
9+
use Magento\CheckoutAgreements\Model\ResourceModel\Agreement\Grid\CollectionFactory as GridCollectionFactory;
10+
811
class Grid extends \Magento\Backend\Block\Widget\Grid\Extended
912
{
1013
/**
1114
* @var \Magento\CheckoutAgreements\Model\ResourceModel\Agreement\CollectionFactory
15+
* @deprecated
1216
*/
1317
protected $_collectionFactory;
1418

19+
/**
20+
* @param GridCollectionFactory
21+
*/
22+
private $gridCollectionFactory;
23+
1524
/**
1625
* @param \Magento\Backend\Block\Template\Context $context
1726
* @param \Magento\Backend\Helper\Data $backendHelper
1827
* @param \Magento\CheckoutAgreements\Model\ResourceModel\Agreement\CollectionFactory $collectionFactory
1928
* @param array $data
29+
* @param GridCollectionFactory $gridColFactory
2030
* @codeCoverageIgnore
2131
*/
2232
public function __construct(
2333
\Magento\Backend\Block\Template\Context $context,
2434
\Magento\Backend\Helper\Data $backendHelper,
2535
\Magento\CheckoutAgreements\Model\ResourceModel\Agreement\CollectionFactory $collectionFactory,
26-
array $data = []
36+
array $data = [],
37+
GridCollectionFactory $gridColFactory = null
2738
) {
39+
2840
$this->_collectionFactory = $collectionFactory;
41+
$this->gridCollectionFactory = $gridColFactory
42+
? : ObjectManager::getInstance()->get(GridCollectionFactory::class);
43+
2944
parent::__construct($context, $backendHelper, $data);
3045
}
3146

@@ -47,7 +62,7 @@ protected function _construct()
4762
*/
4863
protected function _prepareCollection()
4964
{
50-
$this->setCollection($this->_collectionFactory->create());
65+
$this->setCollection($this->gridCollectionFactory->create());
5166
return parent::_prepareCollection();
5267
}
5368

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\CheckoutAgreements\Model\ResourceModel\Agreement\Grid;
9+
10+
/**
11+
* CheckoutAgreement Grid Collection
12+
*/
13+
class Collection extends \Magento\CheckoutAgreements\Model\ResourceModel\Agreement\Collection
14+
{
15+
16+
/**
17+
* {@inheritdoc}
18+
*/
19+
public function load($printQuery = false, $logQuery = false)
20+
{
21+
if ($this->isLoaded()) {
22+
return $this;
23+
}
24+
25+
parent::load($printQuery, $logQuery);
26+
27+
$this->addStoresToResult();
28+
29+
return $this;
30+
}
31+
32+
/**
33+
* @return void
34+
*/
35+
private function addStoresToResult()
36+
{
37+
$stores = $this->getStoresForAgreements();
38+
39+
if (!empty($stores)) {
40+
$storesByAgreementId = [];
41+
42+
foreach ($stores as $storeData) {
43+
$storesByAgreementId[$storeData['agreement_id']][] = $storeData['store_id'];
44+
}
45+
46+
foreach ($this as $item) {
47+
$agreementId = $item->getData('agreement_id');
48+
49+
if (!isset($storesByAgreementId[$agreementId])) {
50+
continue;
51+
}
52+
53+
$item->setData('stores', $storesByAgreementId[$agreementId]);
54+
}
55+
}
56+
}
57+
58+
/**
59+
* @return array
60+
*/
61+
private function getStoresForAgreements()
62+
{
63+
$agreementId = $this->getColumnValues('agreement_id');
64+
65+
if (!empty($agreementId)) {
66+
$select = $this->getConnection()->select()->from(
67+
['agreement_store' => 'checkout_agreement_store']
68+
)->where(
69+
'agreement_store.agreement_id IN (?)',
70+
$agreementId
71+
);
72+
73+
return $this->getConnection()->fetchAll($select);
74+
}
75+
76+
return [];
77+
}
78+
}

0 commit comments

Comments
 (0)