Passed
Push — master ( 0ca7f5...355141 )
by Aimeos
07:40 queued 03:13
created

Standard::getOrderBaseItems()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 9
rs 10
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-2022
6
 * @package Admin
7
 * @subpackage JQAdm
8
 */
9
10
11
namespace Aimeos\Admin\JQAdm\Customer\Order;
12
13
sprintf( 'order' ); // for translation
14
15
16
/**
17
 * Default implementation of customer 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
	/** admin/jqadm/customer/order/name
27
	 * Name of the order subpart used by the JQAdm customer implementation
28
	 *
29
	 * Use "Myname" if your class is named "\Aimeos\Admin\Jqadm\Customer\Address\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 2017.06
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
		$total = 0;
70
		$params = $this->storeFilter( $view->param( 'uo', [] ), 'customerorder' );
71
		$orderItems = $this->getOrderItems( $view->item, $params, $total );
72
73
		$view->orderItems = $orderItems;
74
		$view->orderBody = parent::get();
75
		$view->orderTotal = $total;
76
77
		return $this->render( $view );
78
	}
79
80
81
	/**
82
	 * Saves the data
83
	 *
84
	 * @return string|null HTML output
85
	 */
86
	public function save() : ?string
87
	{
88
		return $this->get();
89
	}
90
91
92
	/**
93
	 * Returns the sub-client given by its name.
94
	 *
95
	 * @param string $type Name of the client type
96
	 * @param string|null $name Name of the sub-client (Default if null)
97
	 * @return \Aimeos\Admin\JQAdm\Iface Sub-client object
98
	 */
99
	public function getSubClient( string $type, string $name = null ) : \Aimeos\Admin\JQAdm\Iface
100
	{
101
		/** admin/jqadm/customer/order/decorators/excludes
102
		 * Excludes decorators added by the "common" option from the customer JQAdm client
103
		 *
104
		 * Decorators extend the functionality of a class by adding new aspects
105
		 * (e.g. log what is currently done), executing the methods of the underlying
106
		 * class only in certain conditions (e.g. only for logged in users) or
107
		 * modify what is returned to the caller.
108
		 *
109
		 * This option allows you to remove a decorator added via
110
		 * "admin/jqadm/common/decorators/default" before they are wrapped
111
		 * around the JQAdm client.
112
		 *
113
		 *  admin/jqadm/customer/order/decorators/excludes = array( 'decorator1' )
114
		 *
115
		 * This would remove the decorator named "decorator1" from the list of
116
		 * common decorators ("\Aimeos\Admin\JQAdm\Common\Decorator\*") added via
117
		 * "admin/jqadm/common/decorators/default" to the JQAdm client.
118
		 *
119
		 * @param array List of decorator names
120
		 * @since 2017.07
121
		 * @category Developer
122
		 * @see admin/jqadm/common/decorators/default
123
		 * @see admin/jqadm/customer/order/decorators/global
124
		 * @see admin/jqadm/customer/order/decorators/local
125
		 */
126
127
		/** admin/jqadm/customer/order/decorators/global
128
		 * Adds a list of globally available decorators only to the customer JQAdm client
129
		 *
130
		 * Decorators extend the functionality of a class by adding new aspects
131
		 * (e.g. log what is currently done), executing the methods of the underlying
132
		 * class only in certain conditions (e.g. only for logged in users) or
133
		 * modify what is returned to the caller.
134
		 *
135
		 * This option allows you to wrap global decorators
136
		 * ("\Aimeos\Admin\JQAdm\Common\Decorator\*") around the JQAdm client.
137
		 *
138
		 *  admin/jqadm/customer/order/decorators/global = array( 'decorator1' )
139
		 *
140
		 * This would add the decorator named "decorator1" defined by
141
		 * "\Aimeos\Admin\JQAdm\Common\Decorator\Decorator1" only to the JQAdm client.
142
		 *
143
		 * @param array List of decorator names
144
		 * @since 2017.07
145
		 * @category Developer
146
		 * @see admin/jqadm/common/decorators/default
147
		 * @see admin/jqadm/customer/order/decorators/excludes
148
		 * @see admin/jqadm/customer/order/decorators/local
149
		 */
150
151
		/** admin/jqadm/customer/order/decorators/local
152
		 * Adds a list of local decorators only to the customer JQAdm client
153
		 *
154
		 * Decorators extend the functionality of a class by adding new aspects
155
		 * (e.g. log what is currently done), executing the methods of the underlying
156
		 * class only in certain conditions (e.g. only for logged in users) or
157
		 * modify what is returned to the caller.
158
		 *
159
		 * This option allows you to wrap local decorators
160
		 * ("\Aimeos\Admin\JQAdm\Customer\Decorator\*") around the JQAdm client.
161
		 *
162
		 *  admin/jqadm/customer/order/decorators/local = array( 'decorator2' )
163
		 *
164
		 * This would add the decorator named "decorator2" defined by
165
		 * "\Aimeos\Admin\JQAdm\Customer\Decorator\Decorator2" only to the JQAdm client.
166
		 *
167
		 * @param array List of decorator names
168
		 * @since 2017.07
169
		 * @category Developer
170
		 * @see admin/jqadm/common/decorators/default
171
		 * @see admin/jqadm/customer/order/decorators/excludes
172
		 * @see admin/jqadm/customer/order/decorators/global
173
		 */
174
		return $this->createSubClient( 'customer/order/' . $type, $name );
175
	}
