Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ChangeCurrencyOnCustomWebsiteStep.php
Go to the documentation of this file.
1 <?php
7 
8 use Magento\ImportExport\Test\Fixture\ImportData;
9 use Magento\Mtf\Fixture\FixtureFactory;
10 use Magento\Mtf\TestStep\TestStepInterface;
11 
15 class ChangeCurrencyOnCustomWebsiteStep implements TestStepInterface
16 {
22  private $fixtureFactory;
23 
29  private $import;
30 
36  private $changeCurrency;
37 
43  public function __construct(
44  FixtureFactory $fixtureFactory,
45  ImportData $import,
46  $changeCurrency = false
47  ) {
48  $this->fixtureFactory = $fixtureFactory;
49  $this->import = $import;
50  $this->changeCurrency = $changeCurrency;
51  }
52 
58  public function run()
59  {
60  if ($this->changeCurrency === true) {
61  $currency = $this->import->getDataFieldConfig('import_file')['source']
62  ->getValue()['template']['websiteCurrency'];
63  $entities = $this->import->getDataFieldConfig('import_file')['source']->getEntities();
64  foreach ($entities as $entity) {
65  $websites = $entity->getDataFieldConfig('website_ids')['source']->getWebsites();
66  $configFixture = $this->fixtureFactory->createByCode(
67  'configData',
68  [
69  'data' => [
70  'currency/options/allow' => [
71  'value' => [$currency]
72  ],
73  'currency/options/base' => [
74  'value' => $currency
75  ],
76  'currency/options/default' => [
77  'value' => $currency
78  ],
79  'scope' => [
80  'fixture' => $websites[0],
81  'scope_type' => 'website',
82  'website_id' => $websites[0]->getWebsiteId(),
83  'set_level' => 'website',
84  ]
85  ]
86  ]
87  );
88  $configFixture->persist();
89  }
90  }
91  return ['import' => $this->import];
92  }
93 }
$entity
Definition: element.phtml:22
__construct(FixtureFactory $fixtureFactory, ImportData $import, $changeCurrency=false)