Passed
Branch master (d032f7)
by Aimeos
05:30
created

Standard::copy()   A

Complexity

Conditions 5
Paths 21

Size

Total Lines 38
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 22
nc 21
nop 0
dl 0
loc 38
rs 9.2568
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2017-2018
6
 * @package Admin
7
 * @subpackage JQAdm
8
 */
9
10
11
namespace Aimeos\Admin\JQAdm\Order;
12
13
sprintf( 'order' ); // for translation
14
15
16
/**
17
 * Default implementation of order 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
	/**
27
	 * Copies a resource
28
	 *
29
	 * @return string HTML output
30
	 */
31
	public function copy()
32
	{
33
		$view = $this->getView();
34
		$context = $this->getContext();
35
36
		try
37
		{
38
			if( ( $id = $view->param( 'id' ) ) === null ) {
39
				throw new \Aimeos\Admin\JQAdm\Exception( sprintf( 'Required parameter "%1$s" is missing', 'id' ) );
40
			}
41
42
			$manager = \Aimeos\MShop::create( $context, 'order/base' );
43
			$view->item = $manager->load( $id );
1 ignored issue
show
Bug introduced by
The method load() does not exist on Aimeos\MShop\Common\Manager\Iface. It seems like you code against a sub-type of Aimeos\MShop\Common\Manager\Iface such as Aimeos\MShop\Order\Manager\Base\Iface or Aimeos\MShop\Common\Manager\Decorator\Base or Aimeos\MShop\Service\Manager\Lists\Type\Standard or Aimeos\MShop\Price\Manager\Standard or Aimeos\MShop\Attribute\Manager\Type\Standard or Aimeos\MShop\Price\Manager\Lists\Type\Standard or Aimeos\MShop\Media\Manager\Type\Standard or Aimeos\MShop\Coupon\Manager\Code\Standard or Aimeos\MShop\Order\Manager\Base\Coupon\Standard or Aimeos\MShop\Product\Manager\Standard or Aimeos\MShop\Index\Manager\Standard or Aimeos\MShop\Index\Manager\Attribute\Standard or Aimeos\MShop\Index\Manager\Text\Standard or Aimeos\MShop\Index\Manager\Supplier\Standard or Aimeos\MShop\Index\Manager\Catalog\Standard or Aimeos\MShop\Index\Manager\Price\Standard or Aimeos\MShop\Supplier\Manager\Standard or Aimeos\MShop\Customer\Manager\Property\Standard or Aimeos\MShop\Order\Manager\Base\Service\Standard or Aimeos\MShop\Price\Manager\Lists\Standard or Aimeos\MShop\Supplier\Manager\Lists\Type\Standard or Aimeos\MShop\Order\Manag...vice\Attribute\Standard or Aimeos\MShop\Service\Manager\Lists\Standard or Aimeos\MShop\Tag\Manager\Type\Standard or Aimeos\MShop\Text\Manager\Lists\Standard or Aimeos\MShop\Price\Manager\Type\Standard or Aimeos\MShop\Locale\Manager\Currency\Standard or Aimeos\MShop\Order\Manag...duct\Attribute\Standard or Aimeos\MShop\Media\Manager\Lists\Type\Standard or Aimeos\MShop\Catalog\Manager\Lists\Standard or Aimeos\MShop\Tag\Manager\Standard or Aimeos\MShop\Coupon\Manager\Standard or Aimeos\MShop\Attribute\Manager\Standard or Aimeos\MShop\Attribute\M...\Property\Type\Standard or Aimeos\MShop\Service\Manager\Type\Standard or Aimeos\MShop\Product\Manager\Lists\Standard or Aimeos\MShop\Customer\Ma...\Property\Type\Standard or Aimeos\MShop\Order\Manager\Standard or Aimeos\MShop\Customer\Manager\Standard or Aimeos\MShop\Media\Manager\Standard or Aimeos\MShop\Customer\Manager\Lists\Type\Standard or Aimeos\MShop\Attribute\Manager\Lists\Standard or Aimeos\MShop\Product\Man...\Property\Type\Standard or Aimeos\MShop\Media\Manager\Lists\Standard or Aimeos\MShop\Plugin\Manager\Standard or Aimeos\MShop\Order\Manager\Base\Address\Standard or Aimeos\MShop\Catalog\Manager\Standard or Aimeos\MShop\Locale\Manager\Site\Standard or Aimeos\MShop\Product\Manager\Type\Standard or Aimeos\MShop\Supplier\Manager\Lists\Standard or Aimeos\MShop\Stock\Manager\Type\Standard or Aimeos\MShop\Text\Manager\Standard or Aimeos\MAdmin\Job\Manager\Standard or Aimeos\MShop\Customer\Manager\Group\Standard or Aimeos\MShop\Product\Manager\Lists\Type\Standard or Aimeos\MShop\Text\Manager\Lists\Type\Standard or Aimeos\MShop\Text\Manager\Type\Standard or Aimeos\MShop\Order\Manager\Status\Standard or Aimeos\MShop\Supplier\Manager\Address\Standard or Aimeos\MShop\Customer\Manager\Address\Standard or Aimeos\MShop\Plugin\Manager\Type\Standard or Aimeos\MShop\Stock\Manager\Standard or Aimeos\MShop\Stock\Manager\Nolimit or Aimeos\MShop\Attribute\Manager\Property\Standard or Aimeos\MShop\Subscription\Manager\Standard or Aimeos\MShop\Media\Manager\Property\Type\Standard or Aimeos\MShop\Product\Manager\Property\Standard or Aimeos\MShop\Locale\Manager\Language\Standard or Aimeos\MShop\Media\Manager\Property\Standard or Aimeos\MShop\Service\Manager\Standard or Aimeos\MShop\Attribute\Manager\Lists\Type\Standard or Aimeos\MAdmin\Log\Manager\Standard or Aimeos\MShop\Locale\Manager\Standard or Aimeos\MAdmin\Cache\Manager\Standard or Aimeos\MAdmin\Cache\Manager\None or Aimeos\MShop\Order\Manager\Base\Product\Standard or Aimeos\MShop\Customer\Manager\Lists\Standard or Aimeos\MShop\Catalog\Manager\Lists\Type\Standard. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

43
			/** @scrutinizer ignore-call */ 
44
   $view->item = $manager->load( $id );
Loading history...
44
45
			$view->itemData = $this->toArray( $view->item, true );
46
			$view->itemSubparts = $this->getSubClientNames();
47
			$view->itemBody = '';
48
49
			foreach( $this->getSubClients() as $idx => $client )
50
			{
51
				$view->tabindex = ++$idx + 1;
52
				$view->itemBody .= $client->copy();
53
			}
54
		}
55
		catch( \Aimeos\MShop\Exception $e )
56
		{
57
			$error = array( 'order-item' => $context->getI18n()->dt( 'mshop', $e->getMessage() ) );
58
			$view->errors = $view->get( 'errors', [] ) + $error;
59
			$this->logException( $e );
60
		}
61
		catch( \Exception $e )
62
		{
63
			$error = array( 'order-item' => $e->getMessage() . ', ' . $e->getFile() . ':' . $e->getLine() );
64
			$view->errors = $view->get( 'errors', [] ) + $error;
65
			$this->logException( $e );
66
		}
67
68
		return $this->render( $view );
69
	}
