/
AdvancedPricingTab.php
100 lines (91 loc) · 3.36 KB
/
AdvancedPricingTab.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Catalog\Test\Block\Adminhtml\Product\Edit;
use Magento\Mtf\Client\Element\SimpleElement;
/**
* Class AdvancedPricingTab
* Product advanced pricing tab
*/
class AdvancedPricingTab extends ProductTab
{
/**
* Class name 'Subform' of the main tab form
*
* @var array
*/
protected $childrenForm = [
'group_price' => 'AdvancedPricingTab\OptionGroup',
'tier_price' => 'AdvancedPricingTab\OptionTier',
];
/**
* Fill 'Advanced price' product form on tab
*
* @param array $fields
* @param SimpleElement|null $element
* @return $this
*/
public function fillFormTab(array $fields, SimpleElement $element = null)
{
$context = $element ? $element : $this->_rootElement;
foreach ($fields as $fieldName => $field) {
// Fill form
if (isset($this->childrenForm[$fieldName]) && is_array($field['value'])) {
/** @var \Magento\Catalog\Test\Block\Adminhtml\Product\Edit\Tab\Options\AbstractOptions $optionsForm */
$optionsForm = $this->blockFactory->create(
__NAMESPACE__ . '\\' . $this->childrenForm[$fieldName],
['element' => $context]
);
foreach ($field['value'] as $key => $option) {
++$key;
$optionsForm->fillOptions(
$option,
$context->find(
'#attribute-' . $fieldName . '-container tbody tr:nth-child(' . $key . ')'
)
);
}
} elseif (!empty($field['value'])) {
$data = $this->dataMapping([$fieldName => $field]);
$this->_fill($data, $this->_rootElement);
}
}
return $this;
}
/**
* Get data of tab
*
* @param array|null $fields
* @param SimpleElement|null $element
* @return array
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function getDataFormTab($fields = null, SimpleElement $element = null)
{
$formData = [];
foreach ($fields as $fieldName => $field) {
// Data collection forms
if (isset($this->childrenForm[$fieldName]) && is_array($field['value'])) {
/** @var \Magento\Catalog\Test\Block\Adminhtml\Product\Edit\Tab\Options\AbstractOptions $optionsForm */
$optionsForm = $this->blockFactory->create(
__NAMESPACE__ . '\\' . $this->childrenForm[$fieldName],
['element' => $this->_rootElement]
);
foreach ($field['value'] as $key => $option) {
$formData[$fieldName][$key++] = $optionsForm->getDataOptions(
$option,
$this->_rootElement->find(
'#attribute-' . $fieldName . '-container tbody tr:nth-child(' . $key . ')'
)
);
}
} elseif (!empty($field['value'])) {
$data = $this->dataMapping([$fieldName => $field]);
$formData += $this->_getData($data, $this->_rootElement);
}
}
return $formData;
}
}