Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CollectionProvider.php
Go to the documentation of this file.
1 <?php
8 
11 
13 {
17  protected $providers;
18 
22  protected $converterPool;
23 
28  public function __construct(ConverterPool $converterPool, array $providers = [])
29  {
30  $this->converterPool = $converterPool;
31  $this->providers = $providers;
32  }
33 
42  public function getCollection(\Magento\Catalog\Model\Product $product, $type)
43  {
44  if (!isset($this->providers[$type])) {
45  throw new NoSuchEntityException(__("The collection provider isn't registered."));
46  }
47 
48  $products = $this->providers[$type]->getLinkedProducts($product);
49  $converter = $this->converterPool->getConverter($type);
50  $output = [];
51  $sorterItems = [];
52  foreach ($products as $item) {
53  $output[$item->getId()] = $converter->convert($item);
54  }
55 
56  foreach ($output as $item) {
57  $itemPosition = $item['position'];
58  if (!isset($sorterItems[$itemPosition])) {
59  $sorterItems[$itemPosition] = $item;
60  } else {
61  $newPosition = $itemPosition + 1;
62  $sorterItems[$newPosition] = $item;
63  }
64  }
65  ksort($sorterItems);
66  return $sorterItems;
67  }
68 }
__()
Definition: __.php:13
$type
Definition: item.phtml:13