70
71
72
	/**
73
	 * Creates a new resource
74
	 *
75
	 * @return string HTML output
76
	 */
77
	public function create()
78
	{
79
		$view = $this->getView();
80
		$context = $this->getContext();
81
82
		try
83
		{
84
			$data = $view->param( 'item', [] );
85
86
			if( !isset( $view->item ) ) {
87
				$view->item = \Aimeos\MShop::create( $context, 'order/base' )->createItem();
88
			}
89
90
			$data['order.siteid'] = $view->item->getSiteId();
91
92
			$view->itemSubparts = $this->getSubClientNames();
93
			$view->itemData = $data;
94
			$view->itemBody = '';
95
96
			foreach( $this->getSubClients() as $idx => $client )
97
			{
98
				$view->tabindex = ++$idx + 1;
99
				$view->itemBody .= $client->create();
100
			}
101
		}
102
		catch( \Aimeos\MShop\Exception $e )
103
		{
104
			$error = array( 'order-item' => $context->getI18n()->dt( 'mshop', $e->getMessage() ) );
105
			$view->errors = $view->get( 'errors', [] ) + $error;
106
			$this->logException( $e );
107
		}
108
		catch( \Exception $e )
109
		{
110
			$error = array( 'order-item' => $e->getMessage() . ', ' . $e->getFile() . ':' . $e->getLine() );
111
			$view->errors = $view->get( 'errors', [] ) + $error;
112
			$this->logException( $e );
113
		}
114
115
		return $this->render( $view );
116
	}
