|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2014 |
|
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2018 |
|
7
|
|
|
* @package Client |
|
8
|
|
|
* @subpackage Html |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
namespace Aimeos\Client\Html\Account\Favorite; |
|
13
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Default implementation of account favorite HTML client. |
|
17
|
|
|
* |
|
18
|
|
|
* @package Client |
|
19
|
|
|
* @subpackage Html |
|
20
|
|
|
*/ |
|
21
|
|
|
class Standard |
|
22
|
|
|
extends \Aimeos\Client\Html\Common\Client\Factory\Base |
|
23
|
|
|
implements \Aimeos\Client\Html\Common\Client\Factory\Iface |
|
24
|
|
|
{ |
|
25
|
|
|
/** client/html/account/favorite/standard/subparts |
|
26
|
|
|
* List of HTML sub-clients rendered within the account favorite section |
|
27
|
|
|
* |
|
28
|
|
|
* The output of the frontend is composed of the code generated by the HTML |
|
29
|
|
|
* clients. Each HTML client can consist of serveral (or none) sub-clients |
|
30
|
|
|
* that are responsible for rendering certain sub-parts of the output. The |
|
31
|
|
|
* sub-clients can contain HTML clients themselves and therefore a |
|
32
|
|
|
* hierarchical tree of HTML clients is composed. Each HTML client creates |
|
33
|
|
|
* the output that is placed inside the container of its parent. |
|
34
|
|
|
* |
|
35
|
|
|
* At first, always the HTML code generated by the parent is printed, then |
|
36
|
|
|
* the HTML code of its sub-clients. The order of the HTML sub-clients |
|
37
|
|
|
* determines the order of the output of these sub-clients inside the parent |
|
38
|
|
|
* container. If the configured list of clients is |
|
39
|
|
|
* |
|
40
|
|
|
* array( "subclient1", "subclient2" ) |
|
41
|
|
|
* |
|
42
|
|
|
* you can easily change the order of the output by reordering the subparts: |
|
43
|
|
|
* |
|
44
|
|
|
* client/html/<clients>/subparts = array( "subclient1", "subclient2" ) |
|
45
|
|
|
* |
|
46
|
|
|
* You can also remove one or more parts if they shouldn't be rendered: |
|
47
|
|
|
* |
|
48
|
|
|
* client/html/<clients>/subparts = array( "subclient1" ) |
|
49
|
|
|
* |
|
50
|
|
|
* As the clients only generates structural HTML, the layout defined via CSS |
|
51
|
|
|
* should support adding, removing or reordering content by a fluid like |
|
52
|
|
|
* design. |
|
53
|
|
|
* |
|
54
|
|
|
* @param array List of sub-client names |
|
55
|
|
|
* @since 2014.03 |
|
56
|
|
|
* @category Developer |
|
57
|
|
|
*/ |
|
58
|
|
|
private $subPartPath = 'client/html/account/favorite/standard/subparts'; |
|
59
|
|
|
private $subPartNames = []; |
|
60
|
|
|
private $view; |
|
61
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Returns the HTML code for insertion into the body. |
|
65
|
|
|
* |
|
66
|
|
|
* @param string $uid Unique identifier for the output if the content is placed more than once on the same page |
|
67
|
|
|
* @return string HTML code |
|
68
|
|
|
*/ |
|
69
|
|
|
public function getBody( $uid = '' ) |
|
70
|
|
|
{ |
|
71
|
|
|
$context = $this->getContext(); |
|
72
|
|
|
$view = $this->getView(); |
|
73
|
|
|
|
|
74
|
|
|
try |
|
75
|
|
|
{ |
|
76
|
|
|
if( !isset( $this->view ) ) { |
|
77
|
|
|
$view = $this->view = $this->getObject()->addData( $view ); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
$html = ''; |
|
81
|
|
|
foreach( $this->getSubClients() as $subclient ) { |
|
82
|
|
|
$html .= $subclient->setView( $view )->getBody( $uid ); |
|
83
|
|
|
} |
|
84
|
|
|
$view->favoriteBody = $html; |
|
85
|
|
|
} |
|
86
|
|
|
catch( \Aimeos\Client\Html\Exception $e ) |
|
87
|
|
|
{ |
|
88
|
|
|
$error = array( $context->getI18n()->dt( 'client', $e->getMessage() ) ); |
|
89
|
|
|
$view->favoriteErrorList = $view->get( 'favoriteErrorList', [] ) + $error; |
|
90
|
|
|
} |
|
91
|
|
|
catch( \Aimeos\Controller\Frontend\Exception $e ) |
|
92
|
|
|
{ |
|
93
|
|
|
$error = array( $context->getI18n()->dt( 'controller/frontend', $e->getMessage() ) ); |
|
94
|
|
|
$view->favoriteErrorList = $view->get( 'favoriteErrorList', [] ) + $error; |
|
95
|
|
|
} |
|
96
|
|
|
catch( \Aimeos\MShop\Exception $e ) |
|
97
|
|
|
{ |
|
98
|
|
|
$error = array( $context->getI18n()->dt( 'mshop', $e->getMessage() ) ); |
|
99
|
|
|
$view->favoriteErrorList = $view->get( 'favoriteErrorList', [] ) + $error; |
|
100
|
|
|
} |
|
101
|
|
|
catch( \Exception $e ) |
|
102
|
|
|
{ |
|
103
|
|
|
$error = array( $context->getI18n()->dt( 'client', 'A non-recoverable error occured' ) ); |
|
104
|
|
|
$view->favoriteErrorList = $view->get( 'favoriteErrorList', [] ) + $error; |
|
105
|
|
|
$this->logException( $e ); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** client/html/account/favorite/standard/template-body |
|
109
|
|
|
* Relative path to the HTML body template of the account favorite client. |
|
110
|
|
|
* |
|
111
|
|
|
* The template file contains the HTML code and processing instructions |
|
112
|
|
|
* to generate the result shown in the body of the frontend. The |
|
113
|
|
|
* configuration string is the path to the template file relative |
|
114
|
|
|
* to the templates directory (usually in client/html/templates). |
|
115
|
|
|
* |
|
116
|
|
|
* You can overwrite the template file configuration in extensions and |
|
117
|
|
|
* provide alternative templates. These alternative templates should be |
|
118
|
|
|
* named like the default one but with the string "standard" replaced by |
|
119
|
|
|
* an unique name. You may use the name of your project for this. If |
|
120
|
|
|
* you've implemented an alternative client class as well, "standard" |
|
121
|
|
|
* should be replaced by the name of the new class. |
|
122
|
|
|
* |
|
123
|
|
|
* @param string Relative path to the template creating code for the HTML page body |
|
124
|
|
|
* @since 2014.03 |
|
125
|
|
|
* @category Developer |
|
126
|
|
|
* @see client/html/account/favorite/standard/template-header |
|
127
|
|
|
*/ |
|
128
|
|
|
$tplconf = 'client/html/account/favorite/standard/template-body'; |
|
129
|
|
|
$default = 'account/favorite/body-standard'; |
|
130
|
|
|
|
|
131
|
|
|
return $view->render( $view->config( $tplconf, $default ) ); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* Returns the HTML string for insertion into the header. |
|
137
|
|
|
* |
|
138
|
|
|
* @param string $uid Unique identifier for the output if the content is placed more than once on the same page |
|
139
|
|
|
* @return string|null String including HTML tags for the header on error |
|
140
|
|
|
*/ |
|
141
|
|
|
public function getHeader( $uid = '' ) |
|
142
|
|
|
{ |
|
143
|
|
|
$view = $this->getView(); |
|
144
|
|
|
|
|
145
|
|
|
try |
|
146
|
|
|
{ |
|
147
|
|
|
if( !isset( $this->view ) ) { |
|
148
|
|
|
$view = $this->view = $this->getObject()->addData( $view ); |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
$html = ''; |
|
152
|
|
|
foreach( $this->getSubClients() as $subclient ) { |
|
153
|
|
|
$html .= $subclient->setView( $view )->getHeader( $uid ); |
|
154
|
|
|
} |
|
155
|
|
|
$view->favoriteHeader = $html; |
|
156
|
|
|
|
|
157
|
|
|
/** client/html/account/favorite/standard/template-header |
|
158
|
|
|
* Relative path to the HTML header template of the account favorite client. |
|
159
|
|
|
* |
|
160
|
|
|
* The template file contains the HTML code and processing instructions |
|
161
|
|
|
* to generate the HTML code that is inserted into the HTML page header |
|
162
|
|
|
* of the rendered page in the frontend. The configuration string is the |
|
163
|
|
|
* path to the template file relative to the templates directory (usually |
|
164
|
|
|
* in client/html/templates). |
|
165
|
|
|
* |
|
166
|
|
|
* You can overwrite the template file configuration in extensions and |
|
167
|
|
|
* provide alternative templates. These alternative templates should be |
|
168
|
|
|
* named like the default one but with the string "standard" replaced by |
|
169
|
|
|
* an unique name. You may use the name of your project for this. If |
|
170
|
|
|
* you've implemented an alternative client class as well, "standard" |
|
171
|
|
|
* should be replaced by the name of the new class. |
|
172
|
|
|
* |
|
173
|
|
|
* @param string Relative path to the template creating code for the HTML page head |
|
174
|
|
|
* @since 2014.03 |
|
175
|
|
|
* @category Developer |
|
176
|
|
|
* @see client/html/account/favorite/standard/template-body |
|
177
|
|
|
*/ |
|
178
|
|
|
$tplconf = 'client/html/account/favorite/standard/template-header'; |
|
179
|
|
|
$default = 'account/favorite/header-standard'; |
|
180
|
|
|
|
|
181
|
|
|
return $view->render( $view->config( $tplconf, $default ) ); |
|
182
|
|
|
} |
|
183
|
|
|
catch( \Exception $e ) |
|
184
|
|
|
{ |
|
185
|
|
|
$this->logException( $e ); |
|
186
|
|
|
} |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
|
|
190
|
|
|
/** |
|
191
|
|
|
* Returns the sub-client given by its name. |
|
192
|
|
|
* |
|
193
|
|
|
* @param string $type Name of the client type |
|
194
|
|
|
* @param string|null $name Name of the sub-client (Default if null) |
|
195
|
|
|
* @return \Aimeos\Client\Html\Iface Sub-client object |
|
196
|
|
|
*/ |
|
197
|
|
|
public function getSubClient( $type, $name = null ) |
|
198
|
|
|
{ |
|
199
|
|
|
/** client/html/account/favorite/decorators/excludes |
|
200
|
|
|
* Excludes decorators added by the "common" option from the account favorite html client |
|
201
|
|
|
* |
|
202
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
|
203
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
|
204
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
|
205
|
|
|
* modify what is returned to the caller. |
|
206
|
|
|
* |
|
207
|
|
|
* This option allows you to remove a decorator added via |
|
208
|
|
|
* "client/html/common/decorators/default" before they are wrapped |
|
209
|
|
|
* around the html client. |
|
210
|
|
|
* |
|
211
|
|
|
* client/html/account/favorite/decorators/excludes = array( 'decorator1' ) |
|
212
|
|
|
* |
|
213
|
|
|
* This would remove the decorator named "decorator1" from the list of |
|
214
|
|
|
* common decorators ("\Aimeos\Client\Html\Common\Decorator\*") added via |
|
215
|
|
|
* "client/html/common/decorators/default" to the html client. |
|
216
|
|
|
* |
|
217
|
|
|
* @param array List of decorator names |
|
218
|
|
|
* @since 2014.05 |
|
219
|
|
|
* @category Developer |
|
220
|
|
|
* @see client/html/common/decorators/default |
|
221
|
|
|
* @see client/html/account/favorite/decorators/global |
|
222
|
|
|
* @see client/html/account/favorite/decorators/local |
|
223
|
|
|
*/ |
|
224
|
|
|
|
|
225
|
|
|
/** client/html/account/favorite/decorators/global |
|
226
|
|
|
* Adds a list of globally available decorators only to the account favorite html client |
|
227
|
|
|
* |
|
228
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
|
229
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
|
230
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
|
231
|
|
|
* modify what is returned to the caller. |
|
232
|
|
|
* |
|
233
|
|
|
* This option allows you to wrap global decorators |
|
234
|
|
|
* ("\Aimeos\Client\Html\Common\Decorator\*") around the html client. |
|
235
|
|
|
* |
|
236
|
|
|
* client/html/account/favorite/decorators/global = array( 'decorator1' ) |
|
237
|
|
|
* |
|
238
|
|
|
* This would add the decorator named "decorator1" defined by |
|
239
|
|
|
* "\Aimeos\Client\Html\Common\Decorator\Decorator1" only to the html client. |
|
240
|
|
|
* |
|
241
|
|
|
* @param array List of decorator names |
|
242
|
|
|
* @since 2014.05 |
|
243
|
|
|
* @category Developer |
|
244
|
|
|
* @see client/html/common/decorators/default |
|
245
|
|
|
* @see client/html/account/favorite/decorators/excludes |
|
246
|
|
|
* @see client/html/account/favorite/decorators/local |
|
247
|
|
|
*/ |
|
248
|
|
|
|
|
249
|
|
|
/** client/html/account/favorite/decorators/local |
|
250
|
|
|
* Adds a list of local decorators only to the account favorite html client |
|
251
|
|
|
* |
|
252
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
|
253
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
|
254
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
|
255
|
|
|
* modify what is returned to the caller. |
|
256
|
|
|
* |
|
257
|
|
|
* This option allows you to wrap local decorators |
|
258
|
|
|
* ("\Aimeos\Client\Html\Account\Decorator\*") around the html client. |
|
259
|
|
|
* |
|
260
|
|
|
* client/html/account/favorite/decorators/local = array( 'decorator2' ) |
|
261
|
|
|
* |
|
262
|
|
|
* This would add the decorator named "decorator2" defined by |
|
263
|
|
|
* "\Aimeos\Client\Html\Account\Decorator\Decorator2" only to the html client. |
|
264
|
|
|
* |
|
265
|
|
|
* @param array List of decorator names |
|
266
|
|
|
* @since 2014.05 |
|
267
|
|
|
* @category Developer |
|
268
|
|
|
* @see client/html/common/decorators/default |
|
269
|
|
|
* @see client/html/account/favorite/decorators/excludes |
|
270
|
|
|
* @see client/html/account/favorite/decorators/global |
|
271
|
|
|
*/ |
|
272
|
|
|
return $this->createSubClient( 'account/favorite/' . $type, $name ); |
|
273
|
|
|
} |
|
274
|
|
|
|
|
275
|
|
|
|
|
276
|
|
|
/** |
|
277
|
|
|
* Processes the input, e.g. store given values. |
|
278
|
|
|
* A view must be available and this method doesn't generate any output |
|
279
|
|
|
* besides setting view variables. |
|
280
|
|
|
*/ |
|
281
|
|
|
public function process() |
|
282
|
|
|
{ |
|
283
|
|
|
$view = $this->getView(); |
|
284
|
|
|
$context = $this->getContext(); |
|
285
|
|
|
$userId = $context->getUserId(); |
|
286
|
|
|
$ids = (array) $view->param( 'fav_id', [] ); |
|
287
|
|
|
|
|
288
|
|
|
try |
|
289
|
|
|
{ |
|
290
|
|
|
if( $userId != null && !empty( $ids ) ) |
|
291
|
|
|
{ |
|
292
|
|
|
switch( $view->param( 'fav_action' ) ) |
|
293
|
|
|
{ |
|
294
|
|
|
case 'add': |
|
295
|
|
|
$this->addFavorites( $ids, $userId ); break; |
|
296
|
|
|
case 'delete': |
|
297
|
|
|
$this->deleteFavorites( $ids, $userId ); break; |
|
298
|
|
|
} |
|
299
|
|
|
} |
|
300
|
|
|
|
|
301
|
|
|
parent::process(); |
|
302
|
|
|
} |
|
303
|
|
|
catch( \Aimeos\MShop\Exception $e ) |
|
304
|
|
|
{ |
|
305
|
|
|
$error = array( $context->getI18n()->dt( 'mshop', $e->getMessage() ) ); |
|
306
|
|
|
$view->favoriteErrorList = $view->get( 'favoriteErrorList', [] ) + $error; |
|
307
|
|
|
} |
|
308
|
|
|
catch( \Aimeos\Controller\Frontend\Exception $e ) |
|
309
|
|
|
{ |
|
310
|
|
|
$error = array( $context->getI18n()->dt( 'controller/frontend', $e->getMessage() ) ); |
|
311
|
|
|
$view->favoriteErrorList = $view->get( 'favoriteErrorList', [] ) + $error; |
|
312
|
|
|
} |
|
313
|
|
|
catch( \Aimeos\Client\Html\Exception $e ) |
|
314
|
|
|
{ |
|
315
|
|
|
$error = array( $context->getI18n()->dt( 'client', $e->getMessage() ) ); |
|
316
|
|
|
$view->favoriteErrorList = $view->get( 'favoriteErrorList', [] ) + $error; |
|
317
|
|
|
} |
|
318
|
|
|
catch( \Exception $e ) |
|
319
|
|
|
{ |
|
320
|
|
|
$error = array( $context->getI18n()->dt( 'client', 'A non-recoverable error occured' ) ); |
|
321
|
|
|
$view->favoriteErrorList = $view->get( 'favoriteErrorList', [] ) + $error; |
|
322
|
|
|
$this->logException( $e ); |
|
323
|
|
|
} |
|
324
|
|
|
} |
|
325
|
|
|
|
|
326
|
|
|
|
|
327
|
|
|
/** |
|
328
|
|
|
* Returns the customer list items referencing the favorite products |
|
329
|
|
|
* |
|
330
|
|
|
* @param array $ids List of product IDs |
|
331
|
|
|
* @param string $userId Unique customer ID |
|
332
|
|
|
* @param string $type Type of the list item |
|
333
|
|
|
* @return array Associative list of product IDs as keys and list items as values |
|
334
|
|
|
*/ |
|
335
|
|
|
protected function getListItems( array $ids, $userId, $type ) |
|
336
|
|
|
{ |
|
337
|
|
|
$context = $this->getContext(); |
|
338
|
|
|
$manager = \Aimeos\MShop::create( $context, 'customer/lists' ); |
|
339
|
|
|
|
|
340
|
|
|
$search = $manager->createSearch(); |
|
341
|
|
|
$expr = array( |
|
342
|
|
|
$search->compare( '==', 'customer.lists.parentid', $userId ), |
|
343
|
|
|
$search->compare( '==', 'customer.lists.refid', $ids ), |
|
344
|
|
|
$search->compare( '==', 'customer.lists.domain', 'product' ), |
|
345
|
|
|
$search->compare( '==', 'customer.lists.type', $type ), |
|
346
|
|
|
); |
|
347
|
|
|
$search->setConditions( $search->combine( '&&', $expr ) ); |
|
348
|
|
|
|
|
349
|
|
|
$items = []; |
|
350
|
|
|
foreach( $manager->searchItems( $search ) as $item ) { |
|
351
|
|
|
$items[$item->getRefId()] = $item; |
|
|
|
|
|
|
352
|
|
|
} |
|
353
|
|
|
|
|
354
|
|
|
return $items; |
|
355
|
|
|
} |
|
356
|
|
|
|
|
357
|
|
|
|
|
358
|
|
|
/** |
|
359
|
|
|
* Adds new product favorite references to the given customer |
|
360
|
|
|
* |
|
361
|
|
|
* @param array $ids List of product IDs |
|
362
|
|
|
* @param string $userId Unique customer ID |
|
363
|
|
|
*/ |
|
364
|
|
|
protected function addFavorites( array $ids, $userId ) |
|
365
|
|
|
{ |
|
366
|
|
|
$context = $this->getContext(); |
|
367
|
|
|
$manager = \Aimeos\MShop::create( $context, 'customer/lists' ); |
|
368
|
|
|
$listItems = $this->getListItems( $ids, $userId, 'favorite' ); |
|
369
|
|
|
|
|
370
|
|
|
$item = $manager->createItem(); |
|
371
|
|
|
$item->setDomain( 'product' ); |
|
372
|
|
|
$item->setParentId( $userId ); |
|
|
|
|
|
|
373
|
|
|
$item->setType( 'favorite' ); |
|
374
|
|
|
$item->setStatus( 1 ); |
|
375
|
|
|
|
|
376
|
|
|
foreach( $ids as $id ) |
|
377
|
|
|
{ |
|
378
|
|
|
if( !isset( $listItems[$id] ) ) |
|
379
|
|
|
{ |
|
380
|
|
|
$item->setId( null ); |
|
381
|
|
|
$item->setRefId( $id ); |
|
|
|
|
|
|
382
|
|
|
|
|
383
|
|
|
$item = $manager->saveItem( $item ); |
|
384
|
|
|
$manager->moveItem( $item->getId() ); |
|
|
|
|
|
|
385
|
|
|
} |
|
386
|
|
|
} |
|
387
|
|
|
} |
|
388
|
|
|
|
|
389
|
|
|
|
|
390
|
|
|
/** |
|
391
|
|
|
* Removes product favorite references from the customer |
|
392
|
|
|
* |
|
393
|
|
|
* @param array $ids List of product IDs |
|
394
|
|
|
* @param string $userId Unique customer ID |
|
395
|
|
|
*/ |
|
396
|
|
|
protected function deleteFavorites( array $ids, $userId ) |
|
397
|
|
|
{ |
|
398
|
|
|
$listIds = []; |
|
399
|
|
|
$context = $this->getContext(); |
|
400
|
|
|
$manager = \Aimeos\MShop::create( $context, 'customer/lists' ); |
|
401
|
|
|
|
|
402
|
|
|
$listItems = $this->getListItems( $ids, $userId, 'favorite' ); |
|
403
|
|
|
|
|
404
|
|
|
foreach( $ids as $id ) |
|
405
|
|
|
{ |
|
406
|
|
|
if( isset( $listItems[$id] ) ) { |
|
407
|
|
|
$listIds[] = $listItems[$id]->getId(); |
|
408
|
|
|
} |
|
409
|
|
|
} |
|
410
|
|
|
|
|
411
|
|
|
$manager->deleteItems( $listIds ); |
|
412
|
|
|
} |
|
413
|
|
|
|
|
414
|
|
|
|
|
415
|
|
|
/** |
|
416
|
|
|
* Returns the list of sub-client names configured for the client. |
|
417
|
|
|
* |
|
418
|
|
|
* @return array List of HTML client names |
|
419
|
|
|
*/ |
|
420
|
|
|
protected function getSubClientNames() |
|
421
|
|
|
{ |
|
422
|
|
|
return $this->getContext()->getConfig()->get( $this->subPartPath, $this->subPartNames ); |
|
423
|
|
|
} |
|
424
|
|
|
|
|
425
|
|
|
|
|
426
|
|
|
/** |
|
427
|
|
|
* Returns the sanitized page from the parameters for the product list. |
|
428
|
|
|
* |
|
429
|
|
|
* @param \Aimeos\MW\View\Iface $view View instance with helper for retrieving the required parameters |
|
430
|
|
|
* @return integer Page number starting from 1 |
|
431
|
|
|
*/ |
|
432
|
|
|
protected function getProductListPage( \Aimeos\MW\View\Iface $view ) |
|
433
|
|
|
{ |
|
434
|
|
|
$page = (int) $view->param( 'fav_page', 1 ); |
|
435
|
|
|
return ( $page < 1 ? 1 : $page ); |
|
436
|
|
|
} |
|
437
|
|
|
|
|
438
|
|
|
|
|
439
|
|
|
/** |
|
440
|
|
|
* Returns the sanitized page size from the parameters for the product list. |
|
441
|
|
|
* |
|
442
|
|
|
* @param \Aimeos\MW\View\Iface $view View instance with helper for retrieving the required parameters |
|
443
|
|
|
* @return integer Page size |
|
444
|
|
|
*/ |
|
445
|
|
|
protected function getProductListSize( \Aimeos\MW\View\Iface $view ) |
|
446
|
|
|
{ |
|
447
|
|
|
/** client/html/account/favorite/size |
|
448
|
|
|
* The number of products shown in a list page for favorite products |
|
449
|
|
|
* |
|
450
|
|
|
* Limits the number of products that is shown in the list pages to the |
|
451
|
|
|
* given value. If more products are available, the products are split |
|
452
|
|
|
* into bunches which will be shown on their own list page. The user is |
|
453
|
|
|
* able to move to the next page (or previous one if it's not the first) |
|
454
|
|
|
* to display the next (or previous) products. |
|
455
|
|
|
* |
|
456
|
|
|
* The value must be an integer number from 1 to 100. Negative values as |
|
457
|
|
|
* well as values above 100 are not allowed. The value can be overwritten |
|
458
|
|
|
* per request if the "l_size" parameter is part of the URL. |
|
459
|
|
|
* |
|
460
|
|
|
* @param integer Number of products |
|
461
|
|
|
* @since 2014.09 |
|
462
|
|
|
* @category User |
|
463
|
|
|
* @category Developer |
|
464
|
|
|
* @see client/html/catalog/lists/size |
|
465
|
|
|
*/ |
|
466
|
|
|
$defaultSize = $this->getContext()->getConfig()->get( 'client/html/account/favorite/size', 48 ); |
|
467
|
|
|
|
|
468
|
|
|
$size = (int) $view->param( 'fav-size', $defaultSize ); |
|
469
|
|
|
return ( $size < 1 || $size > 100 ? $defaultSize : $size ); |
|
470
|
|
|
} |
|
471
|
|
|
|
|
472
|
|
|
|
|
473
|
|
|
/** |
|
474
|
|
|
* Sets the necessary parameter values in the view. |
|
475
|
|
|
* |
|
476
|
|
|
* @param \Aimeos\MW\View\Iface $view The view object which generates the HTML output |
|
477
|
|
|
* @param array &$tags Result array for the list of tags that are associated to the output |
|
478
|
|
|
* @param string|null &$expire Result variable for the expiration date of the output (null for no expiry) |
|
479
|
|
|
* @return \Aimeos\MW\View\Iface Modified view object |
|
480
|
|
|
*/ |
|
481
|
|
|
public function addData( \Aimeos\MW\View\Iface $view, array &$tags = [], &$expire = null ) |
|
482
|
|
|
{ |
|
483
|
|
|
$total = 0; |
|
484
|
|
|
$productIds = []; |
|
485
|
|
|
$context = $this->getContext(); |
|
486
|
|
|
|
|
487
|
|
|
$size = $this->getProductListSize( $view ); |
|
488
|
|
|
$current = $this->getProductListPage( $view ); |
|
489
|
|
|
$last = ( $total != 0 ? ceil( $total / $size ) : 1 ); |
|
|
|
|
|
|
490
|
|
|
|
|
491
|
|
|
|
|
492
|
|
|
$manager = \Aimeos\MShop::create( $context, 'customer/lists' ); |
|
493
|
|
|
|
|
494
|
|
|
$search = $manager->createSearch(); |
|
495
|
|
|
$expr = array( |
|
496
|
|
|
$search->compare( '==', 'customer.lists.parentid', $context->getUserId() ), |
|
497
|
|
|
$search->compare( '==', 'customer.lists.domain', 'product' ), |
|
498
|
|
|
$search->compare( '==', 'customer.lists.type', 'favorite' ), |
|
499
|
|
|
); |
|
500
|
|
|
$search->setConditions( $search->combine( '&&', $expr ) ); |
|
501
|
|
|
$search->setSortations( array( $search->sort( '-', 'customer.lists.position' ) ) ); |
|
502
|
|
|
$search->setSlice( ( $current - 1 ) * $size, $size ); |
|
503
|
|
|
|
|
504
|
|
|
$view->favoriteListItems = $manager->searchItems( $search, [], $total ); |
|
505
|
|
|
|
|
506
|
|
|
|
|
507
|
|
|
/** client/html/account/favorite/domains |
|
508
|
|
|
* A list of domain names whose items should be available in the account favorite view template |
|
509
|
|
|
* |
|
510
|
|
|
* The templates rendering product details usually add the images, |
|
511
|
|
|
* prices and texts associated to the product item. If you want to |
|
512
|
|
|
* display additional or less content, you can configure your own |
|
513
|
|
|
* list of domains (attribute, media, price, product, text, etc. are |
|
514
|
|
|
* domains) whose items are fetched from the storage. Please keep |
|
515
|
|
|
* in mind that the more domains you add to the configuration, the |
|
516
|
|
|
* more time is required for fetching the content! |
|
517
|
|
|
* |
|
518
|
|
|
* @param array List of domain names |
|
519
|
|
|
* @since 2014.09 |
|
520
|
|
|
* @category Developer |
|
521
|
|
|
* @see client/html/catalog/domains |
|
522
|
|
|
*/ |
|
523
|
|
|
$default = array( 'text', 'price', 'media' ); |
|
524
|
|
|
$domains = $context->getConfig()->get( 'client/html/account/favorite/domains', $default ); |
|
525
|
|
|
|
|
526
|
|
|
foreach( $view->favoriteListItems as $listItem ) { |
|
527
|
|
|
$productIds[] = $listItem->getRefId(); |
|
528
|
|
|
} |
|
529
|
|
|
|
|
530
|
|
|
$cntl = \Aimeos\Controller\Frontend::create( $context, 'product' ); |
|
531
|
|
|
|
|
532
|
|
|
$view->favoriteProductItems = $cntl->product( $productIds )->search( $domains ); |
|
|
|
|
|
|
533
|
|
|
$view->favoritePageFirst = 1; |
|
534
|
|
|
$view->favoritePagePrev = ( $current > 1 ? $current - 1 : 1 ); |
|
535
|
|
|
$view->favoritePageNext = ( $current < $last ? $current + 1 : $last ); |
|
536
|
|
|
$view->favoritePageLast = $last; |
|
537
|
|
|
$view->favoritePageCurr = $current; |
|
538
|
|
|
|
|
539
|
|
|
return parent::addData( $view, $tags, $expire ); |
|
540
|
|
|
} |
|
541
|
|
|
} |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.