1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\GroupedProduct\Ui\DataProvider\Product;
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
use Magento\Catalog\Ui\DataProvider\Product\ProductDataProvider;
use Magento\GroupedProduct\Model\Product\Type\Grouped as GroupedProductType;
use Magento\Catalog\Model\ProductTypes\ConfigInterface;
use Magento\Framework\App\RequestInterface;
use Magento\Store\Api\Data\StoreInterface;
use Magento\Store\Api\StoreRepositoryInterface;
class GroupedProductDataProvider extends ProductDataProvider
{
/**
* @var RequestInterface
*/
protected $request;
/**
* @var ConfigInterface
*/
protected $config;
/**
* @var StoreRepositoryInterface
*/
protected $storeRepository;
/**
* Construct
*
* @param string $name
* @param string $primaryFieldName
* @param string $requestFieldName
* @param CollectionFactory $collectionFactory
* @param RequestInterface $request
* @param StoreRepositoryInterface $storeRepository
* @param ConfigInterface $config
* @param \Magento\Ui\DataProvider\AddFieldToCollectionInterface[] $addFieldStrategies
* @param \Magento\Ui\DataProvider\AddFilterToCollectionInterface[] $addFilterStrategies
* @param array $meta
* @param array $data
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
$name,
$primaryFieldName,
$requestFieldName,
CollectionFactory $collectionFactory,
RequestInterface $request,
ConfigInterface $config,
StoreRepositoryInterface $storeRepository,
array $meta = [],
array $data = [],
array $addFieldStrategies = [],
array $addFilterStrategies = []
) {
parent::__construct(
$name,
$primaryFieldName,
$requestFieldName,
$collectionFactory,
$addFieldStrategies,
$addFilterStrategies,
$meta,
$data
);
$this->request = $request;
$this->storeRepository = $storeRepository;
$this->config = $config;
}
/**
* Get data
*
* @return array
*/
public function getData()
{
if (!$this->getCollection()->isLoaded()) {
$this->getCollection()->addAttributeToFilter(
'type_id',
$this->config->getComposableTypes()
);
if ($storeId = $this->request->getParam('current_store_id')) {
/** @var StoreInterface $store */
$store = $this->storeRepository->getById($storeId);
$this->getCollection()->setStore($store);
}
$this->getCollection()->load();
}
$items = $this->getCollection()->toArray();
return [
'totalRecords' => $this->getCollection()->getSize(),
'items' => array_values($items),
];
}
}