1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2025 |
6
|
|
|
* @package Client |
7
|
|
|
* @subpackage Html |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
namespace Aimeos\Client\Html\Catalog\Detail; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Default implementation of catalog detail section HTML clients. |
16
|
|
|
* |
17
|
|
|
* @package Client |
18
|
|
|
* @subpackage Html |
19
|
|
|
*/ |
20
|
|
|
class Standard |
21
|
|
|
extends \Aimeos\Client\Html\Catalog\Base |
22
|
|
|
implements \Aimeos\Client\Html\Common\Client\Factory\Iface |
23
|
|
|
{ |
24
|
|
|
/** client/html/catalog/detail/name |
25
|
|
|
* Class name of the used catalog detail client implementation |
26
|
|
|
* |
27
|
|
|
* Each default HTML client can be replace by an alternative imlementation. |
28
|
|
|
* To use this implementation, you have to set the last part of the class |
29
|
|
|
* name as configuration value so the client factory knows which class it |
30
|
|
|
* has to instantiate. |
31
|
|
|
* |
32
|
|
|
* For example, if the name of the default class is |
33
|
|
|
* |
34
|
|
|
* \Aimeos\Client\Html\Catalog\Detail\Standard |
35
|
|
|
* |
36
|
|
|
* and you want to replace it with your own version named |
37
|
|
|
* |
38
|
|
|
* \Aimeos\Client\Html\Catalog\Detail\Mydetail |
39
|
|
|
* |
40
|
|
|
* then you have to set the this configuration option: |
41
|
|
|
* |
42
|
|
|
* client/html/catalog/detail/name = Mydetail |
43
|
|
|
* |
44
|
|
|
* The value is the last part of your own class name and it's case sensitive, |
45
|
|
|
* so take care that the configuration value is exactly named like the last |
46
|
|
|
* part of the class name. |
47
|
|
|
* |
48
|
|
|
* The allowed characters of the class name are A-Z, a-z and 0-9. No other |
49
|
|
|
* characters are possible! You should always start the last part of the class |
50
|
|
|
* name with an upper case character and continue only with lower case characters |
51
|
|
|
* or numbers. Avoid chamel case names like "MyDetail"! |
52
|
|
|
* |
53
|
|
|
* @param string Last part of the class name |
54
|
|
|
* @since 2014.03 |
55
|
|
|
*/ |
56
|
|
|
|
57
|
|
|
|
58
|
|
|
private array $tags = []; |
59
|
|
|
private ?string $expire = null; |
60
|
|
|
private ?\Aimeos\Base\View\Iface $view = null; |
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 body( string $uid = '' ) : string |
70
|
|
|
{ |
71
|
|
|
$view = $this->view(); |
72
|
|
|
$config = $this->context()->config(); |
73
|
|
|
$prefixes = ['d_prodid', 'd_name']; |
74
|
|
|
|
75
|
|
|
$code = $config->get( 'client/html/catalog/detail/prodcode-default' ); |
76
|
|
|
$id = $config->get( 'client/html/catalog/detail/prodid-default', $code ); |
77
|
|
|
|
78
|
|
|
if( !$view->param( 'd_name', $view->param( 'd_prodid', $id ) ) ) { |
79
|
|
|
return ''; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** client/html/catalog/detail/cache |
83
|
|
|
* Enables or disables caching only for the catalog detail component |
84
|
|
|
* |
85
|
|
|
* Disable caching for components can be useful if you would have too much |
86
|
|
|
* entries to cache or if the component contains non-cacheable parts that |
87
|
|
|
* can't be replaced using the modify() method. |
88
|
|
|
* |
89
|
|
|
* @param boolean True to enable caching, false to disable |
90
|
|
|
* @see client/html/catalog/filter/cache |
91
|
|
|
* @see client/html/catalog/lists/cache |
92
|
|
|
* @see client/html/catalog/stage/cache |
93
|
|
|
*/ |
94
|
|
|
|
95
|
|
|
/** client/html/catalog/detail |
96
|
|
|
* All parameters defined for the catalog detail component and its subparts |
97
|
|
|
* |
98
|
|
|
* This returns all settings related to the detail component. |
99
|
|
|
* Please refer to the single settings for details. |
100
|
|
|
* |
101
|
|
|
* @param array Associative list of name/value settings |
102
|
|
|
* @see client/html/catalog#detail |
103
|
|
|
*/ |
104
|
|
|
$confkey = 'client/html/catalog/detail'; |
105
|
|
|
|
106
|
|
|
if( $html = $this->cached( 'body', $uid, $prefixes, $confkey ) ) { |
107
|
|
|
return $this->modify( $html, $uid ); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** client/html/catalog/detail/template-body |
111
|
|
|
* Relative path to the HTML body template of the catalog detail client. |
112
|
|
|
* |
113
|
|
|
* The template file contains the HTML code and processing instructions |
114
|
|
|
* to generate the result shown in the body of the frontend. The |
115
|
|
|
* configuration string is the path to the template file relative |
116
|
|
|
* to the templates directory (usually in templates/client/html). |
117
|
|
|
* |
118
|
|
|
* You can overwrite the template file configuration in extensions and |
119
|
|
|
* provide alternative templates. These alternative templates should be |
120
|
|
|
* named like the default one but suffixed by |
121
|
|
|
* an unique name. You may use the name of your project for this. If |
122
|
|
|
* you've implemented an alternative client class as well, it |
123
|
|
|
* should be suffixed by the name of the new class. |
124
|
|
|
* |
125
|
|
|
* @param string Relative path to the template creating code for the HTML page body |
126
|
|
|
* @since 2014.03 |
127
|
|
|
* @see client/html/catalog/detail/template-header |
128
|
|
|
* @see client/html/catalog/detail/404 |
129
|
|
|
*/ |
130
|
|
|
$template = $config->get( 'client/html/catalog/detail/template-body', 'catalog/detail/body' ); |
131
|
|
|
|
132
|
|
|
$view = $this->view = $this->view ?? $this->object()->data( $view, $this->tags, $this->expire ); |
133
|
|
|
$html = $this->modify( $view->render( $template ), $uid ); |
134
|
|
|
|
135
|
|
|
return $this->cache( 'body', $uid, $prefixes, $confkey, $html, $this->tags, $this->expire ); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Returns the HTML string for insertion into the header. |
141
|
|
|
* |
142
|
|
|
* @param string $uid Unique identifier for the output if the content is placed more than once on the same page |
143
|
|
|
* @return string|null String including HTML tags for the header on error |
144
|
|
|
*/ |
145
|
|
|
public function header( string $uid = '' ) : ?string |
146
|
|
|
{ |
147
|
|
|
$view = $this->view(); |
148
|
|
|
$config = $this->context()->config(); |
149
|
|
|
$prefixes = ['d_prodid', 'd_name']; |
150
|
|
|
$confkey = 'client/html/catalog/detail'; |
151
|
|
|
|
152
|
|
|
$code = $config->get( 'client/html/catalog/detail/prodcode-default' ); |
153
|
|
|
$id = $config->get( 'client/html/catalog/detail/prodid-default', $code ); |
154
|
|
|
|
155
|
|
|
if( !$view->param( 'd_name', $view->param( 'd_prodid', $id ) ) ) { |
156
|
|
|
return ''; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
if( $html = $this->cached( 'header', $uid, $prefixes, $confkey ) ) { |
160
|
|
|
return $this->modify( $html, $uid ); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** client/html/catalog/detail/template-header |
164
|
|
|
* Relative path to the HTML header template of the catalog detail client. |
165
|
|
|
* |
166
|
|
|
* The template file contains the HTML code and processing instructions |
167
|
|
|
* to generate the HTML code that is inserted into the HTML page header |
168
|
|
|
* of the rendered page in the frontend. The configuration string is the |
169
|
|
|
* path to the template file relative to the templates directory (usually |
170
|
|
|
* in templates/client/html). |
171
|
|
|
* |
172
|
|
|
* You can overwrite the template file configuration in extensions and |
173
|
|
|
* provide alternative templates. These alternative templates should be |
174
|
|
|
* named like the default one but suffixed by |
175
|
|
|
* an unique name. You may use the name of your project for this. If |
176
|
|
|
* you've implemented an alternative client class as well, it |
177
|
|
|
* should be suffixed by the name of the new class. |
178
|
|
|
* |
179
|
|
|
* @param string Relative path to the template creating code for the HTML page head |
180
|
|
|
* @since 2014.03 |
181
|
|
|
* @see client/html/catalog/detail/template-body |
182
|
|
|
* @see client/html/catalog/detail/404 |
183
|
|
|
*/ |
184
|
|
|
$template = $config->get( 'client/html/catalog/detail/template-header', 'catalog/detail/header' ); |
185
|
|
|
|
186
|
|
|
$view = $this->view = $this->view ?? $this->object()->data( $this->view(), $this->tags, $this->expire ); |
187
|
|
|
$html = $view->render( $template ); |
188
|
|
|
|
189
|
|
|
return $this->cache( 'header', $uid, $prefixes, $confkey, $html, $this->tags, $this->expire ); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* Modifies the cached content to replace content based on sessions or cookies. |
195
|
|
|
* |
196
|
|
|
* @param string $content Cached content |
197
|
|
|
* @param string $uid Unique identifier for the output if the content is placed more than once on the same page |
198
|
|
|
* @return string Modified content |
199
|
|
|
*/ |
200
|
|
|
public function modify( string $content, string $uid ) : string |
201
|
|
|
{ |
202
|
|
|
$content = $this->replaceSection( $content, $this->navigator(), 'catalog.detail.navigator' ); |
203
|
|
|
return $this->replaceSection( $content, $this->view()->csrf()->formfield(), 'catalog.detail.csrf' ); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* Processes the input, e.g. store given values. |
209
|
|
|
* |
210
|
|
|
* A view must be available and this method doesn't generate any output |
211
|
|
|
* besides setting view variables if necessary. |
212
|
|
|
*/ |
213
|
|
|
public function init() |
214
|
|
|
{ |
215
|
|
|
$view = $this->view(); |
216
|
|
|
$context = $this->context(); |
217
|
|
|
$session = $context->session(); |
218
|
|
|
|
219
|
|
|
$params = $view->param(); |
220
|
|
|
$site = $context->locale()->getSiteItem()->getCode(); |
221
|
|
|
|
222
|
|
|
$session->set( 'aimeos/catalog/last/' . $site, $view->link( 'client/html/catalog/detail/url', $params ) ); |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* Sets the necessary parameter values in the view. |
228
|
|
|
* |
229
|
|
|
* @param \Aimeos\Base\View\Iface $view The view object which generates the HTML output |
230
|
|
|
* @param array &$tags Result array for the list of tags that are associated to the output |
231
|
|
|
* @param string|null &$expire Result variable for the expiration date of the output (null for no expiry) |
232
|
|
|
* @return \Aimeos\Base\View\Iface Modified view object |
233
|
|
|
*/ |
234
|
|
|
public function data( \Aimeos\Base\View\Iface $view, array &$tags = [], ?string &$expire = null ) : \Aimeos\Base\View\Iface |
235
|
|
|
{ |
236
|
|
|
$productItem = $this->product( $view ); |
237
|
|
|
|
238
|
|
|
$propItems = $productItem->getPropertyItems(); |
239
|
|
|
$attrItems = $productItem->getRefItems( 'attribute', null, 'default' ); |
240
|
|
|
$mediaItems = $productItem->getRefItems( 'media', 'default', 'default' ); |
241
|
|
|
|
242
|
|
|
$this->addMetaItems( $productItem, $expire, $tags, ['product'] ); |
243
|
|
|
|
244
|
|
|
if( in_array( $productItem->getType(), ['bundle', 'select'] ) ) |
245
|
|
|
{ |
246
|
|
|
\Aimeos\Map::method( 'attrparent', function( $subProdId ) { |
247
|
|
|
foreach( $this->list as $item ) { |
|
|
|
|
248
|
|
|
$item->parent = array_merge( $item->parent ?? [], [$subProdId] ); |
249
|
|
|
} |
250
|
|
|
return $this; |
251
|
|
|
} ); |
252
|
|
|
|
253
|
|
|
foreach( $productItem->getRefItems( 'product', null, 'default' ) as $subProdId => $subProduct ) |
254
|
|
|
{ |
255
|
|
|
$propItems->merge( $subProduct->getPropertyItems()->assign( ['parent' => $subProdId] ) ); |
256
|
|
|
$mediaItems->merge( $subProduct->getRefItems( 'media', 'default', 'default' ) ); |
257
|
|
|
$attrItems->replace( |
258
|
|
|
$subProduct->getRefItems( 'attribute', null, ['default', 'variant'] )->attrparent( $subProdId ) |
259
|
|
|
); |
260
|
|
|
} |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
$attrItems->uasort( function( $a, $b ) { |
264
|
|
|
return $a->getPosition() <=> $b->getPosition(); |
265
|
|
|
} ); |
266
|
|
|
|
267
|
|
|
$attrMap = $attrItems->groupBy( 'attribute.type' ); |
268
|
|
|
$propMap = $propItems->groupBy( 'product.property.type' ); |
269
|
|
|
|
270
|
|
|
$attrTypes = $this->attributeTypes( $attrMap->keys()->concat( $productItem->getRefItems( 'attribute' )->getType() )->unique() ); |
271
|
|
|
$propTypes = $this->propertyTypes( $propMap->keys() ); |
272
|
|
|
|
273
|
|
|
$view->detailMediaItems = $mediaItems; |
274
|
|
|
$view->detailProductItem = $productItem; |
275
|
|
|
$view->detailPropertyTypes = $propTypes->col( null, 'product.property.type.code' ); |
276
|
|
|
$view->detailAttributeTypes = $attrTypes->col( null, 'attribute.type.code' ); |
277
|
|
|
$view->detailAttributeMap = $attrMap->order( $attrTypes->getCode() )->filter(); |
278
|
|
|
$view->detailPropertyMap = $propMap->order( $propTypes->getCode() )->filter(); |
279
|
|
|
$view->detailStockTypes = $productItem->getStockItems()->getType(); |
280
|
|
|
$view->detailStockUrl = $this->stockUrl( $productItem ); |
281
|
|
|
|
282
|
|
|
$this->call( 'seen', $productItem ); |
283
|
|
|
|
284
|
|
|
return parent::data( $view, $tags, $expire ); |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
|
288
|
|
|
/** |
289
|
|
|
* Returns the attribute type items for the given codes |
290
|
|
|
* |
291
|
|
|
* @param \Aimeos\Map $codes List of attribute type codes |
292
|
|
|
* @return \Aimeos\Map List of attribute type items |
293
|
|
|
*/ |
294
|
|
|
protected function attributeTypes( \Aimeos\Map $codes ) : \Aimeos\Map |
295
|
|
|
{ |
296
|
|
|
$manager = \Aimeos\MShop::create( $this->context(), 'attribute/type' ); |
297
|
|
|
|
298
|
|
|
$filter = $manager->filter( true ) |
299
|
|
|
->add( 'attribute.type.code', '==', $codes ) |
300
|
|
|
->order( 'attribute.type.position' ); |
301
|
|
|
|
302
|
|
|
return $manager->search( $filter->slice( 0, count( $codes ) ) ); |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
|
306
|
|
|
/** |
307
|
|
|
* Returns the data domains fetched along with the products |
308
|
|
|
* |
309
|
|
|
* @return array List of domain names |
310
|
|
|
*/ |
311
|
|
|
protected function domains() : array |
312
|
|
|
{ |
313
|
|
|
$context = $this->context(); |
314
|
|
|
$config = $context->config(); |
315
|
|
|
|
316
|
|
|
$domains = [ |
317
|
|
|
'attribute', 'attribute/property', 'catalog', 'media', 'media/property', 'price', |
318
|
|
|
'product', 'product/property', 'supplier', 'supplier/address', 'text', 'stock' |
319
|
|
|
]; |
320
|
|
|
|
321
|
|
|
/** client/html/catalog/domains |
322
|
|
|
* A list of domain names whose items should be available in the catalog view templates |
323
|
|
|
* |
324
|
|
|
* @see client/html/catalog/detail/domains |
325
|
|
|
*/ |
326
|
|
|
$domains = $config->get( 'client/html/catalog/domains', $domains ); |
327
|
|
|
|
328
|
|
|
/** client/html/catalog/detail/domains |
329
|
|
|
* A list of domain names whose items should be available in the product detail view template |
330
|
|
|
* |
331
|
|
|
* The templates rendering product details usually add the images, |
332
|
|
|
* prices, texts, attributes, products, etc. associated to the product |
333
|
|
|
* item. If you want to display additional or less content, you can |
334
|
|
|
* configure your own list of domains (attribute, media, price, product, |
335
|
|
|
* text, etc. are domains) whose items are fetched from the storage. |
336
|
|
|
* Please keep in mind that the more domains you add to the configuration, |
337
|
|
|
* the more time is required for fetching the content! |
338
|
|
|
* |
339
|
|
|
* Since version 2014.05 this configuration option overwrites the |
340
|
|
|
* "client/html/catalog/domains" option that allows to configure the |
341
|
|
|
* domain names of the items fetched for all catalog related data. |
342
|
|
|
* |
343
|
|
|
* @param array List of domain names |
344
|
|
|
* @since 2014.03 |
345
|
|
|
* @see client/html/catalog/domains |
346
|
|
|
* @see client/html/catalog/lists/domains |
347
|
|
|
*/ |
348
|
|
|
$domains = $config->get( 'client/html/catalog/detail/domains', $domains ); |
349
|
|
|
|
350
|
|
|
return $domains; |
351
|
|
|
} |
352
|
|
|
|
353
|
|
|
|
354
|
|
|
/** |
355
|
|
|
* Sets the necessary parameter values in the view. |
356
|
|
|
* |
357
|
|
|
* @param \Aimeos\Base\View\Iface $view The view object which generates the HTML output |
358
|
|
|
* @param array &$tags Result array for the list of tags that are associated to the output |
359
|
|
|
* @param string|null &$expire Result variable for the expiration date of the output (null for no expiry) |
360
|
|
|
* @return \Aimeos\Base\View\Iface Modified view object |
361
|
|
|
*/ |
362
|
|
|
protected function navigator() : string |
363
|
|
|
{ |
364
|
|
|
$view = $this->view(); |
365
|
|
|
$context = $this->context(); |
366
|
|
|
|
367
|
|
|
if( is_numeric( $pos = $view->param( 'd_pos' ) ) ) |
368
|
|
|
{ |
369
|
|
|
if( $pos < 1 ) { |
370
|
|
|
$pos = $start = 0; $size = 2; |
371
|
|
|
} else { |
372
|
|
|
$start = $pos - 1; $size = 3; |
373
|
|
|
} |
374
|
|
|
|
375
|
|
|
$site = $context->locale()->getSiteItem()->getCode(); |
376
|
|
|
$params = $context->session()->get( 'aimeos/catalog/lists/params/last/' . $site, [] ); |
377
|
|
|
$level = $view->config( 'client/html/catalog/lists/levels', \Aimeos\MW\Tree\Manager\Base::LEVEL_ONE ); |
378
|
|
|
|
379
|
|
|
$catids = $view->value( $params, 'f_catid', $view->config( 'client/html/catalog/lists/catid-default' ) ); |
380
|
|
|
$sort = $view->value( $params, 'f_sort', $view->config( 'client/html/catalog/lists/sort', 'relevance' ) ); |
381
|
|
|
|
382
|
|
|
$products = \Aimeos\Controller\Frontend::create( $context, 'product' ) |
383
|
|
|
->sort( $sort ) // prioritize user sorting over the sorting through relevance and category |
384
|
|
|
->allOf( $view->value( $params, 'f_attrid', [] ) ) |
385
|
|
|
->oneOf( $view->value( $params, 'f_optid', [] ) ) |
386
|
|
|
->oneOf( $view->value( $params, 'f_oneid', [] ) ) |
387
|
|
|
->text( $view->value( $params, 'f_search' ) ) |
388
|
|
|
->category( $catids, 'default', $level ) |
389
|
|
|
->slice( $start, $size ) |
390
|
|
|
->uses( ['text'] ) |
391
|
|
|
->search(); |
392
|
|
|
|
393
|
|
|
if( ( $count = count( $products ) ) > 1 ) |
394
|
|
|
{ |
395
|
|
|
if( $pos > 0 && ( $product = $products->first() ) !== null ) |
396
|
|
|
{ |
397
|
|
|
$url = $product->getName( 'url' ); |
398
|
|
|
$param = ['path' => $url, 'd_name' => $url, 'd_prodid' => $product->getId(), 'd_pos' => $pos - 1]; |
399
|
|
|
$view->navigationPrev = $view->link( 'client/html/catalog/detail/url', $param ); |
400
|
|
|
} |
401
|
|
|
|
402
|
|
|
if( ( $pos === 0 || $count === 3 ) && ( $product = $products->last() ) !== null ) |
403
|
|
|
{ |
404
|
|
|
$url = $product->getName( 'url' ); |
405
|
|
|
$param = ['path' => $url, 'd_name' => $url, 'd_prodid' => $product->getId(), 'd_pos' => $pos + 1]; |
406
|
|
|
$view->navigationNext = $view->link( 'client/html/catalog/detail/url', $param ); |
407
|
|
|
} |
408
|
|
|
} |
409
|
|
|
|
410
|
|
|
/** client/html/catalog/detail/template-navigator |
411
|
|
|
* Relative path to the HTML template of the catalog detail navigator partial. |
412
|
|
|
* |
413
|
|
|
* The template file contains the HTML code and processing instructions |
414
|
|
|
* to generate the result shown in the body of the frontend. The |
415
|
|
|
* configuration string is the path to the template file relative |
416
|
|
|
* to the templates directory (usually in templates/client/html). |
417
|
|
|
* |
418
|
|
|
* You can overwrite the template file configuration in extensions and |
419
|
|
|
* provide alternative templates. These alternative templates should be |
420
|
|
|
* named like the default one but suffixed by |
421
|
|
|
* an unique name. You may use the name of your project for this. If |
422
|
|
|
* you've implemented an alternative client class as well, it |
423
|
|
|
* should be suffixed by the name of the new class. |
424
|
|
|
* |
425
|
|
|
* @param string Relative path to the template creating the HTML fragment |
426
|
|
|
* @since 2022.10 |
427
|
|
|
*/ |
428
|
|
|
$template = $context->config()->get( 'client/html/catalog/detail/template-navigator', 'catalog/detail/navigator' ); |
429
|
|
|
|
430
|
|
|
return $view->render( $template ); |
431
|
|
|
} |
432
|
|
|
|
433
|
|
|
return ''; |
434
|
|
|
} |
435
|
|
|
|
436
|
|
|
|
437
|
|
|
/** |
438
|
|
|
* Returns the product item |
439
|
|
|
* |
440
|
|
|
* @param \Aimeos\Base\View\Iface $view The view object which generates the HTML output |
441
|
|
|
* @return \Aimeos\MShop\Product\Item\Iface Product item |
442
|
|
|
*/ |
443
|
|
|
protected function product( \Aimeos\Base\View\Iface $view ) : \Aimeos\MShop\Product\Item\Iface |
444
|
|
|
{ |
445
|
|
|
$context = $this->context(); |
446
|
|
|
$config = $context->config(); |
447
|
|
|
|
448
|
|
|
/** client/html/catalog/detail/prodid-default |
449
|
|
|
* The default product ID used if none is given as parameter |
450
|
|
|
* |
451
|
|
|
* To display a product detail view or a part of it for a specific |
452
|
|
|
* product, you can configure its ID using this setting. This is |
453
|
|
|
* most useful in a CMS where the product ID can be configured |
454
|
|
|
* separately for each content node. |
455
|
|
|
* |
456
|
|
|
* @param string Product ID |
457
|
|
|
* @since 2016.01 |
458
|
|
|
* @see client/html/catalog/detail/prodid-default |
459
|
|
|
* @see client/html/catalog/lists/catid-default |
460
|
|
|
*/ |
461
|
|
|
$id = $view->param( 'd_prodid', $config->get( 'client/html/catalog/detail/prodid-default' ) ); |
462
|
|
|
|
463
|
|
|
/** client/html/catalog/detail/prodcode-default |
464
|
|
|
* The default product code used if none is given as parameter |
465
|
|
|
* |
466
|
|
|
* To display a product detail view or a part of it for a specific |
467
|
|
|
* product, you can configure its code using this setting. This is |
468
|
|
|
* most useful in a CMS where the product code can be configured |
469
|
|
|
* separately for each content node. |
470
|
|
|
* |
471
|
|
|
* @param string Product code |
472
|
|
|
* @since 2019.10 |
473
|
|
|
* @see client/html/catalog/detail/prodid-default |
474
|
|
|
* @see client/html/catalog/lists/catid-default |
475
|
|
|
*/ |
476
|
|
|
$code = $config->get( 'client/html/catalog/detail/prodcode-default' ); |
477
|
|
|
|
478
|
|
|
$cntl = \Aimeos\Controller\Frontend::create( $context, 'product' )->uses( $this->domains() ); |
479
|
|
|
return ( $id ? $cntl->get( $id ) : ( $code ? $cntl->find( $code ) : $cntl->resolve( $view->param( 'd_name' ) ) ) ); |
480
|
|
|
} |
481
|
|
|
|
482
|
|
|
|
483
|
|
|
/** |
484
|
|
|
* Returns the property type items for the given codes |
485
|
|
|
* |
486
|
|
|
* @param \Aimeos\Map $codes List of property type codes |
487
|
|
|
* @return \Aimeos\Map List of property type items |
488
|
|
|
*/ |
489
|
|
|
protected function propertyTypes( \Aimeos\Map $codes ) : \Aimeos\Map |
490
|
|
|
{ |
491
|
|
|
$manager = \Aimeos\MShop::create( $this->context(), 'product/property/type' ); |
492
|
|
|
|
493
|
|
|
$filter = $manager->filter( true ) |
494
|
|
|
->add( 'product.property.type.code', '==', $codes ) |
495
|
|
|
->order( 'product.property.type.position' ); |
496
|
|
|
|
497
|
|
|
return $manager->search( $filter->slice( 0, count( $codes ) ) ); |
498
|
|
|
} |
499
|
|
|
|
500
|
|
|
|
501
|
|
|
/** |
502
|
|
|
* Adds the product to the list of last seen products. |
503
|
|
|
* |
504
|
|
|
* @param \Aimeos\MShop\Product\Item\Iface $product Product item |
505
|
|
|
*/ |
506
|
|
|
protected function seen( \Aimeos\MShop\Product\Item\Iface $product ) |
507
|
|
|
{ |
508
|
|
|
$id = $product->getId(); |
509
|
|
|
$context = $this->context(); |
510
|
|
|
$session = $context->session(); |
511
|
|
|
$lastSeen = map( $session->get( 'aimeos/catalog/session/seen/list', [] ) ); |
512
|
|
|
|
513
|
|
|
if( !$lastSeen->has( $id ) ) |
514
|
|
|
{ |
515
|
|
|
$config = $context->config(); |
516
|
|
|
|
517
|
|
|
/** client/html/catalog/detail/partials/seen |
518
|
|
|
* Relative path to the HTML template of the catalog detail seen partial. |
519
|
|
|
* |
520
|
|
|
* The template file contains the HTML code and processing instructions |
521
|
|
|
* to generate the result shown in the body of the frontend. The |
522
|
|
|
* configuration string is the path to the template file relative |
523
|
|
|
* to the templates directory (usually in templates/client/html). |
524
|
|
|
* |
525
|
|
|
* You can overwrite the template file configuration in extensions and |
526
|
|
|
* provide alternative templates. These alternative templates should be |
527
|
|
|
* named like the default one but suffixed by |
528
|
|
|
* an unique name. You may use the name of your project for this. If |
529
|
|
|
* you've implemented an alternative client class as well, it |
530
|
|
|
* should be suffixed by the name of the new class. |
531
|
|
|
* |
532
|
|
|
* @param string Relative path to the template creating the HTML fragment |
533
|
|
|
* @since 2014.03 |
534
|
|
|
*/ |
535
|
|
|
$template = $config->get( 'client/html/catalog/detail/partials/seen', 'catalog/detail/seen' ); |
536
|
|
|
|
537
|
|
|
/** client/html/catalog/session/seen/maxitems |
538
|
|
|
* Maximum number of products displayed in the "last seen" section |
539
|
|
|
* |
540
|
|
|
* This option limits the number of products that are shown in the |
541
|
|
|
* "last seen" section after the user visited their detail pages. It |
542
|
|
|
* must be a positive integer value greater than 0. |
543
|
|
|
* |
544
|
|
|
* @param integer Number of products |
545
|
|
|
* @since 2014.03 |
546
|
|
|
*/ |
547
|
|
|
$max = $config->get( 'client/html/catalog/session/seen/maxitems', 6 ); |
548
|
|
|
|
549
|
|
|
$html = $this->view()->set( 'product', $product )->render( $template ); |
550
|
|
|
$lastSeen = $lastSeen->put( $id, $html )->slice( -$max ); |
551
|
|
|
} |
552
|
|
|
|
553
|
|
|
$session->set( 'aimeos/catalog/session/seen/list', $lastSeen->put( $id, $lastSeen->pull( $id ) )->all() ); |
554
|
|
|
} |
555
|
|
|
|
556
|
|
|
|
557
|
|
|
/** |
558
|
|
|
* Returns the URL for fetching stock levels |
559
|
|
|
* |
560
|
|
|
* @param \Aimeos\MShop\Product\Item\Iface $product Product item |
561
|
|
|
* @return \Aimeos\Map List of stock URLs |
562
|
|
|
*/ |
563
|
|
|
protected function stockUrl( \Aimeos\MShop\Product\Item\Iface $productItem ) : \Aimeos\Map |
564
|
|
|
{ |
565
|
|
|
/** client/html/catalog/detail/stock/enable |
566
|
|
|
* Enables or disables displaying product stock levels in product detail view |
567
|
|
|
* |
568
|
|
|
* This configuration option allows shop owners to display product |
569
|
|
|
* stock levels for each product in the detail views or to disable |
570
|
|
|
* fetching product stock information. |
571
|
|
|
* |
572
|
|
|
* The stock information is fetched via AJAX and inserted via Javascript. |
573
|
|
|
* This allows to cache product items by leaving out such highly |
574
|
|
|
* dynamic content like stock levels which changes with each order. |
575
|
|
|
* |
576
|
|
|
* @param boolean Value of "1" to display stock levels, "0" to disable displaying them |
577
|
|
|
* @since 2014.03 |
578
|
|
|
* @see client/html/catalog/lists/stock/enable |
579
|
|
|
* @see client/html/catalog/stock/url/target |
580
|
|
|
* @see client/html/catalog/stock/url/controller |
581
|
|
|
* @see client/html/catalog/stock/url/action |
582
|
|
|
* @see client/html/catalog/stock/url/config |
583
|
|
|
*/ |
584
|
|
|
if( !$this->context()->config()->get( 'client/html/catalog/detail/stock/enable', true ) ) { |
585
|
|
|
return map(); |
586
|
|
|
} |
587
|
|
|
|
588
|
|
|
$products = $productItem->getRefItems( 'product', null, 'default' )->push( $productItem ); |
589
|
|
|
|
590
|
|
|
return $this->getStockUrl( $this->view(), $products ); |
591
|
|
|
} |
592
|
|
|
|
593
|
|
|
|
594
|
|
|
/** client/html/catalog/detail/decorators/excludes |
595
|
|
|
* Excludes decorators added by the "common" option from the catalog detail html client |
596
|
|
|
* |
597
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
598
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
599
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
600
|
|
|
* modify what is returned to the caller. |
601
|
|
|
* |
602
|
|
|
* This option allows you to remove a decorator added via |
603
|
|
|
* "client/html/common/decorators/default" before they are wrapped |
604
|
|
|
* around the html client. |
605
|
|
|
* |
606
|
|
|
* client/html/catalog/detail/decorators/excludes = array( 'decorator1' ) |
607
|
|
|
* |
608
|
|
|
* This would remove the decorator named "decorator1" from the list of |
609
|
|
|
* common decorators ("\Aimeos\Client\Html\Common\Decorator\*") added via |
610
|
|
|
* "client/html/common/decorators/default" to the html client. |
611
|
|
|
* |
612
|
|
|
* @param array List of decorator names |
613
|
|
|
* @see client/html/common/decorators/default |
614
|
|
|
* @see client/html/catalog/detail/decorators/global |
615
|
|
|
* @see client/html/catalog/detail/decorators/local |
616
|
|
|
*/ |
617
|
|
|
|
618
|
|
|
/** client/html/catalog/detail/decorators/global |
619
|
|
|
* Adds a list of globally available decorators only to the catalog detail html client |
620
|
|
|
* |
621
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
622
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
623
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
624
|
|
|
* modify what is returned to the caller. |
625
|
|
|
* |
626
|
|
|
* This option allows you to wrap global decorators |
627
|
|
|
* ("\Aimeos\Client\Html\Common\Decorator\*") around the html client. |
628
|
|
|
* |
629
|
|
|
* client/html/catalog/detail/decorators/global = array( 'decorator1' ) |
630
|
|
|
* |
631
|
|
|
* This would add the decorator named "decorator1" defined by |
632
|
|
|
* "\Aimeos\Client\Html\Common\Decorator\Decorator1" only to the html client. |
633
|
|
|
* |
634
|
|
|
* @param array List of decorator names |
635
|
|
|
* @see client/html/common/decorators/default |
636
|
|
|
* @see client/html/catalog/detail/decorators/excludes |
637
|
|
|
* @see client/html/catalog/detail/decorators/local |
638
|
|
|
*/ |
639
|
|
|
|
640
|
|
|
/** client/html/catalog/detail/decorators/local |
641
|
|
|
* Adds a list of local decorators only to the catalog detail html client |
642
|
|
|
* |
643
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
644
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
645
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
646
|
|
|
* modify what is returned to the caller. |
647
|
|
|
* |
648
|
|
|
* This option allows you to wrap local decorators |
649
|
|
|
* ("\Aimeos\Client\Html\Catalog\Decorator\*") around the html client. |
650
|
|
|
* |
651
|
|
|
* client/html/catalog/detail/decorators/local = array( 'decorator2' ) |
652
|
|
|
* |
653
|
|
|
* This would add the decorator named "decorator2" defined by |
654
|
|
|
* "\Aimeos\Client\Html\Catalog\Decorator\Decorator2" only to the html client. |
655
|
|
|
* |
656
|
|
|
* @param array List of decorator names |
657
|
|
|
* @see client/html/common/decorators/default |
658
|
|
|
* @see client/html/catalog/detail/decorators/excludes |
659
|
|
|
* @see client/html/catalog/detail/decorators/global |
660
|
|
|
*/ |
661
|
|
|
} |
662
|
|
|
|