117
118
119
	/**
120
	 * Exports a resource
121
	 *
122
	 * @return string Admin output to display
123
	 */
124
	public function export()
125
	{
126
		$view = $this->getView();
127
		$context = $this->getContext();
128
129
		try
130
		{
131
			$params = $this->storeSearchParams( $view->param(), 'order' );
132
			$msg = ['sitecode' => $context->getLocale()->getSite()->getCode()];
133
134
			if( isset( $params['filter'] ) ) {
135
				$msg['filter'] = $this->getCriteriaConditions( $params['filter'] );
136
			}
137
138
			if( isset( $params['sort'] ) ) {
139
				$msg['sort'] = $this->getCriteriaSortations( $params['sort'] );
140
			}
141
142
			$mq = $context->getMessageQueueManager()->get( 'mq-admin' )->getQueue( 'order-export' );
143
			$mq->add( json_encode( $msg ) );
144
145
			$msg = $context->getI18n()->dt( 'admin', 'Your export will be available in a few minutes for download' );
146
			$view->info = $view->get( 'info', [] ) + ['order-item' => $msg];
147
		}
148
		catch( \Aimeos\MShop\Exception $e )
149
		{
150
			$error = array( 'order-item' => $context->getI18n()->dt( 'mshop', $e->getMessage() ) );
151
			$view->errors = $view->get( 'errors', [] ) + $error;
152
			$this->logException( $e );
153
		}
154
		catch( \Exception $e )
155
		{
156
			$error = array( 'order-item' => $e->getMessage() . ', ' . $e->getFile() . ':' . $e->getLine() );
157
			$view->errors = $view->get( 'errors', [] ) + $error;
158
			$this->logException( $e );
159
		}
160
161
		return $this->search();
162
	}
163
164
165
	/**
166
	 * Returns a single resource
167
	 *
168
	 * @return string HTML output
169
	 */
170
	public function get()
171
	{
172
		$view = $this->getView();
173
		$context = $this->getContext();
174
175
		try
176
		{
177
			if( ( $id = $view->param( 'id' ) ) === null ) {
178
				throw new \Aimeos\Admin\JQAdm\Exception( sprintf( 'Required parameter "%1$s" is missing', 'id' ) );
179
			}
180
181
			$manager = \Aimeos\MShop::create( $context, 'order/base' );
182
			$refs = ['order/base/address', 'order/base/coupon', 'order/base/product', 'order/base/service'];
183
184
			$view->item = $manager->getItem( $id, $refs );
185
			$view->itemSubparts = $this->getSubClientNames();
186
			$view->itemData = $this->toArray( $view->item );
187
			$view->itemBody = '';
188
189
			foreach( $this->getSubClients() as $idx => $client )
190
			{
191
				$view->tabindex = ++$idx + 1;
192
				$view->itemBody .= $client->get();
193
			}
194
		}
195
		catch( \Aimeos\MShop\Exception $e )
196
		{
197
			$error = array( 'order-item' => $context->getI18n()->dt( 'mshop', $e->getMessage() ) );
198
			$view->errors = $view->get( 'errors', [] ) + $error;
199
			$this->logException( $e );
200
		}
201
		catch( \Exception $e )
202
		{
203
			$error = array( 'order-item' => $e->getMessage() . ', ' . $e->getFile() . ':' . $e->getLine() );
204
			$view->errors = $view->get( 'errors', [] ) + $error;
205
			$this->logException( $e );
206
		}
207
208
		return $this->render( $view );
209
	}
210
211
212
	/**
213
	 * Saves the data
214
	 *
215
	 * @return string HTML output
216
	 */
217
	public function save()