176
177
178
	/**
179
	 * Returns the order items of the customer
180
	 *
181
	 * @param \Aimeos\MShop\Customer\Item\Iface $item Customer item object
182
	 * @param array $params Associative list of GET/POST parameters
183
	 * @param integer $total Value/result parameter that will contain the item total afterwards
184
	 * @return \Aimeos\Map Order items of the customer implementing \Aimeos\MShop\Order\Item\Iface
185
	 */
186
	protected function getOrderItems( \Aimeos\MShop\Customer\Item\Iface $item, array $params = [], &$total = null ) : \Aimeos\Map
187
	{
188
		$manager = \Aimeos\MShop::create( $this->context(), 'order' );
189
190
		$search = $manager->filter()->order( '-order.ctime' );
191
		$search = $this->initCriteria( $search, $params )->add( 'order.customerid', '==', $item->getId() );
192
193
		return $manager->search( $search, [], $total );
194
	}
195
196
197
	/**
198
	 * Returns the list of sub-client names configured for the client.
199
	 *
200
	 * @return array List of JQAdm client names
201
	 */
202
	protected function getSubClientNames() : array
203
	{
204
		/** admin/jqadm/customer/order/subparts
205
		 * List of JQAdm sub-clients rendered within the customer order section
206
		 *
207
		 * The output of the frontend is composed of the code generated by the JQAdm
208
		 * clients. Each JQAdm client can consist of serveral (or none) sub-clients
209
		 * that are responsible for rendering certain sub-parts of the output. The
210
		 * sub-clients can contain JQAdm clients themselves and therefore a
211
		 * hierarchical tree of JQAdm clients is composed. Each JQAdm client creates
212
		 * the output that is placed inside the container of its parent.
213
		 *
214
		 * At first, always the JQAdm code generated by the parent is printed, then
215
		 * the JQAdm code of its sub-clients. The order of the JQAdm sub-clients
216
		 * determines the order of the output of these sub-clients inside the parent
217
		 * container. If the configured list of clients is
218
		 *
219
		 *  array( "subclient1", "subclient2" )
220
		 *
221
		 * you can easily change the order of the output by reordering the subparts:
222
		 *
223
		 *  admin/jqadm/<clients>/subparts = array( "subclient1", "subclient2" )
224
		 *
225
		 * You can also remove one or more parts if they shouldn't be rendered:
226
		 *
227
		 *  admin/jqadm/<clients>/subparts = array( "subclient1" )
228
		 *
229
		 * As the clients only generates structural JQAdm, the layout defined via CSS
230
		 * should support adding, removing or reordering content by a fluid like
231
		 * design.
232
		 *
233
		 * @param array List of sub-client names
234
		 * @since 2017.07
235
		 * @category Developer
236
		 */
237
		return $this->context()->config()->get( 'admin/jqadm/customer/order/subparts', [] );
238
	}
239
240
241
	/**
242
	 * Returns the rendered template including the view data
243
	 *
244
	 * @param \Aimeos\Base\View\Iface $view View object with data assigned
245
	 * @return string HTML output
246
	 */
247
	protected function render( \Aimeos\Base\View\Iface $view ) : string
248
	{
249
		/** admin/jqadm/customer/order/template-item
250
		 * Relative path to the HTML body template of the order subpart for customers.
251
		 *
252
		 * The template file contains the HTML code and processing instructions
253
		 * to generate the result shown in the body of the frontend. The
254
		 * configuration string is the path to the template file relative
255
		 * to the templates directory (usually in templates/admin/jqadm).
256
		 *
257
		 * You can overwrite the template file configuration in extensions and
258
		 * provide alternative templates. These alternative templates should be
259
		 * named like the default one but with the string "default" replaced by
260
		 * an unique name. You may use the name of your project for this. If
261
		 * you've implemented an alternative client class as well, "default"
262
		 * should be replaced by the name of the new class.
263
		 *
264
		 * @param string Relative path to the template creating the HTML code
265
		 * @since 2016.04
266
		 * @category Developer
267
		 */
268
		$tplconf = 'admin/jqadm/customer/order/template-item';
269
		$default = 'customer/item-order';
270
271
		return $view->render( $view->config( $tplconf, $default ) );
272
	}
273
}
274