1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2022 |
6
|
|
|
* @package Admin |
7
|
|
|
* @subpackage JQAdm |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
namespace Aimeos\Admin\JQAdm\Order\Transaction; |
12
|
|
|
|
13
|
|
|
sprintf( 'transaction' ); // for translation |
14
|
|
|
|
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Default implementation of order transaction JQAdm client. |
18
|
|
|
* |
19
|
|
|
* @package Admin |
20
|
|
|
* @subpackage JQAdm |
21
|
|
|
*/ |
22
|
|
|
class Standard |
23
|
|
|
extends \Aimeos\Admin\JQAdm\Common\Admin\Factory\Base |
24
|
|
|
implements \Aimeos\Admin\JQAdm\Common\Admin\Factory\Iface |
25
|
|
|
{ |
26
|
|
|
/** admin/jqadm/order/transaction/name |
27
|
|
|
* Name of the transaction subpart used by the JQAdm order implementation |
28
|
|
|
* |
29
|
|
|
* Use "Myname" if your class is named "\Aimeos\Admin\Jqadm\Order\Transaction\Myname". |
30
|
|
|
* The name is case-sensitive and you should avoid camel case names like "MyName". |
31
|
|
|
* |
32
|
|
|
* @param string Last part of the JQAdm class name |
33
|
|
|
* @since 2023.01 |
34
|
|
|
* @category Developer |
35
|
|
|
*/ |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Copies a resource |
40
|
|
|
* |
41
|
|
|
* @return string|null HTML output |
42
|
|
|
*/ |
43
|
|
|
public function copy() : ?string |
44
|
|
|
{ |
45
|
|
|
return $this->get(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Creates a new resource |
51
|
|
|
* |
52
|
|
|
* @return string|null HTML output |
53
|
|
|
*/ |
54
|
|
|
public function create() : ?string |
55
|
|
|
{ |
56
|
|
|
return $this->get(); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Returns a single resource |
62
|
|
|
* |
63
|
|
|
* @return string|null HTML output |
64
|
|
|
*/ |
65
|
|
|
public function get() : ?string |
66
|
|
|
{ |
67
|
|
|
$view = $this->object()->data( $this->view() ); |
68
|
|
|
|
69
|
|
|
return $this->render( $view ); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Saves the data |
75
|
|
|
* |
76
|
|
|
* @return string|null HTML output |
77
|
|
|
*/ |
78
|
|
|
public function save() : ?string |
79
|
|
|
{ |
80
|
|
|
$view = $this->view(); |
81
|
|
|
|
82
|
|
|
$this->fromArray( $view->item, $view->param( 'transaction', [] ) ); |
83
|
|
|
$view->transactionBody = parent::save(); |
84
|
|
|
|
85
|
|
|
return null; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Returns the sub-client given by its name. |
91
|
|
|
* |
92
|
|
|
* @param string $type Name of the client type |
93
|
|
|
* @param string|null $name Name of the sub-client (Default if null) |
94
|
|
|
* @return \Aimeos\Admin\JQAdm\Iface Sub-client object |
95
|
|
|
*/ |
96
|
|
|
public function getSubClient( string $type, string $name = null ) : \Aimeos\Admin\JQAdm\Iface |
97
|
|
|
{ |
98
|
|
|
/** admin/jqadm/order/transaction/decorators/excludes |
99
|
|
|
* Excludes decorators added by the "common" option from the order JQAdm client |
100
|
|
|
* |
101
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
102
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
103
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
104
|
|
|
* modify what is returned to the caller. |
105
|
|
|
* |
106
|
|
|
* This option allows you to remove a decorator added via |
107
|
|
|
* "admin/jqadm/common/decorators/default" before they are wrapped |
108
|
|
|
* around the JQAdm client. |
109
|
|
|
* |
110
|
|
|
* admin/jqadm/order/transaction/decorators/excludes = array( 'decorator1' ) |
111
|
|
|
* |
112
|
|
|
* This would remove the decorator named "decorator1" from the list of |
113
|
|
|
* common decorators ("\Aimeos\Admin\JQAdm\Common\Decorator\*") added via |
114
|
|
|
* "admin/jqadm/common/decorators/default" to the JQAdm client. |
115
|
|
|
* |
116
|
|
|
* @param array List of decorator names |
117
|
|
|
* @since 2023.01 |
118
|
|
|
* @category Developer |
119
|
|
|
* @see admin/jqadm/common/decorators/default |
120
|
|
|
* @see admin/jqadm/order/transaction/decorators/global |
121
|
|
|
* @see admin/jqadm/order/transaction/decorators/local |
122
|
|
|
*/ |
123
|
|
|
|
124
|
|
|
/** admin/jqadm/order/transaction/decorators/global |
125
|
|
|
* Adds a list of globally available decorators only to the order JQAdm client |
126
|
|
|
* |
127
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
128
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
129
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
130
|
|
|
* modify what is returned to the caller. |
131
|
|
|
* |
132
|
|
|
* This option allows you to wrap global decorators |
133
|
|
|
* ("\Aimeos\Admin\JQAdm\Common\Decorator\*") around the JQAdm client. |
134
|
|
|
* |
135
|
|
|
* admin/jqadm/order/transaction/decorators/global = array( 'decorator1' ) |
136
|
|
|
* |
137
|
|
|
* This would add the decorator named "decorator1" defined by |
138
|
|
|
* "\Aimeos\Admin\JQAdm\Common\Decorator\Decorator1" only to the JQAdm client. |
139
|
|
|
* |
140
|
|
|
* @param array List of decorator names |
141
|
|
|
* @since 2023.01 |
142
|
|
|
* @category Developer |
143
|
|
|
* @see admin/jqadm/common/decorators/default |
144
|
|
|
* @see admin/jqadm/order/transaction/decorators/excludes |
145
|
|
|
* @see admin/jqadm/order/transaction/decorators/local |
146
|
|
|
*/ |
147
|
|
|
|
148
|
|
|
/** admin/jqadm/order/transaction/decorators/local |
149
|
|
|
* Adds a list of local decorators only to the order JQAdm client |
150
|
|
|
* |
151
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
152
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
153
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
154
|
|
|
* modify what is returned to the caller. |
155
|
|
|
* |
156
|
|
|
* This option allows you to wrap local decorators |
157
|
|
|
* ("\Aimeos\Admin\JQAdm\Order\Decorator\*") around the JQAdm client. |
158
|
|
|
* |
159
|
|
|
* admin/jqadm/order/transaction/decorators/local = array( 'decorator2' ) |
160
|
|
|
* |
161
|
|
|
* This would add the decorator named "decorator2" defined by |
162
|
|
|
* "\Aimeos\Admin\JQAdm\Order\Decorator\Decorator2" only to the JQAdm client. |
163
|
|
|
* |
164
|
|
|
* @param array List of decorator names |
165
|
|
|
* @since 2023.01 |
166
|
|
|
* @category Developer |
167
|
|
|
* @see admin/jqadm/common/decorators/default |
168
|
|
|
* @see admin/jqadm/order/transaction/decorators/excludes |
169
|
|
|
* @see admin/jqadm/order/transaction/decorators/global |
170
|
|
|
*/ |
171
|
|
|
return $this->createSubClient( 'order/transaction/' . $type, $name ); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* Returns the list of sub-client names configured for the client. |
177
|
|
|
* |
178
|
|
|
* @return array List of JQAdm client names |
179
|
|
|
*/ |
180
|
|
|
protected function getSubClientNames() : array |
181
|
|
|
{ |
182
|
|
|
/** admin/jqadm/order/transaction/subparts |
183
|
|
|
* List of JQAdm sub-clients rendered within the order transaction section |
184
|
|
|
* |
185
|
|
|
* The output of the frontend is composed of the code generated by the JQAdm |
186
|
|
|
* clients. Each JQAdm client can consist of serveral (or none) sub-clients |
187
|
|
|
* that are responsible for rendering certain sub-parts of the output. The |
188
|
|
|
* sub-clients can contain JQAdm clients themselves and therefore a |
189
|
|
|
* hierarchical tree of JQAdm clients is composed. Each JQAdm client creates |
190
|
|
|
* the output that is placed inside the container of its parent. |
191
|
|
|
* |
192
|
|
|
* At first, always the JQAdm code generated by the parent is printed, then |
193
|
|
|
* the JQAdm code of its sub-clients. The transaction of the JQAdm sub-clients |
194
|
|
|
* determines the transaction of the output of these sub-clients inside the parent |
195
|
|
|
* container. If the configured list of clients is |
196
|
|
|
* |
197
|
|
|
* array( "subclient1", "subclient2" ) |
198
|
|
|
* |
199
|
|
|
* you can easily change the transaction of the output by retransactioning the subparts: |
200
|
|
|
* |
201
|
|
|
* admin/jqadm/<clients>/subparts = array( "subclient1", "subclient2" ) |
202
|
|
|
* |
203
|
|
|
* You can also remove one or more parts if they shouldn't be rendered: |
204
|
|
|
* |
205
|
|
|
* admin/jqadm/<clients>/subparts = array( "subclient1" ) |
206
|
|
|
* |
207
|
|
|
* As the clients only generates structural JQAdm, the layout defined via CSS |
208
|
|
|
* should support adding, removing or retransactioning content by a fluid like |
209
|
|
|
* design. |
210
|
|
|
* |
211
|
|
|
* @param array List of sub-client names |
212
|
|
|
* @since 2023.01 |
213
|
|
|
* @category Developer |
214
|
|
|
*/ |
215
|
|
|
return $this->context()->config()->get( 'admin/jqadm/order/transaction/subparts', [] ); |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* Creates new and updates existing items using the data array |
221
|
|
|
* |
222
|
|
|
* @param \Aimeos\MShop\Order\Item\Iface $order Order item object |
223
|
|
|
* @param array $data Data array |
224
|
|
|
*/ |
225
|
|
|
protected function fromArray( \Aimeos\MShop\Order\Item\Iface $order, array $data ) |
226
|
|
|
{ |
227
|
|
|
$context = $this->context(); |
228
|
|
|
$manager = \Aimeos\MShop::create( $context, 'order' ); |
229
|
|
|
$services = map( $order->getService( 'payment' ) )->col( null, 'order.service.id' ); |
230
|
|
|
|
231
|
|
|
foreach( $data as $serviceId => $entry ) |
232
|
|
|
{ |
233
|
|
|
if( array_sum( $entry ) === 0 || ( $service = $services->get( $serviceId ) ) === null ) { |
234
|
|
|
continue; |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
$price = \Aimeos\MShop::create( $context, 'price' )->create() |
238
|
|
|
->setValue( -$entry['order.service.transaction.value'] ?? 0 ) |
239
|
|
|
->setCosts( -$entry['order.service.transaction.costs'] ?? 0 ) |
240
|
|
|
->setCurrencyId( $service->getPrice()->getCurrencyId() ); |
241
|
|
|
|
242
|
|
|
$txItem = \Aimeos\MShop::create( $context, 'order/service' )->createTransaction() |
|
|
|
|
243
|
|
|
->setType( 'payment' )->setPrice( $price )->setStatus( \Aimeos\MShop\Order\Item\Base::PAY_REFUND ); |
244
|
|
|
|
245
|
|
|
$serviceItem = \Aimeos\MShop::create( $context, 'service' )->get( $service->getServiceId() ); |
246
|
|
|
|
247
|
|
|
$provider = \Aimeos\MShop::create( $context, 'service' )->getProvider( $serviceItem, 'payment' ); |
248
|
|
|
|
249
|
|
|
if( $provider->isImplemented( \Aimeos\MShop\Service\Provider\Payment\Base::FEAT_REFUND ) ) { |
250
|
|
|
$manager->save( $provider->refund( $order, $price ) ); |
251
|
|
|
} else { |
252
|
|
|
$txItem->setConfigValue( 'info', $context->translate( 'admin', 'Manual transfer' ) ); |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
$service->addTransaction( $txItem ); |
256
|
|
|
} |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
|
260
|
|
|
/** |
261
|
|
|
* Returns the rendered template including the view data |
262
|
|
|
* |
263
|
|
|
* @param \Aimeos\Base\View\Iface $view View object with data assigned |
264
|
|
|
* @return string HTML output |
265
|
|
|
*/ |
266
|
|
|
protected function render( \Aimeos\Base\View\Iface $view ) : string |
267
|
|
|
{ |
268
|
|
|
/** admin/jqadm/order/transaction/template-item |
269
|
|
|
* Relative path to the HTML body template of the transaction subpart for orders. |
270
|
|
|
* |
271
|
|
|
* The template file contains the HTML code and processing instructions |
272
|
|
|
* to generate the result shown in the body of the frontend. The |
273
|
|
|
* configuration string is the path to the template file relative |
274
|
|
|
* to the templates directory (usually in templates/admin/jqadm). |
275
|
|
|
* |
276
|
|
|
* You can overwrite the template file configuration in extensions and |
277
|
|
|
* provide alternative templates. These alternative templates should be |
278
|
|
|
* named like the default one but with the string "default" replaced by |
279
|
|
|
* an unique name. You may use the name of your project for this. If |
280
|
|
|
* you've implemented an alternative client class as well, "default" |
281
|
|
|
* should be replaced by the name of the new class. |
282
|
|
|
* |
283
|
|
|
* @param string Relative path to the template creating the HTML code |
284
|
|
|
* @since 2016.04 |
285
|
|
|
* @category Developer |
286
|
|
|
*/ |
287
|
|
|
$tplconf = 'admin/jqadm/order/transaction/template-item'; |
288
|
|
|
$default = 'order/item-transaction'; |
289
|
|
|
|
290
|
|
|
return $view->render( $view->config( $tplconf, $default ) ); |
291
|
|
|
} |
292
|
|
|
} |
293
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.