218
	{
219
		$view = $this->getView();
220
		$context = $this->getContext();
221
222
		$manager = \Aimeos\MShop::create( $context, 'order/base' );
223
		$manager->begin();
224
225
		try
226
		{
227
			$item = $this->fromArray( $view->param( 'item', [] ) );
228
			$view->item = $item->getId() ? $item : $manager->store( clone $item );
1 ignored issue
show
Bug introduced by
The method store() does not exist on Aimeos\MShop\Common\Manager\Iface. It seems like you code against a sub-type of Aimeos\MShop\Common\Manager\Iface such as Aimeos\MShop\Order\Manager\Base\Iface or Aimeos\MShop\Common\Manager\Decorator\Base or Aimeos\MShop\Service\Manager\Lists\Type\Standard or Aimeos\MShop\Price\Manager\Standard or Aimeos\MShop\Attribute\Manager\Type\Standard or Aimeos\MShop\Price\Manager\Lists\Type\Standard or Aimeos\MShop\Media\Manager\Type\Standard or Aimeos\MShop\Coupon\Manager\Code\Standard or Aimeos\MShop\Order\Manager\Base\Coupon\Standard or Aimeos\MShop\Product\Manager\Standard or Aimeos\MShop\Index\Manager\Standard or Aimeos\MShop\Index\Manager\Attribute\Standard or Aimeos\MShop\Index\Manager\Text\Standard or Aimeos\MShop\Index\Manager\Supplier\Standard or Aimeos\MShop\Index\Manager\Catalog\Standard or Aimeos\MShop\Index\Manager\Price\Standard or Aimeos\MShop\Supplier\Manager\Standard or Aimeos\MShop\Customer\Manager\Property\Standard or Aimeos\MShop\Order\Manager\Base\Service\Standard or Aimeos\MShop\Price\Manager\Lists\Standard or Aimeos\MShop\Supplier\Manager\Lists\Type\Standard or Aimeos\MShop\Order\Manag...vice\Attribute\Standard or Aimeos\MShop\Service\Manager\Lists\Standard or Aimeos\MShop\Tag\Manager\Type\Standard or Aimeos\MShop\Text\Manager\Lists\Standard or Aimeos\MShop\Price\Manager\Type\Standard or Aimeos\MShop\Locale\Manager\Currency\Standard or Aimeos\MShop\Order\Manag...duct\Attribute\Standard or Aimeos\MShop\Media\Manager\Lists\Type\Standard or Aimeos\MShop\Catalog\Manager\Lists\Standard or Aimeos\MShop\Tag\Manager\Standard or Aimeos\MShop\Coupon\Manager\Standard or Aimeos\MShop\Attribute\Manager\Standard or Aimeos\MShop\Attribute\M...\Property\Type\Standard or Aimeos\MShop\Service\Manager\Type\Standard or Aimeos\MShop\Product\Manager\Lists\Standard or Aimeos\MShop\Customer\Ma...\Property\Type\Standard or Aimeos\MShop\Order\Manager\Standard or Aimeos\MShop\Customer\Manager\Standard or Aimeos\MShop\Media\Manager\Standard or Aimeos\MShop\Customer\Manager\Lists\Type\Standard or Aimeos\MShop\Attribute\Manager\Lists\Standard or Aimeos\MShop\Product\Man...\Property\Type\Standard or Aimeos\MShop\Media\Manager\Lists\Standard or Aimeos\MShop\Plugin\Manager\Standard or Aimeos\MShop\Order\Manager\Base\Address\Standard or Aimeos\MShop\Catalog\Manager\Standard or Aimeos\MShop\Locale\Manager\Site\Standard or Aimeos\MShop\Product\Manager\Type\Standard or Aimeos\MShop\Supplier\Manager\Lists\Standard or Aimeos\MShop\Stock\Manager\Type\Standard or Aimeos\MShop\Text\Manager\Standard or Aimeos\MAdmin\Job\Manager\Standard or Aimeos\MShop\Customer\Manager\Group\Standard or Aimeos\MShop\Product\Manager\Lists\Type\Standard or Aimeos\MShop\Text\Manager\Lists\Type\Standard or Aimeos\MShop\Text\Manager\Type\Standard or Aimeos\MShop\Order\Manager\Status\Standard or Aimeos\MShop\Supplier\Manager\Address\Standard or Aimeos\MShop\Customer\Manager\Address\Standard or Aimeos\MShop\Plugin\Manager\Type\Standard or Aimeos\MShop\Stock\Manager\Standard or Aimeos\MShop\Stock\Manager\Nolimit or Aimeos\MShop\Attribute\Manager\Property\Standard or Aimeos\MShop\Subscription\Manager\Standard or Aimeos\MShop\Media\Manager\Property\Type\Standard or Aimeos\MShop\Product\Manager\Property\Standard or Aimeos\MShop\Locale\Manager\Language\Standard or Aimeos\MShop\Media\Manager\Property\Standard or Aimeos\MShop\Service\Manager\Standard or Aimeos\MShop\Attribute\Manager\Lists\Type\Standard or Aimeos\MAdmin\Log\Manager\Standard or Aimeos\MShop\Locale\Manager\Standard or Aimeos\MAdmin\Cache\Manager\Standard or Aimeos\MAdmin\Cache\Manager\None or Aimeos\MShop\Order\Manager\Base\Product\Standard or Aimeos\MShop\Customer\Manager\Lists\Standard or Aimeos\MShop\Catalog\Manager\Lists\Type\Standard. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

228
			$view->item = $item->getId() ? $item : $manager->/** @scrutinizer ignore-call */ store( clone $item );
Loading history...
229
			$view->itemBody = '';
230
231
			foreach( $this->getSubClients() as $client ) {
232
				$view->itemBody .= $client->save();
233
			}
234
235
			$manager->store( clone $view->item );
236
			$manager->commit();
237
238
			$this->nextAction( $view, $view->param( 'next' ), 'order', $view->item->getId(), 'save' );
239
			return;
240
		}
241
		catch( \Aimeos\Admin\JQAdm\Exception $e )
242
		{
243
			// fall through to create
244
		}
245
		catch( \Aimeos\MShop\Exception $e )
246
		{
247
			$error = array( 'order-item' => $context->getI18n()->dt( 'mshop', $e->getMessage() ) );
248
			$view->errors = $view->get( 'errors', [] ) + $error;
249
			$this->logException( $e );
250
		}
251
		catch( \Exception $e )
252
		{
253
			$error = array( 'order-item' => $e->getMessage() . ', ' . $e->getFile() . ':' . $e->getLine() );
254
			$view->errors = $view->get( 'errors', [] ) + $error;
255
			$this->logException( $e );
256
		}
257
258
		$manager->rollback();
259
260
		return $this->get();
261
	}
