Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AbstractConfigureBlock.php
Go to the documentation of this file.
1 <?php
8 
11 use Magento\Mtf\Block\Form;
12 use Magento\Mtf\Fixture\FixtureInterface;
13 use Magento\Mtf\Fixture\InjectableFixture;
14 
19 abstract class AbstractConfigureBlock extends Form
20 {
27 
33  public function getCustomOptionsBlock()
34  {
35  return $this->blockFactory->create(
36  \Magento\Catalog\Test\Block\Product\View\CustomOptions::class,
37  ['element' => $this->_rootElement->find($this->customOptionsSelector)]
38  );
39  }
40 
49  public function fillOptions(FixtureInterface $product)
50  {
51  $dataConfig = $product->getDataConfig();
52  $typeId = isset($dataConfig['type_id']) ? $dataConfig['type_id'] : null;
53  $checkoutData = null;
54 
56  if ($this->hasRender($typeId)) {
57  $this->callRender($typeId, 'fillOptions', ['product' => $product]);
58  }
59 
61  $checkoutData = $product->getCheckoutData();
62  $checkoutCustomOptions = isset($checkoutData['options']['custom_options'])
63  ? $checkoutData['options']['custom_options']
64  : [];
65  $customOptions = $product->hasData('custom_options')
66  ? $product->getDataFieldConfig('custom_options')['source']->getCustomOptions()
67  : [];
68 
69  $checkoutCustomOptions = $this->prepareCheckoutData($customOptions, $checkoutCustomOptions);
70  $this->getCustomOptionsBlock()->fillCustomOptions($checkoutCustomOptions);
71  }
72 
79  abstract public function setQty($qty);
80 
88  protected function prepareCheckoutData(array $options, array $checkoutData)
89  {
90  $result = [];
91 
92  foreach ($checkoutData as $checkoutOption) {
93  $attribute = str_replace('attribute_key_', '', $checkoutOption['title']);
94  $option = str_replace('option_key_', '', $checkoutOption['value']);
95 
96  if (isset($options[$attribute])) {
97  $result[] = [
98  'type' => $options[$attribute]['type'],
99  'title' => isset($options[$attribute]['title'])
100  ? $options[$attribute]['title']
101  : $attribute,
102  'value' => isset($options[$attribute]['options'][$option]['title'])
103  ? $options[$attribute]['options'][$option]['title']
104  : $option,
105  ];
106  }
107  }
108 
109  return $result;
110  }
111 }
prepareCheckoutData(array $options, array $checkoutData)