Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
WebsiteIds.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Mtf\Fixture\DataSource;
10 use Magento\Mtf\Fixture\FixtureFactory;
12 
16 class WebsiteIds extends DataSource
17 {
23  private $stores = [];
24 
30  private $websites = [];
31 
37  private $fixtureFactory;
38 
44  private $fixtureData = null;
45 
52  public function __construct(
53  FixtureFactory $fixtureFactory,
54  array $params,
55  $data = []
56  ) {
57  $this->fixtureFactory = $fixtureFactory;
58  $this->params = $params;
59  $this->fixtureData = $data;
60  }
61 
69  public function getData($key = null)
70  {
71  if (empty($this->fixtureData)) {
72  throw new \Exception("Data must be set");
73  }
74 
75  foreach ($this->fixtureData as $dataset) {
76  if (is_array($dataset) && isset($dataset['websites'])) {
77  foreach ($dataset['websites'] as $website) {
78  $this->websites[] = $website;
79  }
80  } else {
81  $this->createStore($dataset);
82  }
83  }
84 
85  return parent::getData($key);
86  }
87 
94  private function createStore($dataset)
95  {
96  if ($dataset instanceof Store) {
97  $store = $dataset;
98  } elseif (is_array($dataset)) {
99  $store = isset($dataset['store']) ? $dataset['store'] :
100  (isset($dataset['dataset']) ? $this->fixtureFactory->createByCode('store', $dataset) : null);
101  }
102  if (isset($store)) {
103  $this->setWebsiteStoreData($store);
104  }
105  }
106 
113  private function setWebsiteStoreData(Store $store)
114  {
115  if (!$store->getStoreId()) {
116  $store->persist();
117  }
118  $website = $store->getDataFieldConfig('group_id')['source']
119  ->getStoreGroup()->getDataFieldConfig('website_id')['source']->getWebsite();
120  $this->data[] = $website->getName();
121  $this->websites[] = $website;
122  $this->stores[] = $store;
123  }
124 
130  public function getStores()
131  {
132  return $this->stores;
133  }
134 
140  public function getWebsites()
141  {
142  return $this->websites;
143  }
144 }
__construct(FixtureFactory $fixtureFactory, array $params, $data=[])
Definition: WebsiteIds.php:52
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18