Skip to content

Commit 9000f74

Browse files
afirlejczykrostyslav-hymon
authored andcommitted
Fix issue #13944. Show Store Views in Terms and Conditions grid.
1 parent 18a7e29 commit 9000f74

File tree

2 files changed

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

2 files changed

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

0 commit comments

Comments
 (0)