Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
GroupedProductDataProvider.php
Go to the documentation of this file.
1 <?php
7 
8 use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
15 
17 {
21  protected $request;
22 
26  protected $config;
27 
31  protected $storeRepository;
32 
49  public function __construct(
50  $name,
53  CollectionFactory $collectionFactory,
57  array $meta = [],
58  array $data = [],
59  array $addFieldStrategies = [],
60  array $addFilterStrategies = []
61  ) {
62  parent::__construct(
63  $name,
66  $collectionFactory,
69  $meta,
70  $data
71  );
72 
73  $this->request = $request;
74  $this->storeRepository = $storeRepository;
75  $this->config = $config;
76  }
77 
83  public function getData()
84  {
85  if (!$this->getCollection()->isLoaded()) {
86  $this->getCollection()->addAttributeToFilter(
87  'type_id',
88  $this->config->getComposableTypes()
89  );
90  if ($storeId = $this->request->getParam('current_store_id')) {
92  $store = $this->storeRepository->getById($storeId);
93  $this->getCollection()->setStore($store);
94  }
95  $this->getCollection()->load();
96  }
97  $items = $this->getCollection()->toArray();
98 
99  return [
100  'totalRecords' => $this->getCollection()->getSize(),
101  'items' => array_values($items),
102  ];
103  }
104 }
__construct( $name, $primaryFieldName, $requestFieldName, CollectionFactory $collectionFactory, RequestInterface $request, ConfigInterface $config, StoreRepositoryInterface $storeRepository, array $meta=[], array $data=[], array $addFieldStrategies=[], array $addFilterStrategies=[])
$items