|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* PAYONE Magento 2 Connector is free software: you can redistribute it and/or modify |
|
5
|
|
|
* it under the terms of the GNU Lesser General Public License as published by |
|
6
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
|
7
|
|
|
* (at your option) any later version. |
|
8
|
|
|
* |
|
9
|
|
|
* PAYONE Magento 2 Connector is distributed in the hope that it will be useful, |
|
10
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12
|
|
|
* GNU Lesser General Public License for more details. |
|
13
|
|
|
* |
|
14
|
|
|
* You should have received a copy of the GNU Lesser General Public License |
|
15
|
|
|
* along with PAYONE Magento 2 Connector. If not, see <http://www.gnu.org/licenses/>. |
|
16
|
|
|
* |
|
17
|
|
|
* PHP version 5 |
|
18
|
|
|
* |
|
19
|
|
|
* @category Payone |
|
20
|
|
|
* @package Payone_Magento2_Plugin |
|
21
|
|
|
* @author FATCHIP GmbH <[email protected]> |
|
22
|
|
|
* @copyright 2003 - 2016 Payone GmbH |
|
23
|
|
|
* @license <http://www.gnu.org/licenses/> GNU Lesser General Public License |
|
24
|
|
|
* @link http://www.payone.de |
|
25
|
|
|
*/ |
|
26
|
|
|
|
|
27
|
|
|
namespace Payone\Core\Block\Adminhtml\Config\Form\Field; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Block class for status-mapping grid-element |
|
31
|
|
|
*/ |
|
32
|
|
|
class StatusMapping extends \Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray |
|
33
|
|
|
{ |
|
34
|
|
|
/** |
|
35
|
|
|
* Element factory |
|
36
|
|
|
* |
|
37
|
|
|
* @var \Magento\Framework\Data\Form\Element\Factory |
|
38
|
|
|
*/ |
|
39
|
|
|
protected $elementFactory; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* List of all possible OrderStatus types |
|
43
|
|
|
* |
|
44
|
|
|
* @var \Magento\Sales\Model\Config\Source\Order\Status |
|
45
|
|
|
*/ |
|
46
|
|
|
protected $orderStatus; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* List of all possible TransactionStatus types |
|
50
|
|
|
* |
|
51
|
|
|
* @var \Payone\Core\Model\Source\TransactionStatus |
|
52
|
|
|
*/ |
|
53
|
|
|
protected $transactionStatus; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Rows cache |
|
57
|
|
|
* |
|
58
|
|
|
* @var array|null |
|
59
|
|
|
*/ |
|
60
|
|
|
private $_arrayRowsCache; |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Constructor |
|
64
|
|
|
* |
|
65
|
|
|
* @param \Magento\Backend\Block\Template\Context $context |
|
66
|
|
|
* @param \Magento\Framework\Data\Form\Element\Factory $elementFactory |
|
67
|
|
|
* @param \Magento\Sales\Model\Config\Source\Order\Status $orderStatus |
|
68
|
|
|
* @param \Payone\Core\Model\Source\TransactionStatus $transactionStatus |
|
69
|
|
|
* @param array $data |
|
70
|
|
|
* @return void |
|
|
|
|
|
|
71
|
|
|
*/ |
|
72
|
|
|
public function __construct( |
|
73
|
|
|
\Magento\Backend\Block\Template\Context $context, |
|
74
|
|
|
\Magento\Framework\Data\Form\Element\Factory $elementFactory, |
|
75
|
|
|
\Magento\Sales\Model\ResourceModel\Order\Status\Collection $orderStatus, |
|
76
|
|
|
\Payone\Core\Model\Source\TransactionStatus $transactionStatus, |
|
77
|
|
|
array $data = [] |
|
78
|
|
|
) { |
|
79
|
|
|
parent::__construct($context, $data); |
|
80
|
|
|
$this->elementFactory = $elementFactory; |
|
81
|
|
|
$this->orderStatus = $orderStatus; |
|
|
|
|
|
|
82
|
|
|
$this->transactionStatus = $transactionStatus; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Initialise form fields |
|
87
|
|
|
* |
|
88
|
|
|
* @return void |
|
89
|
|
|
*/ |
|
90
|
|
View Code Duplication |
protected function _construct() |
|
|
|
|
|
|
91
|
|
|
{ |
|
92
|
|
|
$this->addColumn('txaction', ['label' => __('Transactionstatus-message')]); |
|
93
|
|
|
$this->addColumn('state_status', ['label' => __('Magento-status')]); |
|
94
|
|
|
$this->addAfter = false; |
|
95
|
|
|
$this->addButtonLabel = __('Add Statusmapping'); |
|
96
|
|
|
parent::_construct(); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Render array cell for prototypeJS template |
|
101
|
|
|
* |
|
102
|
|
|
* @param string $columnName |
|
103
|
|
|
* @return string |
|
104
|
|
|
*/ |
|
105
|
|
|
public function renderCellTemplate($columnName) |
|
106
|
|
|
{ |
|
107
|
|
|
if ($columnName == 'txaction' && isset($this->_columns[$columnName])) { |
|
108
|
|
|
$aOptions = $this->transactionStatus->toOptionArray(); |
|
109
|
|
|
} elseif ($columnName == 'state_status' && isset($this->_columns[$columnName])) { |
|
110
|
|
|
$aOptions = $this->orderStatus->toOptionArray(); |
|
111
|
|
|
} else { |
|
112
|
|
|
return parent::renderCellTemplate($columnName); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
$oElement = $this->elementFactory->create('select'); |
|
116
|
|
|
$oElement->setForm( |
|
117
|
|
|
$this->getForm() |
|
118
|
|
|
)->setName( |
|
119
|
|
|
$this->_getCellInputElementName($columnName) |
|
120
|
|
|
)->setHtmlId( |
|
121
|
|
|
$this->_getCellInputElementId('<%- _id %>', $columnName) |
|
122
|
|
|
)->setValues( |
|
123
|
|
|
$aOptions |
|
124
|
|
|
); |
|
125
|
|
|
return str_replace("\n", '', $oElement->getElementHtml()); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* Obtain existing data from form element |
|
130
|
|
|
* |
|
131
|
|
|
* Each row will be instance of \Magento\Framework\DataObject |
|
132
|
|
|
* |
|
133
|
|
|
* @return array |
|
134
|
|
|
*/ |
|
135
|
|
|
public function getArrayRows() |
|
136
|
|
|
{ |
|
137
|
|
|
if (null !== $this->_arrayRowsCache) { |
|
138
|
|
|
return $this->_arrayRowsCache; |
|
139
|
|
|
} |
|
140
|
|
|
$result = []; |
|
141
|
|
|
/** @var \Magento\Framework\Data\Form\Element\AbstractElement */ |
|
142
|
|
|
$element = $this->getElement(); |
|
143
|
|
|
$aValue = $element->getValue(); |
|
144
|
|
|
if (!is_array($aValue)) { |
|
145
|
|
|
$aValue = unserialize($aValue); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
if ($aValue && is_array($aValue)) { |
|
149
|
|
|
foreach ($aValue as $rowId => $row) { |
|
150
|
|
|
$rowColumnValues = []; |
|
151
|
|
|
foreach ($row as $key => $value) { |
|
152
|
|
|
$row[$key] = $value; |
|
153
|
|
|
$rowColumnValues[$this->_getCellInputElementId($rowId, $key)] = $row[$key]; |
|
154
|
|
|
} |
|
155
|
|
|
$row['_id'] = $rowId; |
|
156
|
|
|
$row['column_values'] = $rowColumnValues; |
|
157
|
|
|
$result[$rowId] = new \Magento\Framework\DataObject($row); |
|
158
|
|
|
$this->_prepareArrayRow($result[$rowId]); |
|
159
|
|
|
} |
|
160
|
|
|
} |
|
161
|
|
|
$this->_arrayRowsCache = $result; |
|
162
|
|
|
return $this->_arrayRowsCache; |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
/** |
|
166
|
|
|
* Get the grid and scripts contents |
|
167
|
|
|
* |
|
168
|
|
|
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element |
|
169
|
|
|
* @return string |
|
170
|
|
|
*/ |
|
171
|
|
|
protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element) |
|
172
|
|
|
{ |
|
173
|
|
|
$this->setElement($element); |
|
174
|
|
|
$html = $this->_toHtml(); |
|
175
|
|
|
$this->_arrayRowsCache = null; |
|
176
|
|
|
// doh, the object is used as singleton! |
|
177
|
|
|
return $html; |
|
178
|
|
|
} |
|
179
|
|
|
} |
|
180
|
|
|
|
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.