262
263
264
	/**
265
	 * Returns a list of resource according to the conditions
266
	 *
267
	 * @return string HTML output
268
	 */
269
	public function search()
270
	{
271
		$view = $this->getView();
272
		$context = $this->getContext();
273
274
		try
275
		{
276
			$total = 0;
277
			$params = $this->storeSearchParams( $view->param(), 'order' );
278
			$manager = \Aimeos\MShop::create( $context, 'order' );
279
280
			$search = $manager->createSearch();
281
			$search->setSortations( [$search->sort( '-', 'order.id' )] );
282
			$search = $this->initCriteria( $search, $params );
283
284
			$view->items = $manager->searchItems( $search, [], $total );
285
			$view->baseItems = $this->getOrderBaseItems( $view->items );
286
			$view->filterAttributes = $manager->getSearchAttributes( true );
287
			$view->filterOperators = $search->getOperators();
288
			$view->total = $total;
289
			$view->itemBody = '';
290
291
			foreach( $this->getSubClients() as $client ) {
292
				$view->itemBody .= $client->search();
293
			}
294
		}
295
		catch( \Aimeos\MShop\Exception $e )
296
		{
297
			$error = array( 'order-item' => $context->getI18n()->dt( 'mshop', $e->getMessage() ) );
298
			$view->errors = $view->get( 'errors', [] ) + $error;
299
			$this->logException( $e );
300
		}
301
		catch( \Exception $e )
302
		{
303
			$error = array( 'order-item' => $e->getMessage() . ', ' . $e->getFile() . ':' . $e->getLine() );
304
			$view->errors = $view->get( 'errors', [] ) + $error;
305
			$this->logException( $e );
306
		}
307
308
		/** admin/jqadm/order/template-list
309
		 * Relative path to the HTML body template for the order list.
310
		 *
311
		 * The template file contains the HTML code and processing instructions
312
		 * to generate the result shown in the body of the frontend. The
313
		 * configuration string is the path to the template file relative
314
		 * to the templates directory (usually in admin/jqadm/templates).
315
		 *
316
		 * You can overwrite the template file configuration in extensions and
317
		 * provide alternative templates. These alternative templates should be
318
		 * named like the default one but with the string "default" replaced by
319
		 * an unique name. You may use the name of your project for this. If
320
		 * you've implemented an alternative client class as well, "default"
321
		 * should be replaced by the name of the new class.
322
		 *
323
		 * @param string Relative path to the template creating the HTML code
324
		 * @since 2016.04
325
		 * @category Developer
326
		 */
327
		$tplconf = 'admin/jqadm/order/template-list';
328
		$default = 'order/list-standard';
329
330
		return $view->render( $view->config( $tplconf, $default ) );
331
	}
