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-2025 |
7
|
|
|
* @package Client |
8
|
|
|
* @subpackage Html |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
namespace Aimeos\Client\Html\Account\Watch; |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Default implementation of account watch 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/watch/name |
26
|
|
|
* Class name of the used account watch client implementation |
27
|
|
|
* |
28
|
|
|
* Each default HTML client can be replace by an alternative imlementation. |
29
|
|
|
* To use this implementation, you have to set the last part of the class |
30
|
|
|
* name as configuration value so the client factory knows which class it |
31
|
|
|
* has to instantiate. |
32
|
|
|
* |
33
|
|
|
* For example, if the name of the default class is |
34
|
|
|
* |
35
|
|
|
* \Aimeos\Client\Html\Account\Watch\Standard |
36
|
|
|
* |
37
|
|
|
* and you want to replace it with your own version named |
38
|
|
|
* |
39
|
|
|
* \Aimeos\Client\Html\Account\Watch\Mywatch |
40
|
|
|
* |
41
|
|
|
* then you have to set the this configuration option: |
42
|
|
|
* |
43
|
|
|
* client/html/account/watch/name = Mywatch |
44
|
|
|
* |
45
|
|
|
* The value is the last part of your own class name and it's case sensitive, |
46
|
|
|
* so take care that the configuration value is exactly named like the last |
47
|
|
|
* part of the class name. |
48
|
|
|
* |
49
|
|
|
* The allowed characters of the class name are A-Z, a-z and 0-9. No other |
50
|
|
|
* characters are possible! You should always start the last part of the class |
51
|
|
|
* name with an upper case character and continue only with lower case characters |
52
|
|
|
* or numbers. Avoid chamel case names like "MyWatch"! |
53
|
|
|
* |
54
|
|
|
* @param string Last part of the class name |
55
|
|
|
* @since 2015.10 |
56
|
|
|
*/ |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Processes the input, e.g. store given values. |
61
|
|
|
* |
62
|
|
|
* A view must be available and this method doesn't generate any output |
63
|
|
|
* besides setting view variables if necessary. |
64
|
|
|
*/ |
65
|
|
|
public function init() |
66
|
|
|
{ |
67
|
|
|
$view = $this->view(); |
68
|
|
|
$context = $this->context(); |
69
|
|
|
$ids = (array) $view->param( 'wat_id', [] ); |
70
|
|
|
|
71
|
|
|
if( $context->user() !== null && !empty( $ids ) && $view->request()->getMethod() === 'POST' ) |
72
|
|
|
{ |
73
|
|
|
switch( $view->param( 'wat_action' ) ) |
74
|
|
|
{ |
75
|
|
|
case 'add': |
76
|
|
|
$this->addItems( $view, $ids ); break; |
77
|
|
|
case 'edit': |
78
|
|
|
$this->editItems( $view, $ids ); break; |
79
|
|
|
case 'delete': |
80
|
|
|
$this->deleteItems( $view, $ids ); break; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Adds one or more list items to the given customer item |
88
|
|
|
* |
89
|
|
|
* @param \Aimeos\Base\View\Iface $view View object |
90
|
|
|
* @param array $ids List of referenced IDs |
91
|
|
|
*/ |
92
|
|
|
protected function addItems( \Aimeos\Base\View\Iface $view, array $ids ) |
93
|
|
|
{ |
94
|
|
|
$context = $this->context(); |
95
|
|
|
|
96
|
|
|
/** client/html/account/watch/maxitems |
97
|
|
|
* Maximum number of products that can be watched in parallel |
98
|
|
|
* |
99
|
|
|
* This option limits the number of products that can be watched |
100
|
|
|
* after the users added the products to their watch list. |
101
|
|
|
* It must be a positive integer value greater than 0. |
102
|
|
|
* |
103
|
|
|
* Note: It's recommended to set this value not too high as this |
104
|
|
|
* leads to a high memory consumption when the e-mails are generated |
105
|
|
|
* to notify the customers. The memory used will up to 100*maxitems |
106
|
|
|
* of the footprint of one product item including the associated |
107
|
|
|
* texts, prices and media. |
108
|
|
|
* |
109
|
|
|
* @param integer Number of products |
110
|
|
|
* @since 2014.09 |
111
|
|
|
*/ |
112
|
|
|
$max = $context->config()->get( 'client/html/account/watch/maxitems', 100 ); |
113
|
|
|
|
114
|
|
|
$cntl = \Aimeos\Controller\Frontend::create( $context, 'customer' ); |
115
|
|
|
$item = $cntl->uses( ['product' => ['watch']] )->get(); |
116
|
|
|
|
117
|
|
|
if( count( $item->getRefItems( 'product', null, 'watch' ) ) + count( $ids ) > $max ) |
118
|
|
|
{ |
119
|
|
|
$msg = sprintf( $context->translate( 'client', 'You can only watch up to %1$s products' ), $max ); |
120
|
|
|
throw new \Aimeos\Client\Html\Exception( $msg ); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
foreach( $ids as $id ) |
124
|
|
|
{ |
125
|
|
|
if( ( $listItem = $item->getListItem( 'product', 'watch', $id ) ) === null ) { |
126
|
|
|
$listItem = $cntl->createListItem(); |
127
|
|
|
} |
128
|
|
|
$cntl->addListItem( 'product', $listItem->setType( 'watch' )->setRefId( $id ) ); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
$cntl->store(); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Removes the referencing list items from the given item |
137
|
|
|
* |
138
|
|
|
* @param \Aimeos\Base\View\Iface $view View object |
139
|
|
|
* @param array $ids List of referenced IDs |
140
|
|
|
*/ |
141
|
|
|
protected function deleteItems( \Aimeos\Base\View\Iface $view, array $ids ) |
142
|
|
|
{ |
143
|
|
|
$cntl = \Aimeos\Controller\Frontend::create( $this->context(), 'customer' ); |
144
|
|
|
$item = $cntl->uses( ['product' => ['watch']] )->get(); |
145
|
|
|
|
146
|
|
|
foreach( $ids as $id ) |
147
|
|
|
{ |
148
|
|
|
if( ( $listItem = $item->getListItem( 'product', 'watch', $id ) ) !== null ) { |
149
|
|
|
$cntl->deleteListItem( 'product', $listItem ); |
150
|
|
|
} |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
$cntl->store(); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Updates the item using the given reference IDs |
159
|
|
|
* |
160
|
|
|
* @param \Aimeos\Base\View\Iface $view View object |
161
|
|
|
* @param array $ids List of referenced IDs |
162
|
|
|
*/ |
163
|
|
|
protected function editItems( \Aimeos\Base\View\Iface $view, array $ids ) |
164
|
|
|
{ |
165
|
|
|
$context = $this->context(); |
166
|
|
|
$cntl = \Aimeos\Controller\Frontend::create( $context, 'customer' ); |
167
|
|
|
$item = $cntl->uses( ['product' => ['watch']] )->get(); |
168
|
|
|
|
169
|
|
|
$config = [ |
170
|
|
|
'timeframe' => $view->param( 'wat_timeframe', 7 ), |
171
|
|
|
'pricevalue' => $view->param( 'wat_pricevalue', '0.00' ), |
172
|
|
|
'price' => $view->param( 'wat_price', 0 ), |
173
|
|
|
'stock' => $view->param( 'wat_stock', 0 ), |
174
|
|
|
'currency' => $context->locale()->getCurrencyId(), |
175
|
|
|
]; |
176
|
|
|
|
177
|
|
|
foreach( $ids as $id ) |
178
|
|
|
{ |
179
|
|
|
if( ( $listItem = $item->getListItem( 'product', 'watch', $id ) ) !== null ) |
180
|
|
|
{ |
181
|
|
|
$time = time() + ( $config['timeframe'] + 1 ) * 86400; |
182
|
|
|
$listItem = $listItem->setDateEnd( date( 'Y-m-d 00:00:00', $time ) )->setConfig( $config ); |
183
|
|
|
|
184
|
|
|
$cntl->addListItem( 'product', $listItem ); |
185
|
|
|
} |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
$cntl->store(); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* Returns the sanitized page from the parameters for the product list. |
194
|
|
|
* |
195
|
|
|
* @param \Aimeos\Base\View\Iface $view View instance with helper for retrieving the required parameters |
196
|
|
|
* @return integer Page number starting from 1 |
197
|
|
|
*/ |
198
|
|
|
protected function getProductListPage( \Aimeos\Base\View\Iface $view ) : int |
199
|
|
|
{ |
200
|
|
|
$page = (int) $view->param( 'wat_page', 1 ); |
201
|
|
|
return ( $page < 1 ? 1 : $page ); |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* Returns the sanitized page size from the parameters for the product list. |
207
|
|
|
* |
208
|
|
|
* @param \Aimeos\Base\View\Iface $view View instance with helper for retrieving the required parameters |
209
|
|
|
* @return integer Page size |
210
|
|
|
*/ |
211
|
|
|
protected function getProductListSize( \Aimeos\Base\View\Iface $view ) : int |
212
|
|
|
{ |
213
|
|
|
/** client/html/account/watch/size |
214
|
|
|
* The number of products shown in a list page for watch products |
215
|
|
|
* |
216
|
|
|
* Limits the number of products that is shown in the list pages to the |
217
|
|
|
* given value. If more products are available, the products are split |
218
|
|
|
* into bunches which will be shown on their own list page. The user is |
219
|
|
|
* able to move to the next page (or previous one if it's not the first) |
220
|
|
|
* to display the next (or previous) products. |
221
|
|
|
* |
222
|
|
|
* The value must be an integer number from 1 to 100. Negative values as |
223
|
|
|
* well as values above 100 are not allowed. The value can be overwritten |
224
|
|
|
* per request if the "l_size" parameter is part of the URL. |
225
|
|
|
* |
226
|
|
|
* @param integer Number of products |
227
|
|
|
* @since 2014.09 |
228
|
|
|
* @see client/html/catalog/lists/size |
229
|
|
|
*/ |
230
|
|
|
$defaultSize = $this->context()->config()->get( 'client/html/account/watch/size', 48 ); |
231
|
|
|
|
232
|
|
|
$size = (int) $view->param( 'watch-size', $defaultSize ); |
233
|
|
|
return ( $size < 1 || $size > 100 ? $defaultSize : $size ); |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* Sets the necessary parameter values in the view. |
239
|
|
|
* |
240
|
|
|
* @param \Aimeos\Base\View\Iface $view The view object which generates the HTML output |
241
|
|
|
* @param array &$tags Result array for the list of tags that are associated to the output |
242
|
|
|
* @param string|null &$expire Result variable for the expiration date of the output (null for no expiry) |
243
|
|
|
* @return \Aimeos\Base\View\Iface Modified view object |
244
|
|
|
*/ |
245
|
|
|
public function data( \Aimeos\Base\View\Iface $view, array &$tags = [], ?string &$expire = null ) : \Aimeos\Base\View\Iface |
246
|
|
|
{ |
247
|
|
|
$context = $this->context(); |
248
|
|
|
|
249
|
|
|
/** client/html/account/watch/domains |
250
|
|
|
* A list of domain names whose items should be available in the account watch view template |
251
|
|
|
* |
252
|
|
|
* The templates rendering product details usually add the images, |
253
|
|
|
* prices and texts associated to the product item. If you want to |
254
|
|
|
* display additional or less content, you can configure your own |
255
|
|
|
* list of domains (attribute, media, price, product, text, etc. are |
256
|
|
|
* domains) whose items are fetched from the storage. Please keep |
257
|
|
|
* in mind that the more domains you add to the configuration, the |
258
|
|
|
* more time is required for fetching the content! |
259
|
|
|
* |
260
|
|
|
* @param array List of domain names |
261
|
|
|
* @since 2014.09 |
262
|
|
|
* @see client/html/catalog/domains |
263
|
|
|
*/ |
264
|
|
|
$domains = $context->config()->get( 'client/html/account/watch/domains', ['catalog', 'text', 'price', 'media'] ); |
265
|
|
|
|
266
|
|
|
$cntl = \Aimeos\Controller\Frontend::create( $context, 'customer' ); |
267
|
|
|
$customer = $cntl->uses( ['product' => ['watch']] + $domains )->get(); |
268
|
|
|
|
269
|
|
|
$products = $customer->getRefItems( 'product', null, 'watch' ); |
270
|
|
|
$products = \Aimeos\MShop::create( $context, 'rule' )->apply( $products, 'catalog' ); |
|
|
|
|
271
|
|
|
|
272
|
|
|
$listItems = $customer->getListItems( 'product', 'watch' ); |
273
|
|
|
$total = count( $listItems ); |
274
|
|
|
|
275
|
|
|
$size = $this->getProductListSize( $view ); |
276
|
|
|
$current = $this->getProductListPage( $view ); |
277
|
|
|
$last = ( $total != 0 ? ceil( $total / $size ) : 1 ); |
278
|
|
|
|
279
|
|
|
$view->watchItems = $listItems; |
280
|
|
|
$view->watchPageFirst = 1; |
281
|
|
|
$view->watchPagePrev = ( $current > 1 ? $current - 1 : 1 ); |
282
|
|
|
$view->watchPageNext = ( $current < $last ? $current + 1 : $last ); |
283
|
|
|
$view->watchPageLast = $last; |
284
|
|
|
$view->watchPageCurr = $current; |
285
|
|
|
|
286
|
|
|
return parent::data( $view, $tags, $expire ); |
287
|
|
|
} |
288
|
|
|
|
289
|
|
|
/** client/html/account/watch/template-body |
290
|
|
|
* Relative path to the HTML body template of the account watch client. |
291
|
|
|
* |
292
|
|
|
* The template file contains the HTML code and processing instructions |
293
|
|
|
* to generate the result shown in the body of the frontend. The |
294
|
|
|
* configuration string is the path to the template file relative |
295
|
|
|
* to the templates directory (usually in templates/client/html). |
296
|
|
|
* |
297
|
|
|
* You can overwrite the template file configuration in extensions and |
298
|
|
|
* provide alternative templates. These alternative templates should be |
299
|
|
|
* named like the default one but suffixed by |
300
|
|
|
* an unique name. You may use the name of your project for this. If |
301
|
|
|
* you've implemented an alternative client class as well, it |
302
|
|
|
* should be suffixed by the name of the new class. |
303
|
|
|
* |
304
|
|
|
* @param string Relative path to the template creating code for the HTML page body |
305
|
|
|
* @since 2015.10 |
306
|
|
|
* @see client/html/account/watch/template-header |
307
|
|
|
*/ |
308
|
|
|
|
309
|
|
|
/** client/html/account/watch/template-header |
310
|
|
|
* Relative path to the HTML header template of the account watch client. |
311
|
|
|
* |
312
|
|
|
* The template file contains the HTML code and processing instructions |
313
|
|
|
* to generate the HTML code that is inserted into the HTML page header |
314
|
|
|
* of the rendered page in the frontend. The configuration string is the |
315
|
|
|
* path to the template file relative to the templates directory (usually |
316
|
|
|
* in templates/client/html). |
317
|
|
|
* |
318
|
|
|
* You can overwrite the template file configuration in extensions and |
319
|
|
|
* provide alternative templates. These alternative templates should be |
320
|
|
|
* named like the default one but suffixed by |
321
|
|
|
* an unique name. You may use the name of your project for this. If |
322
|
|
|
* you've implemented an alternative client class as well, it |
323
|
|
|
* should be suffixed by the name of the new class. |
324
|
|
|
* |
325
|
|
|
* @param string Relative path to the template creating code for the HTML page head |
326
|
|
|
* @since 2015.10 |
327
|
|
|
* @see client/html/account/watch/template-body |
328
|
|
|
*/ |
329
|
|
|
|
330
|
|
|
/** client/html/account/watch/decorators/excludes |
331
|
|
|
* Excludes decorators added by the "common" option from the account watch html client |
332
|
|
|
* |
333
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
334
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
335
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
336
|
|
|
* modify what is returned to the caller. |
337
|
|
|
* |
338
|
|
|
* This option allows you to remove a decorator added via |
339
|
|
|
* "client/html/common/decorators/default" before they are wrapped |
340
|
|
|
* around the html client. |
341
|
|
|
* |
342
|
|
|
* client/html/account/watch/decorators/excludes = array( 'decorator1' ) |
343
|
|
|
* |
344
|
|
|
* This would remove the decorator named "decorator1" from the list of |
345
|
|
|
* common decorators ("\Aimeos\Client\Html\Common\Decorator\*") added via |
346
|
|
|
* "client/html/common/decorators/default" to the html client. |
347
|
|
|
* |
348
|
|
|
* @param array List of decorator names |
349
|
|
|
* @see client/html/common/decorators/default |
350
|
|
|
* @see client/html/account/watch/decorators/global |
351
|
|
|
* @see client/html/account/watch/decorators/local |
352
|
|
|
*/ |
353
|
|
|
|
354
|
|
|
/** client/html/account/watch/decorators/global |
355
|
|
|
* Adds a list of globally available decorators only to the account watch html client |
356
|
|
|
* |
357
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
358
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
359
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
360
|
|
|
* modify what is returned to the caller. |
361
|
|
|
* |
362
|
|
|
* This option allows you to wrap global decorators |
363
|
|
|
* ("\Aimeos\Client\Html\Common\Decorator\*") around the html client. |
364
|
|
|
* |
365
|
|
|
* client/html/account/watch/decorators/global = array( 'decorator1' ) |
366
|
|
|
* |
367
|
|
|
* This would add the decorator named "decorator1" defined by |
368
|
|
|
* "\Aimeos\Client\Html\Common\Decorator\Decorator1" only to the html client. |
369
|
|
|
* |
370
|
|
|
* @param array List of decorator names |
371
|
|
|
* @see client/html/common/decorators/default |
372
|
|
|
* @see client/html/account/watch/decorators/excludes |
373
|
|
|
* @see client/html/account/watch/decorators/local |
374
|
|
|
*/ |
375
|
|
|
|
376
|
|
|
/** client/html/account/watch/decorators/local |
377
|
|
|
* Adds a list of local decorators only to the account watch html client |
378
|
|
|
* |
379
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
380
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
381
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
382
|
|
|
* modify what is returned to the caller. |
383
|
|
|
* |
384
|
|
|
* This option allows you to wrap local decorators |
385
|
|
|
* ("\Aimeos\Client\Html\Account\Decorator\*") around the html client. |
386
|
|
|
* |
387
|
|
|
* client/html/account/watch/decorators/local = array( 'decorator2' ) |
388
|
|
|
* |
389
|
|
|
* This would add the decorator named "decorator2" defined by |
390
|
|
|
* "\Aimeos\Client\Html\Account\Decorator\Decorator2" only to the html client. |
391
|
|
|
* |
392
|
|
|
* @param array List of decorator names |
393
|
|
|
* @see client/html/common/decorators/default |
394
|
|
|
* @see client/html/account/watch/decorators/excludes |
395
|
|
|
* @see client/html/account/watch/decorators/global |
396
|
|
|
*/ |
397
|
|
|
} |
398
|
|
|
|