1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright © Getnet. All rights reserved. |
4
|
|
|
* |
5
|
|
|
* @author Bruno Elisei <[email protected]> |
6
|
|
|
* See LICENSE for license details. |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Getnet\SplitExampleMagento\Block\Adminhtml\System\Form\Field; |
10
|
|
|
|
11
|
|
|
use Getnet\SplitExampleMagento\Block\Adminhtml\System\Form\Field\Column\CalculationTypeColumn; |
12
|
|
|
use Getnet\SplitExampleMagento\Block\Adminhtml\System\Form\Field\Column\SubSellerIdColumn; |
13
|
|
|
use Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray; |
14
|
|
|
use Magento\Framework\DataObject; |
15
|
|
|
use Magento\Framework\Exception\LocalizedException; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class SplitCommision - Add List Commision to field. |
19
|
|
|
*/ |
20
|
|
|
class SplitCommision extends AbstractFieldArray |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var SubSellerIdColumn |
24
|
|
|
*/ |
25
|
|
|
protected $subSellerIdRenderer; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var CalculationTypeColumn |
29
|
|
|
*/ |
30
|
|
|
protected $calculationTypeRenderer; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Prepare rendering the new field by adding all the needed columns. |
34
|
|
|
*/ |
35
|
|
|
protected function _prepareToRender() |
36
|
|
|
{ |
37
|
|
|
$this->addColumn('sub_seller_id', [ |
38
|
|
|
'label' => __('Sub Seller'), |
39
|
|
|
'renderer' => $this->getFieldSubSellerIdRenderer(), |
40
|
|
|
]); |
41
|
|
|
|
42
|
|
|
$this->addColumn('commission_percentage', [ |
43
|
|
|
'label' => __('Percentage he receives'), |
44
|
|
|
'class' => 'required-entry admin__control-text', |
45
|
|
|
]); |
46
|
|
|
|
47
|
|
|
$this->addColumn('include_freight', [ |
48
|
|
|
'label' => __('Receiving Freight'), |
49
|
|
|
'renderer' => $this->getFieldCalculationTypeRenderer(), |
50
|
|
|
'class' => 'required-entry', |
51
|
|
|
]); |
52
|
|
|
|
53
|
|
|
$this->addColumn('include_interest', [ |
54
|
|
|
'label' => __('Receiving Interest'), |
55
|
|
|
'renderer' => $this->getFieldCalculationTypeRenderer(), |
56
|
|
|
'class' => 'required-entry', |
57
|
|
|
]); |
58
|
|
|
|
59
|
|
|
$this->_addAfter = false; |
60
|
|
|
$this->_addButtonLabel = __('Add'); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Prepare existing row data object. |
65
|
|
|
* |
66
|
|
|
* @param DataObject $row |
67
|
|
|
* |
68
|
|
|
* @throws LocalizedException |
69
|
|
|
*/ |
70
|
|
|
protected function _prepareArrayRow(DataObject $row): void |
71
|
|
|
{ |
72
|
|
|
$options = []; |
73
|
|
|
|
74
|
|
|
$field = $row->getField(); |
75
|
|
|
if ($field !== null) { |
76
|
|
|
$options[ |
77
|
|
|
'option_'.$this->getFieldSubSellerIdRenderer()->calcOptionHash($field) |
78
|
|
|
] = 'selected="selected"'; |
79
|
|
|
$options[ |
80
|
|
|
'option_'.$this->getFieldCalculationTypeRenderer()->calcOptionHash($field) |
81
|
|
|
] = 'selected="selected"'; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
$row->setData('option_extra_attrs', $options); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Create Block Sub Seller Id Renderer. |
89
|
|
|
* |
90
|
|
|
* @throws LocalizedException |
91
|
|
|
* |
92
|
|
|
* @return SubSellerIdColumn |
93
|
|
|
*/ |
94
|
|
|
private function getFieldSubSellerIdRenderer() |
95
|
|
|
{ |
96
|
|
|
if (!$this->subSellerIdRenderer) { |
97
|
|
|
$this->subSellerIdRenderer = $this->getLayout()->createBlock( |
98
|
|
|
SubSellerIdColumn::class, |
99
|
|
|
'', |
100
|
|
|
['data' => ['is_render_to_js_template' => true]] |
101
|
|
|
); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
return $this->subSellerIdRenderer; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Create Block Calculation Type Renderer. |
109
|
|
|
* |
110
|
|
|
* @throws LocalizedException |
111
|
|
|
* |
112
|
|
|
* @return CalculationTypeColumn |
113
|
|
|
*/ |
114
|
|
|
private function getFieldCalculationTypeRenderer() |
115
|
|
|
{ |
116
|
|
|
if (!$this->calculationTypeRenderer) { |
117
|
|
|
$this->calculationTypeRenderer = $this->getLayout()->createBlock( |
118
|
|
|
CalculationTypeColumn::class, |
119
|
|
|
'', |
120
|
|
|
['data' => ['is_render_to_js_template' => true]] |
121
|
|
|
); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
return $this->calculationTypeRenderer; |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|