332
333
334
	/**
335
	 * Returns the sub-client given by its name.
336
	 *
337
	 * @param string $type Name of the client type
338
	 * @param string|null $name Name of the sub-client (Default if null)
339
	 * @return \Aimeos\Admin\JQAdm\Iface Sub-client object
340
	 */
341
	public function getSubClient( $type, $name = null )
342
	{
343
		/** admin/jqadm/order/decorators/excludes
344
		 * Excludes decorators added by the "common" option from the order JQAdm client
345
		 *
346
		 * Decorators extend the functionality of a class by adding new aspects
347
		 * (e.g. log what is currently done), executing the methods of the underlying
348
		 * class only in certain conditions (e.g. only for logged in users) or
349
		 * modify what is returned to the caller.
350
		 *
351
		 * This option allows you to remove a decorator added via
352
		 * "client/jqadm/common/decorators/default" before they are wrapped
353
		 * around the JQAdm client.
354
		 *
355
		 *  admin/jqadm/order/decorators/excludes = array( 'decorator1' )
356
		 *
357
		 * This would remove the decorator named "decorator1" from the list of
358
		 * common decorators ("\Aimeos\Admin\JQAdm\Common\Decorator\*") added via
359
		 * "client/jqadm/common/decorators/default" to the JQAdm client.
360
		 *
361
		 * @param array List of decorator names
362
		 * @since 2016.01
363
		 * @category Developer
364
		 * @see admin/jqadm/common/decorators/default
365
		 * @see admin/jqadm/order/decorators/global
366
		 * @see admin/jqadm/order/decorators/local
367
		 */
368
369
		/** admin/jqadm/order/decorators/global
370
		 * Adds a list of globally available decorators only to the order JQAdm client
371
		 *
372
		 * Decorators extend the functionality of a class by adding new aspects
373
		 * (e.g. log what is currently done), executing the methods of the underlying
374
		 * class only in certain conditions (e.g. only for logged in users) or
375
		 * modify what is returned to the caller.
376
		 *
377
		 * This option allows you to wrap global decorators
378
		 * ("\Aimeos\Admin\JQAdm\Common\Decorator\*") around the JQAdm client.
379
		 *
380
		 *  admin/jqadm/order/decorators/global = array( 'decorator1' )
381
		 *
382
		 * This would add the decorator named "decorator1" defined by
383
		 * "\Aimeos\Admin\JQAdm\Common\Decorator\Decorator1" only to the JQAdm client.
384
		 *
385
		 * @param array List of decorator names
386
		 * @since 2016.01
387
		 * @category Developer
388
		 * @see admin/jqadm/common/decorators/default
389
		 * @see admin/jqadm/order/decorators/excludes
390
		 * @see admin/jqadm/order/decorators/local
391
		 */
392
393
		/** admin/jqadm/order/decorators/local
394
		 * Adds a list of local decorators only to the order JQAdm client
395
		 *
396
		 * Decorators extend the functionality of a class by adding new aspects
397
		 * (e.g. log what is currently done), executing the methods of the underlying
398
		 * class only in certain conditions (e.g. only for logged in users) or
399
		 * modify what is returned to the caller.
400
		 *
401
		 * This option allows you to wrap local decorators
402
		 * ("\Aimeos\Admin\JQAdm\Order\Decorator\*") around the JQAdm client.
403
		 *
404
		 *  admin/jqadm/order/decorators/local = array( 'decorator2' )
405
		 *
406
		 * This would add the decorator named "decorator2" defined by
407
		 * "\Aimeos\Admin\JQAdm\Order\Decorator\Decorator2" only to the JQAdm client.
408
		 *
409
		 * @param array List of decorator names
410
		 * @since 2016.01
411
		 * @category Developer
412
		 * @see admin/jqadm/common/decorators/default
413
		 * @see admin/jqadm/order/decorators/excludes
414
		 * @see admin/jqadm/order/decorators/global
415
		 */
416
		return $this->createSubClient( 'order/' . $type, $name );
417
	}
418
419
420
	/**
421
	 * Returns the base order items (baskets) for the given order items (invoices)
422
	 *
423
	 * @param \Aimeos\MShop\Order\Item\Iface[] $orderItems List of order items
424
	 * @param \Aimeos\MShop\Order\Item\Base\Iface[] List of order base items
0 ignored issues
show
Bug introduced by
The type Aimeos\Admin\JQAdm\Order\List was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
425
	 */
426
	protected function getOrderBaseItems( array $orderItems )
