Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
BundleSelections.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Mtf\Fixture\DataSource;
10 use Magento\Mtf\Fixture\FixtureFactory;
11 use Magento\Mtf\Fixture\FixtureInterface;
12 use Magento\Mtf\Repository\RepositoryFactory;
13 
17 class BundleSelections extends DataSource
18 {
24  protected $repositoryFactory;
25 
31  protected $fixtureFactory;
32 
40  public function __construct(
41  RepositoryFactory $repositoryFactory,
42  FixtureFactory $fixtureFactory,
43  array $data,
44  array $params = []
45  ) {
46  $this->repositoryFactory = $repositoryFactory;
47  $this->fixtureFactory = $fixtureFactory;
48  $this->params = $params;
49  $this->data = !isset($data['dataset']) ? $data : [];
50  $this->getDataset($data);
51  $this->prepareProducts();
52  }
53 
60  protected function getDataset(array $data)
61  {
62  if (isset($data['dataset']) && isset($this->params['repository'])) {
63  $this->data = $this->repositoryFactory->get($this->params['repository'])->get($data['dataset']);
64  if (!empty($data['products'])) {
65  $this->data['products'] = [];
66  $this->data['products'] = explode('|', $data['products']);
67  foreach ($this->data['products'] as $key => $products) {
68  $this->data['products'][$key] = explode(',', $products);
69  }
70  }
71  }
72  }
73 
79  protected function prepareProducts()
80  {
81  if (!empty($this->data['products'])) {
82  $productsSelections = $this->data['products'];
83  $this->data['products'] = [];
84  foreach ($productsSelections as $index => $products) {
85  $productSelection = [];
86  foreach ($products as $key => $product) {
87  if ($product instanceof FixtureInterface) {
88  $productSelection[$key] = $product;
89  continue;
90  }
91  list($fixture, $dataset) = explode('::', $product);
92  $productSelection[$key] = $this->fixtureFactory->createByCode($fixture, ['dataset' => $dataset]);
93  $productSelection[$key]->persist();
94  $this->data['bundle_options'][$index]['assigned_products'][$key]['search_data']['name'] =
95  $productSelection[$key]->getName();
96  }
97  $this->data['products'][] = $productSelection;
98  }
99  }
100  }
101 
107  public function getProducts()
108  {
109  return $this->data['products'];
110  }
111 }
__construct(RepositoryFactory $repositoryFactory, FixtureFactory $fixtureFactory, array $data, array $params=[])
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18
$index
Definition: list.phtml:44