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-2022 |
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\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
|
|
|
*/ |
61
|
|
|
private $subPartPath = 'client/html/checkout/standard/summary/subparts'; |
62
|
|
|
private $subPartNames = []; |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Returns the HTML code for insertion into the body. |
67
|
|
|
* |
68
|
|
|
* @param string $uid Unique identifier for the output if the content is placed more than once on the same page |
69
|
|
|
* @return string HTML code |
70
|
|
|
*/ |
71
|
|
|
public function body( string $uid = '' ) : string |
72
|
|
|
{ |
73
|
|
|
$view = $this->view(); |
74
|
|
|
$step = $view->get( 'standardStepActive' ); |
75
|
|
|
$onepage = $view->config( 'client/html/checkout/standard/onepage', [] ); |
76
|
|
|
|
77
|
|
|
if( $step != 'summary' && !( in_array( 'summary', $onepage ) && in_array( $step, $onepage ) ) ) { |
78
|
|
|
return ''; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
$html = ''; |
82
|
|
|
foreach( $this->getSubClients() as $subclient ) { |
83
|
|
|
$html .= $subclient->setView( $view )->body( $uid ); |
84
|
|
|
} |
85
|
|
|
$view->summaryBody = $html; |
86
|
|
|
|
87
|
|
|
/** client/html/checkout/standard/summary/template-body |
88
|
|
|
* Relative path to the HTML body template of the checkout standard summary client. |
89
|
|
|
* |
90
|
|
|
* The template file contains the HTML code and processing instructions |
91
|
|
|
* to generate the result shown in the body of the frontend. The |
92
|
|
|
* configuration string is the path to the template file relative |
93
|
|
|
* to the templates directory (usually in client/html/templates). |
94
|
|
|
* |
95
|
|
|
* You can overwrite the template file configuration in extensions and |
96
|
|
|
* provide alternative templates. These alternative templates should be |
97
|
|
|
* named like the default one but suffixed by |
98
|
|
|
* an unique name. You may use the name of your project for this. If |
99
|
|
|
* you've implemented an alternative client class as well, it |
100
|
|
|
* should be suffixed by the name of the new class. |
101
|
|
|
* |
102
|
|
|
* @param string Relative path to the template creating code for the HTML page body |
103
|
|
|
* @since 2014.03 |
104
|
|
|
* @see client/html/checkout/standard/summary/template-header |
105
|
|
|
*/ |
106
|
|
|
$tplconf = 'client/html/checkout/standard/summary/template-body'; |
107
|
|
|
$default = 'checkout/standard/summary-body'; |
108
|
|
|
|
109
|
|
|
return $view->render( $view->config( $tplconf, $default ) ); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Returns the sub-client given by its name. |
115
|
|
|
* |
116
|
|
|
* @param string $type Name of the client type |
117
|
|
|
* @param string|null $name Name of the sub-client (Default if null) |
118
|
|
|
* @return \Aimeos\Client\Html\Iface Sub-client object |
119
|
|
|
*/ |
120
|
|
|
public function getSubClient( string $type, string $name = null ) : \Aimeos\Client\Html\Iface |
121
|
|
|
{ |
122
|
|
|
/** client/html/checkout/standard/summary/decorators/excludes |
123
|
|
|
* Excludes decorators added by the "common" option from the checkout standard summary html client |
124
|
|
|
* |
125
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
126
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
127
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
128
|
|
|
* modify what is returned to the caller. |
129
|
|
|
* |
130
|
|
|
* This option allows you to remove a decorator added via |
131
|
|
|
* "client/html/common/decorators/default" before they are wrapped |
132
|
|
|
* around the html client. |
133
|
|
|
* |
134
|
|
|
* client/html/checkout/standard/summary/decorators/excludes = array( 'decorator1' ) |
135
|
|
|
* |
136
|
|
|
* This would remove the decorator named "decorator1" from the list of |
137
|
|
|
* common decorators ("\Aimeos\Client\Html\Common\Decorator\*") added via |
138
|
|
|
* "client/html/common/decorators/default" to the html client. |
139
|
|
|
* |
140
|
|
|
* @param array List of decorator names |
141
|
|
|
* @since 2015.08 |
142
|
|
|
* @see client/html/common/decorators/default |
143
|
|
|
* @see client/html/checkout/standard/summary/decorators/global |
144
|
|
|
* @see client/html/checkout/standard/summary/decorators/local |
145
|
|
|
*/ |
146
|
|
|
|
147
|
|
|
/** client/html/checkout/standard/summary/decorators/global |
148
|
|
|
* Adds a list of globally available decorators only to the checkout standard summary html client |
149
|
|
|
* |
150
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
151
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
152
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
153
|
|
|
* modify what is returned to the caller. |
154
|
|
|
* |
155
|
|
|
* This option allows you to wrap global decorators |
156
|
|
|
* ("\Aimeos\Client\Html\Common\Decorator\*") around the html client. |
157
|
|
|
* |
158
|
|
|
* client/html/checkout/standard/summary/decorators/global = array( 'decorator1' ) |
159
|
|
|
* |
160
|
|
|
* This would add the decorator named "decorator1" defined by |
161
|
|
|
* "\Aimeos\Client\Html\Common\Decorator\Decorator1" only to the html client. |
162
|
|
|
* |
163
|
|
|
* @param array List of decorator names |
164
|
|
|
* @since 2015.08 |
165
|
|
|
* @see client/html/common/decorators/default |
166
|
|
|
* @see client/html/checkout/standard/summary/decorators/excludes |
167
|
|
|
* @see client/html/checkout/standard/summary/decorators/local |
168
|
|
|
*/ |
169
|
|
|
|
170
|
|
|
/** client/html/checkout/standard/summary/decorators/local |
171
|
|
|
* Adds a list of local 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 local decorators |
179
|
|
|
* ("\Aimeos\Client\Html\Checkout\Decorator\*") around the html client. |
180
|
|
|
* |
181
|
|
|
* client/html/checkout/standard/summary/decorators/local = array( 'decorator2' ) |
182
|
|
|
* |
183
|
|
|
* This would add the decorator named "decorator2" defined by |
184
|
|
|
* "\Aimeos\Client\Html\Checkout\Decorator\Decorator2" only to the html client. |
185
|
|
|
* |
186
|
|
|
* @param array List of decorator names |
187
|
|
|
* @since 2015.08 |
188
|
|
|
* @see client/html/common/decorators/default |
189
|
|
|
* @see client/html/checkout/standard/summary/decorators/excludes |
190
|
|
|
* @see client/html/checkout/standard/summary/decorators/global |
191
|
|
|
*/ |
192
|
|
|
|
193
|
|
|
return $this->createSubClient( 'checkout/standard/summary/' . $type, $name ); |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* Processes the input, e.g. store given values. |
199
|
|
|
* |
200
|
|
|
* A view must be available and this method doesn't generate any output |
201
|
|
|
* besides setting view variables. |
202
|
|
|
*/ |
203
|
|
|
public function init() |
204
|
|
|
{ |
205
|
|
|
$result = true; |
206
|
|
|
$view = $this->view(); |
207
|
|
|
|
208
|
|
|
try |
209
|
|
|
{ |
210
|
|
|
if( $view->param( 'cs_order', null ) === null ) { |
211
|
|
|
return $result; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
|
215
|
|
|
$controller = \Aimeos\Controller\Frontend::create( $this->context(), 'basket' ); |
216
|
|
|
$customerref = strip_tags( $view->param( 'cs_customerref', '', false ) ); |
217
|
|
|
$comment = strip_tags( $view->param( 'cs_comment', '', false ) ); |
218
|
|
|
|
219
|
|
|
if( $customerref || $comment ) |
220
|
|
|
{ |
221
|
|
|
$controller->get()->setCustomerReference( $customerref )->setComment( $comment ); |
222
|
|
|
$controller->save(); |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
|
226
|
|
|
// only start if there's something to do |
227
|
|
|
if( $view->param( 'cs_option_terms', null ) !== null |
228
|
|
|
&& ( $option = $view->param( 'cs_option_terms_value', 0 ) ) != 1 |
|
|
|
|
229
|
|
|
) { |
230
|
|
|
$error = $view->translate( 'client', 'Please accept the terms and conditions' ); |
231
|
|
|
$errors = $view->get( 'summaryErrorCodes', [] ); |
232
|
|
|
$errors['option']['terms'] = $error; |
233
|
|
|
|
234
|
|
|
$view->summaryErrorCodes = $errors; |
235
|
|
|
$view->standardStepActive = 'summary'; |
236
|
|
|
$view->standardErrorList = array_merge( $view->get( 'standardErrorList', [] ), array( $error ) ); |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
|
240
|
|
|
parent::init(); |
241
|
|
|
|
242
|
|
|
$controller->get()->check( ['order/base/address', 'order/base/coupon', 'order/base/product', 'order/base/service'] ); |
243
|
|
|
} |
244
|
|
|
catch( \Exception $e ) |
245
|
|
|
{ |
246
|
|
|
$view->standardStepActive = 'summary'; |
247
|
|
|
throw $e; |
248
|
|
|
} |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* Returns the list of sub-client names configured for the client. |
254
|
|
|
* |
255
|
|
|
* @return array List of HTML client names |
256
|
|
|
*/ |
257
|
|
|
protected function getSubClientNames() : array |
258
|
|
|
{ |
259
|
|
|
return $this->context()->config()->get( $this->subPartPath, $this->subPartNames ); |
260
|
|
|
} |
261
|
|
|
} |
262
|
|
|
|