427
	{
428
		$baseIds = [];
429
		foreach( $orderItems as $item ) {
430
			$baseIds[] = $item->getBaseId();
431
		}
432
433
		$manager = \Aimeos\MShop::create( $this->getContext(), 'order/base' );
434
435
		$search = $manager->createSearch()->setSlice( 0, count( $baseIds ) );
436
		$search->setConditions( $search->compare( '==', 'order.base.id', $baseIds ) );
437
438
		return $manager->searchItems( $search, ['order/base/address', 'order/base/service'] );
439
	}
440
441
442
	/**
443
	 * Returns the list of sub-client names configured for the client.
444
	 *
445
	 * @return array List of JQAdm client names
446
	 */
447
	protected function getSubClientNames()
448
	{
449
		/** admin/jqadm/order/standard/subparts
450
		 * List of JQAdm sub-clients rendered within the order section
451
		 *
452
		 * The output of the frontend is composed of the code generated by the JQAdm
453
		 * clients. Each JQAdm client can consist of serveral (or none) sub-clients
454
		 * that are responsible for rendering certain sub-parts of the output. The
455
		 * sub-clients can contain JQAdm clients themselves and therefore a
456
		 * hierarchical tree of JQAdm clients is composed. Each JQAdm client creates
457
		 * the output that is placed inside the container of its parent.
458
		 *
459
		 * At first, always the JQAdm code generated by the parent is printed, then
460
		 * the JQAdm code of its sub-clients. The order of the JQAdm sub-clients
461
		 * determines the order of the output of these sub-clients inside the parent
462
		 * container. If the configured list of clients is
463
		 *
464
		 *  array( "subclient1", "subclient2" )
465
		 *
466
		 * you can easily change the order of the output by reordering the subparts:
467
		 *
468
		 *  admin/jqadm/<clients>/subparts = array( "subclient1", "subclient2" )
469
		 *
470
		 * You can also remove one or more parts if they shouldn't be rendered:
471
		 *
472
		 *  admin/jqadm/<clients>/subparts = array( "subclient1" )
473
		 *
474
		 * As the clients only generates structural JQAdm, the layout defined via CSS
475
		 * should support adding, removing or reordering content by a fluid like
476
		 * design.
477
		 *
478
		 * @param array List of sub-client names
479
		 * @since 2016.01
480
		 * @category Developer
481
		 */
482
		return $this->getContext()->getConfig()->get( 'admin/jqadm/order/standard/subparts', [] );
483
	}
484
485
486
	/**
487
	 * Creates new and updates existing items using the data array
488
	 *
489
	 * @param string[] Data array
0 ignored issues
show
Bug introduced by
The type Aimeos\Admin\JQAdm\Order\Data was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
490
	 * @return \Aimeos\MShop\Order\Item\Iface New order item object
491
	 */
492
	protected function fromArray( array $data )
493
	{
494
		$manager = \Aimeos\MShop::create( $this->getContext(), 'order/base' );
495
		$attrManager = \Aimeos\MShop::create( $this->getContext(), 'order/base/service/attribute' );
496
497
		if( isset( $data['order.base.id'] ) ) {
498
			$basket = $manager->load( $data['order.base.id'] );
499
		} else {
500
			$basket = $manager->createItem();
501
		}
502
503
		$basket->fromArray( $data );
504
505
		foreach( $basket->getProducts() as $pos => $product )
506
		{
507
			if( isset( $data['product'][$pos]['order.base.product.status'] ) ) {
508
				$product->setStatus( $data['product'][$pos]['order.base.product.status'] );
509
			}
510
		}
511
512
		foreach( $basket->getAddresses() as $type => $address )
513
		{
514
			if( isset( $data['address'][$type] ) ) {
515
				$list = (array) $data['address'][$type];
516
				$basket->setAddress( $address->fromArray( $list ), $type );
517
			} else {
518
				$basket->deleteAddress( $type );
519
			}
520
		}
521
522
		foreach( $basket->getServices() as $type => $services )
523
		{
524
			foreach( $services as $serviceId => $service )
525
			{
526
				$list = [];
527
				$attrItems = $service->getAttributeItems();
528
529
				if( isset( $data['service'][$type][$serviceId] ) )
530
				{
531
					foreach( (array) $data['service'][$type][$serviceId] as $key => $pair )
532
					{
533
						foreach( $pair as $pos => $value ) {
534
							$list[$pos][$key] = $value;
535
						}
536
					}
537
538
					foreach( $list as $array )
539
					{
540
						if( isset( $attrItems[$array['order.base.service.attribute.id']] ) )
541
						{
542
							$attrItem = $attrItems[$array['order.base.service.attribute.id']];
543
							unset( $attrItems[$array['order.base.service.attribute.id']] );
544
						}
545
						else
546
						{
547
							$attrItem = $attrManager->createItem();
548
						}
549
550
						$attrItem->fromArray( $array );
551
						$attrItem->setParentId( $service->getId() );
552
553
						$item = $attrManager->saveItem( $attrItem );
0 ignored issues
show
Unused Code introduced by
The assignment to $item is dead and can be removed.
Loading history...
554
					}
555
				}
556
557
				$attrManager->deleteItems( array_keys( $attrItems ) );
558
			}
559
		}
560
561
		return $basket;
562
	}
