Skip to content

Fix issue #13944. Show Store Views in Terms and Conditions grid. #14546

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

Merged
merged 1 commit into from
Apr 24, 2018
Merged
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 @@ -5,27 +5,42 @@
*/
namespace Magento\CheckoutAgreements\Block\Adminhtml\Agreement;

use Magento\Framework\App\ObjectManager;
use Magento\CheckoutAgreements\Model\ResourceModel\Agreement\Grid\CollectionFactory as GridCollectionFactory;

class Grid extends \Magento\Backend\Block\Widget\Grid\Extended
{
/**
* @var \Magento\CheckoutAgreements\Model\ResourceModel\Agreement\CollectionFactory
* @deprecated
*/
protected $_collectionFactory;

/**
* @param GridCollectionFactory
*/
private $gridCollectionFactory;

/**
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\Backend\Helper\Data $backendHelper
* @param \Magento\CheckoutAgreements\Model\ResourceModel\Agreement\CollectionFactory $collectionFactory
* @param array $data
* @param GridCollectionFactory $gridColFactory
* @codeCoverageIgnore
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Backend\Helper\Data $backendHelper,
\Magento\CheckoutAgreements\Model\ResourceModel\Agreement\CollectionFactory $collectionFactory,

This comment was marked as resolved.

Copy link
Contributor

Choose a reason for hiding this comment

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

You may leave it as is

array $data = []
array $data = [],
GridCollectionFactory $gridColFactory = null
) {

$this->_collectionFactory = $collectionFactory;
$this->gridCollectionFactory = $gridColFactory
? : ObjectManager::getInstance()->get(GridCollectionFactory::class);

parent::__construct($context, $backendHelper, $data);
}

Expand All @@ -47,7 +62,7 @@ protected function _construct()
*/
protected function _prepareCollection()
{
$this->setCollection($this->_collectionFactory->create());
$this->setCollection($this->gridCollectionFactory->create());
return parent::_prepareCollection();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\CheckoutAgreements\Model\ResourceModel\Agreement\Grid;

/**
* CheckoutAgreement Grid Collection
*/
class Collection extends \Magento\CheckoutAgreements\Model\ResourceModel\Agreement\Collection
{

/**
* {@inheritdoc}
*/
public function load($printQuery = false, $logQuery = false)
{
if ($this->isLoaded()) {
return $this;
}

parent::load($printQuery, $logQuery);

$this->addStoresToResult();

return $this;
}

/**
* @return void
*/
private function addStoresToResult()
{
$stores = $this->getStoresForAgreements();

if (!empty($stores)) {
$storesByAgreementId = [];

foreach ($stores as $storeData) {
$storesByAgreementId[$storeData['agreement_id']][] = $storeData['store_id'];
}

foreach ($this as $item) {
$agreementId = $item->getData('agreement_id');

if (!isset($storesByAgreementId[$agreementId])) {
continue;
}

$item->setData('stores', $storesByAgreementId[$agreementId]);
}
}
}

/**
* @return array
*/
private function getStoresForAgreements()
{
$agreementId = $this->getColumnValues('agreement_id');

if (!empty($agreementId)) {
$select = $this->getConnection()->select()->from(
['agreement_store' => 'checkout_agreement_store']
)->where(
'agreement_store.agreement_id IN (?)',
$agreementId
);

return $this->getConnection()->fetchAll($select);
}

return [];
}
}