This repository has been archived by the owner on Oct 17, 2022. It is now read-only.
forked from aimeos/aimeos-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Default.php
330 lines (292 loc) · 12.1 KB
/
Default.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
<?php
/**
* @copyright Copyright (c) Metaways Infosystems GmbH, 2013
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
* @package Client
* @subpackage Html
*/
// Strings for translation
sprintf( 'order' );
/**
* Default implementation of checkout order HTML client.
*
* @package Client
* @subpackage Html
*/
class Client_Html_Checkout_Standard_Order_Default
extends Client_Html_Common_Client_Factory_Abstract
implements Client_Html_Common_Client_Factory_Interface
{
/** client/html/checkout/standard/order/default/subparts
* List of HTML sub-clients rendered within the checkout standard order section
*
* The output of the frontend is composed of the code generated by the HTML
* clients. Each HTML client can consist of serveral (or none) sub-clients
* that are responsible for rendering certain sub-parts of the output. The
* sub-clients can contain HTML clients themselves and therefore a
* hierarchical tree of HTML clients is composed. Each HTML client creates
* the output that is placed inside the container of its parent.
*
* At first, always the HTML code generated by the parent is printed, then
* the HTML code of its sub-clients. The order of the HTML sub-clients
* determines the order of the output of these sub-clients inside the parent
* container. If the configured list of clients is
*
* array( "subclient1", "subclient2" )
*
* you can easily change the order of the output by reordering the subparts:
*
* client/html/<clients>/subparts = array( "subclient1", "subclient2" )
*
* You can also remove one or more parts if they shouldn't be rendered:
*
* client/html/<clients>/subparts = array( "subclient1" )
*
* As the clients only generates structural HTML, the layout defined via CSS
* should support adding, removing or reordering content by a fluid like
* design.
*
* @param array List of sub-client names
* @since 2014.03
* @category Developer
*/
private $_subPartPath = 'client/html/checkout/standard/order/default/subparts';
/** client/html/checkout/standard/order/address/name
* Name of the address part used by the checkout standard order client implementation
*
* Use "Myname" if your class is named "Client_Checkout_Standard_Order_Address_Myname".
* The name is case-sensitive and you should avoid camel case names like "MyName".
*
* @param string Last part of the client class name
* @since 2014.03
* @category Developer
*/
/** client/html/checkout/standard/order/payment/name
* Name of the payment part used by the checkout standard order client implementation
*
* Use "Myname" if your class is named "Client_Checkout_Standard_Order_Payment_Myname".
* The name is case-sensitive and you should avoid camel case names like "MyName".
*
* @param string Last part of the client class name
* @since 2014.03
* @category Developer
*/
private $_subPartNames = array( 'account', 'address' );
/**
* Returns the HTML code for insertion into the body.
*
* @param string $uid Unique identifier for the output if the content is placed more than once on the same page
* @param array &$tags Result array for the list of tags that are associated to the output
* @param string|null &$expire Result variable for the expiration date of the output (null for no expiry)
* @return string HTML code
*/
public function getBody( $uid = '', array &$tags = array(), &$expire = null )
{
$view = $this->getView();
if( $view->get( 'standardStepActive' ) != 'order' ) {
return '';
}
$view = $this->_setViewParams( $view, $tags, $expire );
$html = '';
foreach( $this->_getSubClients() as $subclient ) {
$html .= $subclient->setView( $view )->getBody( $uid, $tags, $expire );
}
$view->orderBody = $html;
/** client/html/checkout/standard/order/default/template-body
* Relative path to the HTML body template of the checkout standard order client.
*
* The template file contains the HTML code and processing instructions
* to generate the result shown in the body of the frontend. The
* configuration string is the path to the template file relative
* to the layouts directory (usually in client/html/layouts).
*
* You can overwrite the template file configuration in extensions and
* provide alternative templates. These alternative templates should be
* named like the default one but with the string "default" replaced by
* an unique name. You may use the name of your project for this. If
* you've implemented an alternative client class as well, "default"
* should be replaced by the name of the new class.
*
* @param string Relative path to the template creating code for the HTML page body
* @since 2014.03
* @category Developer
* @see client/html/checkout/standard/order/default/template-header
*/
$tplconf = 'client/html/checkout/standard/order/default/template-body';
$default = 'checkout/standard/order-body-default.html';
return $view->render( $this->_getTemplate( $tplconf, $default ) );
}
/**
* Returns the HTML string for insertion into the header.
*
* @param string $uid Unique identifier for the output if the content is placed more than once on the same page
* @param array &$tags Result array for the list of tags that are associated to the output
* @param string|null &$expire Result variable for the expiration date of the output (null for no expiry)
* @return string|null String including HTML tags for the header on error
*/
public function getHeader( $uid = '', array &$tags = array(), &$expire = null )
{
$view = $this->getView();
if( $view->get( 'standardStepActive' ) != 'order' ) {
return '';
}
$view = $this->_setViewParams( $view, $tags, $expire );
$html = '';
foreach( $this->_getSubClients() as $subclient ) {
$html .= $subclient->setView( $view )->getHeader( $uid, $tags, $expire );
}
$view->orderHeader = $html;
/** client/html/checkout/standard/order/default/template-header
* Relative path to the HTML header template of the checkout standard order client.
*
* The template file contains the HTML code and processing instructions
* to generate the HTML code that is inserted into the HTML page header
* of the rendered page in the frontend. The configuration string is the
* path to the template file relative to the layouts directory (usually
* in client/html/layouts).
*
* You can overwrite the template file configuration in extensions and
* provide alternative templates. These alternative templates should be
* named like the default one but with the string "default" replaced by
* an unique name. You may use the name of your project for this. If
* you've implemented an alternative client class as well, "default"
* should be replaced by the name of the new class.
*
* @param string Relative path to the template creating code for the HTML page head
* @since 2014.03
* @category Developer
* @see client/html/checkout/standard/order/default/template-body
*/
$tplconf = 'client/html/checkout/standard/order/default/template-header';
$default = 'checkout/standard/order-header-default.html';
return $view->render( $this->_getTemplate( $tplconf, $default ) );
}
/**
* Returns the sub-client given by its name.
*
* @param string $type Name of the client type
* @param string|null $name Name of the sub-client (Default if null)
* @return Client_Html_Interface Sub-client object
*/
public function getSubClient( $type, $name = null )
{
/** client/html/checkout/standard/order/decorators/excludes
* Excludes decorators added by the "common" option from the checkout standard order html client
*
* Decorators extend the functionality of a class by adding new aspects
* (e.g. log what is currently done), executing the methods of the underlying
* class only in certain conditions (e.g. only for logged in users) or
* modify what is returned to the caller.
*
* This option allows you to remove a decorator added via
* "client/html/common/decorators/default" before they are wrapped
* around the html client.
*
* client/html/checkout/standard/order/decorators/excludes = array( 'decorator1' )
*
* This would remove the decorator named "decorator1" from the list of
* common decorators ("Client_Html_Common_Decorator_*") added via
* "client/html/common/decorators/default" to the html client.
*
* @param array List of decorator names
* @since 2015.08
* @category Developer
* @see client/html/common/decorators/default
* @see client/html/checkout/standard/order/decorators/global
* @see client/html/checkout/standard/order/decorators/local
*/
/** client/html/checkout/standard/order/decorators/global
* Adds a list of globally available decorators only to the checkout standard order html client
*
* Decorators extend the functionality of a class by adding new aspects
* (e.g. log what is currently done), executing the methods of the underlying
* class only in certain conditions (e.g. only for logged in users) or
* modify what is returned to the caller.
*
* This option allows you to wrap global decorators
* ("Client_Html_Common_Decorator_*") around the html client.
*
* client/html/checkout/standard/order/decorators/global = array( 'decorator1' )
*
* This would add the decorator named "decorator1" defined by
* "Client_Html_Common_Decorator_Decorator1" only to the html client.
*
* @param array List of decorator names
* @since 2015.08
* @category Developer
* @see client/html/common/decorators/default
* @see client/html/checkout/standard/order/decorators/excludes
* @see client/html/checkout/standard/order/decorators/local
*/
/** client/html/checkout/standard/order/decorators/local
* Adds a list of local decorators only to the checkout standard order html client
*
* Decorators extend the functionality of a class by adding new aspects
* (e.g. log what is currently done), executing the methods of the underlying
* class only in certain conditions (e.g. only for logged in users) or
* modify what is returned to the caller.
*
* This option allows you to wrap local decorators
* ("Client_Html_Checkout_Decorator_*") around the html client.
*
* client/html/checkout/standard/order/decorators/local = array( 'decorator2' )
*
* This would add the decorator named "decorator2" defined by
* "Client_Html_Checkout_Decorator_Decorator2" only to the html client.
*
* @param array List of decorator names
* @since 2015.08
* @category Developer
* @see client/html/common/decorators/default
* @see client/html/checkout/standard/order/decorators/excludes
* @see client/html/checkout/standard/order/decorators/global
*/
return $this->_createSubClient( 'checkout/standard/order/' . $type, $name );
}
/**
* Processes the input, e.g. store given order.
* A view must be available and this method doesn't generate any output
* besides setting view variables.
*/
public function process()
{
$view = $this->getView();
try
{
// only start if there's something to do
if( ( $option = $view->param( 'cs_order', null ) ) === null
|| $view->get( 'standardStepActive' ) !== null
) {
return;
}
$context = $this->_getContext();
$orderBaseManager = MShop_Factory::createManager( $context, 'order/base' );
$basket = $orderBaseManager->getSession();
$basket->setCustomerId( $context->getUserId() );
$basket->finish();
$cntl = Controller_Frontend_Factory::createController( $context, 'order' );
$orderItem = $cntl->store( $basket );
$cntl->block( $orderItem );
$context->getSession()->set( 'arcavias/orderid', $orderItem->getId() );
$view->orderItem = $orderItem;
$view->orderBasket = $basket;
parent::process();
// save again after sub-clients modified it's state
MShop_Factory::createManager( $context, 'order' )->saveItem( $orderItem );
}
catch( Exception $e )
{
$view->standardStepActive = 'order';
throw $e;
}
}
/**
* Returns the list of sub-client names configured for the client.
*
* @return array List of HTML client names
*/
protected function _getSubClientNames()
{
return $this->_getContext()->getConfig()->get( $this->_subPartPath, $this->_subPartNames );
}
}