Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CategoryProducts.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Mtf\Fixture\DataSource;
10 use Magento\Mtf\Fixture\FixtureFactory;
11 
15 class CategoryProducts extends DataSource
16 {
22  protected $products = [];
23 
30  public function __construct(FixtureFactory $fixtureFactory, array $params, $data = [])
31  {
32  $this->params = $params;
33  if (!empty($data['dataset']) && $data['dataset'] !== '-') {
34  $dataset = array_map('trim', explode(',', $data['dataset']));
35  foreach ($dataset as $value) {
36  list($fixtureCode, $dataset) = explode('::', $value);
37  $this->products[] = $fixtureFactory->createByCode($fixtureCode, ['dataset' => $dataset]);
38  }
39  }
40  if (isset($data['products'])) {
41  foreach ($data['products'] as $product) {
42  $this->products[] = $product;
43  }
44  }
45  foreach ($this->products as $product) {
46  if (!$product->hasData('id')) {
47  $product->persist();
48  }
49  $this->data[] = $product->getName();
50  }
51  }
52 
58  public function getProducts()
59  {
60  return $this->products;
61  }
62 }
$value
Definition: gender.phtml:16
__construct(FixtureFactory $fixtureFactory, array $params, $data=[])
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18