Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CustomerGroupDimensionProvider.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
10 use Magento\Customer\Model\ResourceModel\Group\CollectionFactory as CustomerGroupCollectionFactory;
13 
15 {
20  const DIMENSION_NAME = 'cg';
21 
25  private $collectionFactory;
26 
30  private $customerGroupsDataIterator;
31 
35  private $dimensionFactory;
36 
37  public function __construct(CustomerGroupCollectionFactory $collectionFactory, DimensionFactory $dimensionFactory)
38  {
39  $this->dimensionFactory = $dimensionFactory;
40  $this->collectionFactory = $collectionFactory;
41  }
42 
43  public function getIterator(): \Traversable
44  {
45  foreach ($this->getCustomerGroups() as $customerGroup) {
46  yield $this->dimensionFactory->create(self::DIMENSION_NAME, (string)$customerGroup);
47  }
48  }
49 
53  private function getCustomerGroups(): array
54  {
55  if ($this->customerGroupsDataIterator === null) {
56  $customerGroups = $this->collectionFactory->create()->getAllIds();
57  $this->customerGroupsDataIterator = is_array($customerGroups) ? $customerGroups : [];
58  }
59 
60  return $this->customerGroupsDataIterator;
61  }
62 }
__construct(CustomerGroupCollectionFactory $collectionFactory, DimensionFactory $dimensionFactory)