563
564
565
	/**
566
	 * Constructs the data array for the view from the given item
567
	 *
568
	 * @param \Aimeos\MShop\Order\Item\Base\Iface $item Order base item object
569
	 * @return string[] Multi-dimensional associative list of item data
570
	 */
571
	protected function toArray( \Aimeos\MShop\Order\Item\Base\Iface $item, $copy = false )
572
	{
573
		$siteId = $this->getContext()->getLocale()->getSiteId();
574
		$data = $item->toArray( true );
575
576
		if( $item->getCustomerId() != '' )
577
		{
578
			$manager = \Aimeos\MShop::create( $this->getContext(), 'customer' );
579
580
			try {
581
				$data += $manager->getItem( $item->getCustomerId() )->toArray();
582
			} catch( \Exception $e ) {};
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
583
		}
584
585
586
		if( $copy === true )
587
		{
588
			$data['order.base.siteid'] = $siteId;
589
			$data['order.base.id'] = '';
590
		}
591
592
		foreach( $item->getAddresses() as $type => $addrItem )
593
		{
594
			$list = $addrItem->toArray( true );
595
596
			foreach( $list as $key => $value ) {
597
				$data['address'][$type][$key] = $value;
598
			}
599
600
			if( $copy === true )
601
			{
602
				$data['address'][$type]['order.base.address.siteid'] = $siteId;
603
				$data['address'][$type]['order.base.address.id'] = '';
604
			}
605
		}
606
607
		if( $copy !== true )
608
		{
609
			foreach( $item->getServices() as $type => $services )
610
			{
611
				foreach( $services as $serviceItem )
612
				{
613
					$serviceId = $serviceItem->getServiceId();
614
615
					foreach( $serviceItem->getAttributeItems() as $attrItem )
616
					{
617
						foreach( $attrItem->toArray( true ) as $key => $value ) {
618
							$data['service'][$type][$serviceId][$key][] = $value;
619
						}
620
					}
621
				}
622
			}
623
		}
624
625
		foreach( $item->getProducts() as $pos => $productItem ) {
626
			$data['product'][$pos]['order.base.product.status'] = $productItem->getStatus();
627
		}
628
629
		return $data;
630
	}
631
632
633
	/**
634
	 * Returns the rendered template including the view data
635
	 *
636
	 * @param \Aimeos\MW\View\Iface $view View object with data assigned
637
	 * @return string HTML output
638
	 */
639
	protected function render( \Aimeos\MW\View\Iface $view )
640
	{
641
		/** admin/jqadm/order/template-item
642
		 * Relative path to the HTML body template for the order item.
643
		 *
644
		 * The template file contains the HTML code and processing instructions
645
		 * to generate the result shown in the body of the frontend. The
646
		 * configuration string is the path to the template file relative
647
		 * to the templates directory (usually in admin/jqadm/templates).
648
		 *
649
		 * You can overwrite the template file configuration in extensions and
650
		 * provide alternative templates. These alternative templates should be
651
		 * named like the default one but with the string "default" replaced by
652
		 * an unique name. You may use the name of your project for this. If
653
		 * you've implemented an alternative client class as well, "default"
654
		 * should be replaced by the name of the new class.
655
		 *
656
		 * @param string Relative path to the template creating the HTML code
657
		 * @since 2016.04
658
		 * @category Developer
659
		 */
660
		$tplconf = 'admin/jqadm/order/template-item';
661
		$default = 'order/item-standard';
662
663
		return $view->render( $view->config( $tplconf, $default ) );
664
	}
665
}
666