Completed
Push — master ( b9f1e5...5ff555 )
by Aimeos
11:02
created

Standard::getHeader()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 4
nc 2
nop 1
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Metaways Infosystems GmbH, 2013
6
 * @copyright Aimeos (aimeos.org), 2015-2021
7
 * @package Client
8
 * @subpackage Html
9
 */
10
11
12
namespace Aimeos\Client\Html\Checkout\Standard\Summary;
13
14
15
// Strings for translation
16
sprintf( 'summary' );
17
18
19
/**
20
 * Default implementation of checkout summary HTML client.
21
 *
22
 * @package Client
23
 * @subpackage Html
24
 */
25
class Standard
26
	extends \Aimeos\Client\Html\Common\Client\Summary\Base
27
	implements \Aimeos\Client\Html\Common\Client\Factory\Iface
28
{
29
	/** client/html/checkout/standard/summary/subparts
30
	 * List of HTML sub-clients rendered within the checkout standard summary section
31
	 *
32
	 * The output of the frontend is composed of the code generated by the HTML
33
	 * clients. Each HTML client can consist of serveral (or none) sub-clients
34
	 * that are responsible for rendering certain sub-parts of the output. The
35
	 * sub-clients can contain HTML clients themselves and therefore a
36
	 * hierarchical tree of HTML clients is composed. Each HTML client creates
37
	 * the output that is placed inside the container of its parent.
38
	 *
39
	 * At first, always the HTML code generated by the parent is printed, then
40
	 * the HTML code of its sub-clients. The order of the HTML sub-clients
41
	 * determines the order of the output of these sub-clients inside the parent
42
	 * container. If the configured list of clients is
43
	 *
44
	 *  array( "subclient1", "subclient2" )
45
	 *
46
	 * you can easily change the order of the output by reordering the subparts:
47
	 *
48
	 *  client/html/<clients>/subparts = array( "subclient1", "subclient2" )
49
	 *
50
	 * You can also remove one or more parts if they shouldn't be rendered:
51
	 *
52
	 *  client/html/<clients>/subparts = array( "subclient1" )
53
	 *
54
	 * As the clients only generates structural HTML, the layout defined via CSS
55
	 * should support adding, removing or reordering content by a fluid like
56
	 * design.
57
	 *
58
	 * @param array List of sub-client names
59
	 * @since 2014.03
60
	 * @category Developer
61
	 */
62
	private $subPartPath = 'client/html/checkout/standard/summary/subparts';
63
	private $subPartNames = [];
64
65
66
	/**
67
	 * Returns the HTML code for insertion into the body.
68
	 *
69
	 * @param string $uid Unique identifier for the output if the content is placed more than once on the same page
70
	 * @return string HTML code
71
	 */
72
	public function getBody( string $uid = '' ) : string
73
	{
74
		$view = $this->getView();
75
		$step = $view->get( 'standardStepActive' );
76
		$onepage = $view->config( 'client/html/checkout/standard/onepage', [] );
77
78
		if( $step != 'summary' && !( in_array( 'summary', $onepage ) && in_array( $step, $onepage ) ) ) {
79
			return '';
80
		}
81
82
		$html = '';
83
		foreach( $this->getSubClients() as $subclient ) {
84
			$html .= $subclient->setView( $view )->getBody( $uid );
85
		}
86
		$view->summaryBody = $html;
87
88
		/** client/html/checkout/standard/summary/template-body
89
		 * Relative path to the HTML body template of the checkout standard summary client.
90
		 *
91
		 * The template file contains the HTML code and processing instructions
92
		 * to generate the result shown in the body of the frontend. The
93
		 * configuration string is the path to the template file relative
94
		 * to the templates directory (usually in client/html/templates).
95
		 *
96
		 * You can overwrite the template file configuration in extensions and
97
		 * provide alternative templates. These alternative templates should be
98
		 * named like the default one but with the string "standard" replaced by
99
		 * an unique name. You may use the name of your project for this. If
100
		 * you've implemented an alternative client class as well, "standard"
101
		 * should be replaced by the name of the new class.
102
		 *
103
		 * @param string Relative path to the template creating code for the HTML page body
104
		 * @since 2014.03
105
		 * @category Developer
106
		 * @see client/html/checkout/standard/summary/template-header
107
		 */
108
		$tplconf = 'client/html/checkout/standard/summary/template-body';
109
		$default = 'checkout/standard/summary-body-standard';
110
111
		return $view->render( $view->config( $tplconf, $default ) );
112
	}
113
114
115
	/**
116
	 * Returns the HTML string for insertion into the header.
117
	 *
118
	 * @param string $uid Unique identifier for the output if the content is placed more than once on the same page
119
	 * @return string|null String including HTML tags for the header on error
120
	 */
121
	public function getHeader( string $uid = '' ) : ?string
122
	{
123
		$view = $this->getView();
124
		$step = $view->get( 'standardStepActive' );
125
		$onepage = $view->config( 'client/html/checkout/standard/onepage', [] );
126
127
		if( $step != 'summary' && !( in_array( 'summary', $onepage ) && in_array( $step, $onepage ) ) ) {
128
			return '';
129
		}
130
131
		return parent::getHeader( $uid );
132
	}
133
134
135
	/**
136
	 * Returns the sub-client given by its name.
137
	 *
138
	 * @param string $type Name of the client type
139
	 * @param string|null $name Name of the sub-client (Default if null)
140
	 * @return \Aimeos\Client\Html\Iface Sub-client object
141
	 */
142
	public function getSubClient( string $type, string $name = null ) : \Aimeos\Client\Html\Iface
143
	{
144
		/** client/html/checkout/standard/summary/decorators/excludes
145
		 * Excludes decorators added by the "common" option from the checkout standard summary html client
146
		 *
147
		 * Decorators extend the functionality of a class by adding new aspects
148
		 * (e.g. log what is currently done), executing the methods of the underlying
149
		 * class only in certain conditions (e.g. only for logged in users) or
150
		 * modify what is returned to the caller.
151
		 *
152
		 * This option allows you to remove a decorator added via
153
		 * "client/html/common/decorators/default" before they are wrapped
154
		 * around the html client.
155
		 *
156
		 *  client/html/checkout/standard/summary/decorators/excludes = array( 'decorator1' )
157
		 *
158
		 * This would remove the decorator named "decorator1" from the list of
159
		 * common decorators ("\Aimeos\Client\Html\Common\Decorator\*") added via
160
		 * "client/html/common/decorators/default" to the html client.
161
		 *
162
		 * @param array List of decorator names
163
		 * @since 2015.08
164
		 * @category Developer
165
		 * @see client/html/common/decorators/default
166
		 * @see client/html/checkout/standard/summary/decorators/global
167
		 * @see client/html/checkout/standard/summary/decorators/local
168
		 */
169
170
		/** client/html/checkout/standard/summary/decorators/global
171
		 * Adds a list of globally available decorators only to the checkout standard summary html client
172
		 *
173
		 * Decorators extend the functionality of a class by adding new aspects
174
		 * (e.g. log what is currently done), executing the methods of the underlying
175
		 * class only in certain conditions (e.g. only for logged in users) or
176
		 * modify what is returned to the caller.
177
		 *
178
		 * This option allows you to wrap global decorators
179
		 * ("\Aimeos\Client\Html\Common\Decorator\*") around the html client.
180
		 *
181
		 *  client/html/checkout/standard/summary/decorators/global = array( 'decorator1' )
182
		 *
183
		 * This would add the decorator named "decorator1" defined by
184
		 * "\Aimeos\Client\Html\Common\Decorator\Decorator1" only to the html client.
185
		 *
186
		 * @param array List of decorator names
187
		 * @since 2015.08
188
		 * @category Developer
189
		 * @see client/html/common/decorators/default
190
		 * @see client/html/checkout/standard/summary/decorators/excludes
191
		 * @see client/html/checkout/standard/summary/decorators/local
192
		 */
193
194
		/** client/html/checkout/standard/summary/decorators/local
195
		 * Adds a list of local decorators only to the checkout standard summary html client
196
		 *
197
		 * Decorators extend the functionality of a class by adding new aspects
198
		 * (e.g. log what is currently done), executing the methods of the underlying
199
		 * class only in certain conditions (e.g. only for logged in users) or
200
		 * modify what is returned to the caller.
201
		 *
202
		 * This option allows you to wrap local decorators
203
		 * ("\Aimeos\Client\Html\Checkout\Decorator\*") around the html client.
204
		 *
205
		 *  client/html/checkout/standard/summary/decorators/local = array( 'decorator2' )
206
		 *
207
		 * This would add the decorator named "decorator2" defined by
208
		 * "\Aimeos\Client\Html\Checkout\Decorator\Decorator2" only to the html client.
209
		 *
210
		 * @param array List of decorator names
211
		 * @since 2015.08
212
		 * @category Developer
213
		 * @see client/html/common/decorators/default
214
		 * @see client/html/checkout/standard/summary/decorators/excludes
215
		 * @see client/html/checkout/standard/summary/decorators/global
216
		 */
217
218
		return $this->createSubClient( 'checkout/standard/summary/' . $type, $name );
219
	}
220
221
222
	/**
223
	 * Processes the input, e.g. store given values.
224
	 *
225
	 * A view must be available and this method doesn't generate any output
226
	 * besides setting view variables.
227
	 */
228
	public function process()
229
	{
230
		$result = true;
231
		$view = $this->getView();
232
233
		try
234
		{
235
			if( $view->param( 'cs_order', null ) === null ) {
236
				return $result;
237
			}
238
239
240
			$controller = \Aimeos\Controller\Frontend::create( $this->getContext(), 'basket' );
241
			$customerref = strip_tags( $view->param( 'cs_customerref', '', false ) );
242
			$comment = strip_tags( $view->param( 'cs_comment', '', false ) );
243
244
			if( $customerref || $comment )
245
			{
246
				$controller->get()->setCustomerReference( $customerref )->setComment( $comment );
247
				$controller->save();
248
			}
249
250
251
			// only start if there's something to do
252
			if( $view->param( 'cs_option_terms', null ) !== null
253
				&& ( $option = $view->param( 'cs_option_terms_value', 0 ) ) != 1
254
			) {
255
				$error = $view->translate( 'client', 'Please accept the terms and conditions' );
256
				$errors = $view->get( 'summaryErrorCodes', [] );
257
				$errors['option']['terms'] = $error;
258
259
				$view->summaryErrorCodes = $errors;
260
				$view->standardStepActive = 'summary';
261
				$view->standardErrorList = array_merge( $view->get( 'standardErrorList', [] ), array( $error ) );
262
			}
263
264
265
			parent::process();
266
267
			$controller->get()->check( \Aimeos\MShop\Order\Item\Base\Base::PARTS_ALL );
268
		}
269
		catch( \Exception $e )
270
		{
271
			$view->standardStepActive = 'summary';
272
			throw $e;
273
		}
274
	}
275
276
277
	/**
278
	 * Returns the list of sub-client names configured for the client.
279
	 *
280
	 * @return array List of HTML client names
281
	 */
282
	protected function getSubClientNames() : array
283
	{
284
		return $this->getContext()->getConfig()->get( $this->subPartPath, $this->subPartNames );
285
	}
286
287
288
	/**
289
	 * Sets the necessary parameter values in the view.
290
	 *
291
	 * @param \Aimeos\MW\View\Iface $view The view object which generates the HTML output
292
	 * @param array &$tags Result array for the list of tags that are associated to the output
293
	 * @param string|null &$expire Result variable for the expiration date of the output (null for no expiry)
294
	 * @return \Aimeos\MW\View\Iface Modified view object
295
	 */
296
	public function addData( \Aimeos\MW\View\Iface $view, array &$tags = [], string &$expire = null ) : \Aimeos\MW\View\Iface
297
	{
298
		$context = $this->getContext();
0 ignored issues
show
Unused Code introduced by
$context is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
299
		$basket = $view->standardBasket;
300
301
		$view->summaryCostsDelivery = $this->getCostsDelivery( $basket );
302
		$view->summaryCostsPayment = $this->getCostsPayment( $basket );
303
		$view->summaryNamedTaxes = $this->getNamedTaxes( $basket );
304
		$view->summaryTaxRates = $this->getTaxRates( $basket );
305
306
		return parent::addData( $view, $tags, $expire );
307
	}
308
}
309