Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CustomerGroupsFixture.php
Go to the documentation of this file.
1 <?php
7 namespace Magento\Setup\Fixtures;
8 
9 use Magento\Customer\Api\Data\GroupInterfaceFactory;
11 use Magento\Customer\Model\ResourceModel\Group\CollectionFactory;
12 
17 {
19 
23  protected $priority = 60;
24 
28  private $groupCollectionFactory;
29 
33  private $groupRepository;
34 
38  private $groupFactory;
39 
43  public function __construct(
45  CollectionFactory $groupCollectionFactory,
46  GroupRepositoryInterface $groupRepository,
47  GroupInterfaceFactory $groupFactory
48  ) {
49  parent::__construct($fixtureModel);
50  $this->groupCollectionFactory = $groupCollectionFactory;
51  $this->groupRepository = $groupRepository;
52  $this->groupFactory = $groupFactory;
53  }
54 
58  public function execute()
59  {
60  $existingCustomerGroupsCount = $this->groupCollectionFactory->create()->getSize();
61  $customerGroupsCount = $this->fixtureModel->getValue('customer_groups', 0);
62  if ($customerGroupsCount < 1) {
63  return;
64  }
65 
66  for ($i = $existingCustomerGroupsCount; $i < $customerGroupsCount; ++$i) {
67  $groupDataObject = $this->groupFactory->create();
69  ->setCode('customer_group_' . $i)
70  ->setTaxClassId(self::DEFAULT_TAX_CLASS_ID);
71  $this->groupRepository->save($groupDataObject);
72  }
73  }
74 
78  public function getActionTitle()
79  {
80  return 'Generating customer groups';
81  }
82 
86  public function introduceParamLabels()
87  {
88  return [
89  'customer_groups' => 'Customer groups'
90  ];
91  }
92 }
$groupRepository
$groupDataObject
$groupFactory
__construct(FixtureModel $fixtureModel, CollectionFactory $groupCollectionFactory, GroupRepositoryInterface $groupRepository, GroupInterfaceFactory $groupFactory)
$i
Definition: gallery.phtml:31