|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2023 |
|
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() ); |
|
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() ); |
|
278
|
|
|
$view->detailPropertyMap = $propMap->order( $propTypes->getCode() ); |
|
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.domain', '==', 'product' ) |
|
300
|
|
|
->add( 'attribute.type.code', '==', $codes ) |
|
301
|
|
|
->order( 'attribute.type.position' ); |
|
302
|
|
|
|
|
303
|
|
|
return $manager->search( $filter->slice( 0, count( $codes ) ) ); |
|
304
|
|
|
} |
|
305
|
|
|
|
|
306
|
|
|
|
|
307
|
|
|
/** |
|
308
|
|
|
* Returns the data domains fetched along with the products |
|
309
|
|
|
* |
|
310
|
|
|
* @return array List of domain names |
|
311
|
|
|
*/ |
|
312
|
|
|
protected function domains() : array |
|
313
|
|
|
{ |
|
314
|
|
|
$context = $this->context(); |
|
315
|
|
|
$config = $context->config(); |
|
316
|
|
|
|
|
317
|
|
|
$domains = [ |
|
318
|
|
|
'attribute', 'attribute/property', 'catalog', 'media', 'media/property', 'price', |
|
319
|
|
|
'product', 'product/property', 'supplier', 'supplier/address', 'text', 'stock' |
|
320
|
|
|
]; |
|
321
|
|
|
|
|
322
|
|
|
/** client/html/catalog/domains |
|
323
|
|
|
* A list of domain names whose items should be available in the catalog view templates |
|
324
|
|
|
* |
|
325
|
|
|
* @see client/html/catalog/detail/domains |
|
326
|
|
|
*/ |
|
327
|
|
|
$domains = $config->get( 'client/html/catalog/domains', $domains ); |
|
328
|
|
|
|
|
329
|
|
|
/** client/html/catalog/detail/domains |
|
330
|
|
|
* A list of domain names whose items should be available in the product detail view template |
|
331
|
|
|
* |
|
332
|
|
|
* The templates rendering product details usually add the images, |
|
333
|
|
|
* prices, texts, attributes, products, etc. associated to the product |
|
334
|
|
|
* item. If you want to display additional or less content, you can |
|
335
|
|
|
* configure your own list of domains (attribute, media, price, product, |
|
336
|
|
|
* text, etc. are domains) whose items are fetched from the storage. |
|
337
|
|
|
* Please keep in mind that the more domains you add to the configuration, |
|
338
|
|
|
* the more time is required for fetching the content! |
|
339
|
|
|
* |
|
340
|
|
|
* Since version 2014.05 this configuration option overwrites the |
|
341
|
|
|
* "client/html/catalog/domains" option that allows to configure the |
|
342
|
|
|
* domain names of the items fetched for all catalog related data. |
|
343
|
|
|
* |
|
344
|
|
|
* @param array List of domain names |
|
345
|
|
|
* @since 2014.03 |
|
346
|
|
|
* @see client/html/catalog/domains |
|
347
|
|
|
* @see client/html/catalog/lists/domains |
|
348
|
|
|
*/ |
|
349
|
|
|
$domains = $config->get( 'client/html/catalog/detail/domains', $domains ); |
|
350
|
|
|
|
|
351
|
|
|
return $domains; |
|
352
|
|
|
} |
|
353
|
|
|
|
|
354
|
|
|
|
|
355
|
|
|
/** |
|
356
|
|
|
* Sets the necessary parameter values in the view. |
|
357
|
|
|
* |
|
358
|
|
|
* @param \Aimeos\Base\View\Iface $view The view object which generates the HTML output |
|
359
|
|
|
* @param array &$tags Result array for the list of tags that are associated to the output |
|
360
|
|
|
* @param string|null &$expire Result variable for the expiration date of the output (null for no expiry) |
|
361
|
|
|
* @return \Aimeos\Base\View\Iface Modified view object |
|
362
|
|
|
*/ |
|
363
|
|
|
protected function navigator() : string |
|
364
|
|
|
{ |
|
365
|
|
|
$view = $this->view(); |
|
366
|
|
|
$context = $this->context(); |
|
367
|
|
|
|
|
368
|
|
|
if( is_numeric( $pos = $view->param( 'd_pos' ) ) ) |
|
369
|
|
|
{ |
|
370
|
|
|
if( $pos < 1 ) { |
|
371
|
|
|
$pos = $start = 0; $size = 2; |
|
372
|
|
|
} else { |
|
373
|
|
|
$start = $pos - 1; $size = 3; |
|
374
|
|
|
} |
|
375
|
|
|
|
|
376
|
|
|
$site = $context->locale()->getSiteItem()->getCode(); |
|
377
|
|
|
$params = $context->session()->get( 'aimeos/catalog/lists/params/last/' . $site, [] ); |
|
378
|
|
|
$level = $view->config( 'client/html/catalog/lists/levels', \Aimeos\MW\Tree\Manager\Base::LEVEL_ONE ); |
|
379
|
|
|
|
|
380
|
|
|
$catids = $view->value( $params, 'f_catid', $view->config( 'client/html/catalog/lists/catid-default' ) ); |
|
381
|
|
|
$sort = $view->value( $params, 'f_sort', $view->config( 'client/html/catalog/lists/sort', 'relevance' ) ); |
|
382
|
|
|
|
|
383
|
|
|
$products = \Aimeos\Controller\Frontend::create( $context, 'product' ) |
|
384
|
|
|
->sort( $sort ) // prioritize user sorting over the sorting through relevance and category |
|
385
|
|
|
->allOf( $view->value( $params, 'f_attrid', [] ) ) |
|
386
|
|
|
->oneOf( $view->value( $params, 'f_optid', [] ) ) |
|
387
|
|
|
->oneOf( $view->value( $params, 'f_oneid', [] ) ) |
|
388
|
|
|
->text( $view->value( $params, 'f_search' ) ) |
|
389
|
|
|
->category( $catids, 'default', $level ) |
|
390
|
|
|
->slice( $start, $size ) |
|
391
|
|
|
->uses( ['text'] ) |
|
392
|
|
|
->search(); |
|
393
|
|
|
|
|
394
|
|
|
if( ( $count = count( $products ) ) > 1 ) |
|
395
|
|
|
{ |
|
396
|
|
|
if( $pos > 0 && ( $product = $products->first() ) !== null ) |
|
397
|
|
|
{ |
|
398
|
|
|
$param = ['d_name' => $product->getName( '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
|
|
|
$param = ['d_name' => $product->getName( 'url' ), 'd_prodid' => $product->getId(), 'd_pos' => $pos + 1]; |
|
405
|
|
|
$view->navigationNext = $view->link( 'client/html/catalog/detail/url', $param ); |
|
406
|
|
|
} |
|
407
|
|
|
} |
|
408
|
|
|
|
|
409
|
|
|
/** client/html/catalog/detail/template-navigator |
|
410
|
|
|
* Relative path to the HTML template of the catalog detail navigator partial. |
|
411
|
|
|
* |
|
412
|
|
|
* The template file contains the HTML code and processing instructions |
|
413
|
|
|
* to generate the result shown in the body of the frontend. The |
|
414
|
|
|
* configuration string is the path to the template file relative |
|
415
|
|
|
* to the templates directory (usually in templates/client/html). |
|
416
|
|
|
* |
|
417
|
|
|
* You can overwrite the template file configuration in extensions and |
|
418
|
|
|
* provide alternative templates. These alternative templates should be |
|
419
|
|
|
* named like the default one but suffixed by |
|
420
|
|
|
* an unique name. You may use the name of your project for this. If |
|
421
|
|
|
* you've implemented an alternative client class as well, it |
|
422
|
|
|
* should be suffixed by the name of the new class. |
|
423
|
|
|
* |
|
424
|
|
|
* @param string Relative path to the template creating the HTML fragment |
|
425
|
|
|
* @since 2022.10 |
|
426
|
|
|
*/ |
|
427
|
|
|
$template = $context->config()->get( 'client/html/catalog/detail/template-navigator', 'catalog/detail/navigator' ); |
|
428
|
|
|
|
|
429
|
|
|
return $view->render( $template ); |
|
430
|
|
|
} |
|
431
|
|
|
|
|
432
|
|
|
return ''; |
|
433
|
|
|
} |
|
434
|
|
|
|
|
435
|
|
|
|
|
436
|
|
|
/** |
|
437
|
|
|
* Returns the product item |
|
438
|
|
|
* |
|
439
|
|
|
* @param \Aimeos\Base\View\Iface $view The view object which generates the HTML output |
|
440
|
|
|
* @return \Aimeos\MShop\Product\Item\Iface Product item |
|
441
|
|
|
*/ |
|
442
|
|
|
protected function product( \Aimeos\Base\View\Iface $view ) : \Aimeos\MShop\Product\Item\Iface |
|
443
|
|
|
{ |
|
444
|
|
|
$context = $this->context(); |
|
445
|
|
|
$config = $context->config(); |
|
446
|
|
|
|
|
447
|
|
|
/** client/html/catalog/detail/prodid-default |
|
448
|
|
|
* The default product ID used if none is given as parameter |
|
449
|
|
|
* |
|
450
|
|
|
* To display a product detail view or a part of it for a specific |
|
451
|
|
|
* product, you can configure its ID using this setting. This is |
|
452
|
|
|
* most useful in a CMS where the product ID can be configured |
|
453
|
|
|
* separately for each content node. |
|
454
|
|
|
* |
|
455
|
|
|
* @param string Product ID |
|
456
|
|
|
* @since 2016.01 |
|
457
|
|
|
* @see client/html/catalog/detail/prodid-default |
|
458
|
|
|
* @see client/html/catalog/lists/catid-default |
|
459
|
|
|
*/ |
|
460
|
|
|
$id = $view->param( 'd_prodid', $config->get( 'client/html/catalog/detail/prodid-default' ) ); |
|
461
|
|
|
|
|
462
|
|
|
/** client/html/catalog/detail/prodcode-default |
|
463
|
|
|
* The default product code used if none is given as parameter |
|
464
|
|
|
* |
|
465
|
|
|
* To display a product detail view or a part of it for a specific |
|
466
|
|
|
* product, you can configure its code using this setting. This is |
|
467
|
|
|
* most useful in a CMS where the product code can be configured |
|
468
|
|
|
* separately for each content node. |
|
469
|
|
|
* |
|
470
|
|
|
* @param string Product code |
|
471
|
|
|
* @since 2019.10 |
|
472
|
|
|
* @see client/html/catalog/detail/prodid-default |
|
473
|
|
|
* @see client/html/catalog/lists/catid-default |
|
474
|
|
|
*/ |
|
475
|
|
|
$code = $config->get( 'client/html/catalog/detail/prodcode-default' ); |
|
476
|
|
|
|
|
477
|
|
|
$cntl = \Aimeos\Controller\Frontend::create( $context, 'product' )->uses( $this->domains() ); |
|
478
|
|
|
return ( $id ? $cntl->get( $id ) : ( $code ? $cntl->find( $code ) : $cntl->resolve( $view->param( 'd_name' ) ) ) ); |
|
479
|
|
|
} |
|
480
|
|
|
|
|
481
|
|
|
|
|
482
|
|
|
/** |
|
483
|
|
|
* Returns the property type items for the given codes |
|
484
|
|
|
* |
|
485
|
|
|
* @param \Aimeos\Map $codes List of property type codes |
|
486
|
|
|
* @return \Aimeos\Map List of property type items |
|
487
|
|
|
*/ |
|
488
|
|
|
protected function propertyTypes( \Aimeos\Map $codes ) : \Aimeos\Map |
|
489
|
|
|
{ |
|
490
|
|
|
$manager = \Aimeos\MShop::create( $this->context(), 'product/property/type' ); |
|
491
|
|
|
|
|
492
|
|
|
$filter = $manager->filter( true ) |
|
493
|
|
|
->add( 'product.property.type.code', '==', $codes ) |
|
494
|
|
|
->order( 'product.property.type.position' ); |
|
495
|
|
|
|
|
496
|
|
|
return $manager->search( $filter->slice( 0, count( $codes ) ) ); |
|
497
|
|
|
} |
|
498
|
|
|
|
|
499
|
|
|
|
|
500
|
|
|
/** |
|
501
|
|
|
* Adds the product to the list of last seen products. |
|
502
|
|
|
* |
|
503
|
|
|
* @param \Aimeos\MShop\Product\Item\Iface $product Product item |
|
504
|
|
|
*/ |
|
505
|
|
|
protected function seen( \Aimeos\MShop\Product\Item\Iface $product ) |
|
506
|
|
|
{ |
|
507
|
|
|
$id = $product->getId(); |
|
508
|
|
|
$context = $this->context(); |
|
509
|
|
|
$session = $context->session(); |
|
510
|
|
|
$lastSeen = map( $session->get( 'aimeos/catalog/session/seen/list', [] ) ); |
|
511
|
|
|
|
|
512
|
|
|
if( !$lastSeen->has( $id ) ) |
|
513
|
|
|
{ |
|
514
|
|
|
$config = $context->config(); |
|
515
|
|
|
|
|
516
|
|
|
/** client/html/catalog/detail/partials/seen |
|
517
|
|
|
* Relative path to the HTML template of the catalog detail seen partial. |
|
518
|
|
|
* |
|
519
|
|
|
* The template file contains the HTML code and processing instructions |
|
520
|
|
|
* to generate the result shown in the body of the frontend. The |
|
521
|
|
|
* configuration string is the path to the template file relative |
|
522
|
|
|
* to the templates directory (usually in templates/client/html). |
|
523
|
|
|
* |
|
524
|
|
|
* You can overwrite the template file configuration in extensions and |
|
525
|
|
|
* provide alternative templates. These alternative templates should be |
|
526
|
|
|
* named like the default one but suffixed by |
|
527
|
|
|
* an unique name. You may use the name of your project for this. If |
|
528
|
|
|
* you've implemented an alternative client class as well, it |
|
529
|
|
|
* should be suffixed by the name of the new class. |
|
530
|
|
|
* |
|
531
|
|
|
* @param string Relative path to the template creating the HTML fragment |
|
532
|
|
|
* @since 2014.03 |
|
533
|
|
|
*/ |
|
534
|
|
|
$template = $config->get( 'client/html/catalog/detail/partials/seen', 'catalog/detail/seen' ); |
|
535
|
|
|
|
|
536
|
|
|
/** client/html/catalog/session/seen/maxitems |
|
537
|
|
|
* Maximum number of products displayed in the "last seen" section |
|
538
|
|
|
* |
|
539
|
|
|
* This option limits the number of products that are shown in the |
|
540
|
|
|
* "last seen" section after the user visited their detail pages. It |
|
541
|
|
|
* must be a positive integer value greater than 0. |
|
542
|
|
|
* |
|
543
|
|
|
* @param integer Number of products |
|
544
|
|
|
* @since 2014.03 |
|
545
|
|
|
*/ |
|
546
|
|
|
$max = $config->get( 'client/html/catalog/session/seen/maxitems', 6 ); |
|
547
|
|
|
|
|
548
|
|
|
$html = $this->view()->set( 'product', $product )->render( $template ); |
|
549
|
|
|
$lastSeen = $lastSeen->put( $id, $html )->slice( -$max ); |
|
550
|
|
|
} |
|
551
|
|
|
|
|
552
|
|
|
$session->set( 'aimeos/catalog/session/seen/list', $lastSeen->put( $id, $lastSeen->pull( $id ) )->all() ); |
|
553
|
|
|
} |
|
554
|
|
|
|
|
555
|
|
|
|
|
556
|
|
|
/** |
|
557
|
|
|
* Returns the URL for fetching stock levels |
|
558
|
|
|
* |
|
559
|
|
|
* @param \Aimeos\MShop\Product\Item\Iface $product Product item |
|
560
|
|
|
* @return \Aimeos\Map List of stock URLs |
|
561
|
|
|
*/ |
|
562
|
|
|
protected function stockUrl( \Aimeos\MShop\Product\Item\Iface $productItem ) : \Aimeos\Map |
|
563
|
|
|
{ |
|
564
|
|
|
/** client/html/catalog/detail/stock/enable |
|
565
|
|
|
* Enables or disables displaying product stock levels in product detail view |
|
566
|
|
|
* |
|
567
|
|
|
* This configuration option allows shop owners to display product |
|
568
|
|
|
* stock levels for each product in the detail views or to disable |
|
569
|
|
|
* fetching product stock information. |
|
570
|
|
|
* |
|
571
|
|
|
* The stock information is fetched via AJAX and inserted via Javascript. |
|
572
|
|
|
* This allows to cache product items by leaving out such highly |
|
573
|
|
|
* dynamic content like stock levels which changes with each order. |
|
574
|
|
|
* |
|
575
|
|
|
* @param boolean Value of "1" to display stock levels, "0" to disable displaying them |
|
576
|
|
|
* @since 2014.03 |
|
577
|
|
|
* @see client/html/catalog/lists/stock/enable |
|
578
|
|
|
* @see client/html/catalog/stock/url/target |
|
579
|
|
|
* @see client/html/catalog/stock/url/controller |
|
580
|
|
|
* @see client/html/catalog/stock/url/action |
|
581
|
|
|
* @see client/html/catalog/stock/url/config |
|
582
|
|
|
*/ |
|
583
|
|
|
if( !$this->context()->config()->get( 'client/html/catalog/detail/stock/enable', true ) ) { |
|
584
|
|
|
return map(); |
|
585
|
|
|
} |
|
586
|
|
|
|
|
587
|
|
|
$products = $productItem->getRefItems( 'product', null, 'default' )->push( $productItem ); |
|
588
|
|
|
|
|
589
|
|
|
return $this->getStockUrl( $this->view(), $products ); |
|
590
|
|
|
} |
|
591
|
|
|
|
|
592
|
|
|
|
|
593
|
|
|
/** client/html/catalog/detail/decorators/excludes |
|
594
|
|
|
* Excludes decorators added by the "common" option from the catalog detail html client |
|
595
|
|
|
* |
|
596
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
|
597
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
|
598
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
|
599
|
|
|
* modify what is returned to the caller. |
|
600
|
|
|
* |
|
601
|
|
|
* This option allows you to remove a decorator added via |
|
602
|
|
|
* "client/html/common/decorators/default" before they are wrapped |
|
603
|
|
|
* around the html client. |
|
604
|
|
|
* |
|
605
|
|
|
* client/html/catalog/detail/decorators/excludes = array( 'decorator1' ) |
|
606
|
|
|
* |
|
607
|
|
|
* This would remove the decorator named "decorator1" from the list of |
|
608
|
|
|
* common decorators ("\Aimeos\Client\Html\Common\Decorator\*") added via |
|
609
|
|
|
* "client/html/common/decorators/default" to the html client. |
|
610
|
|
|
* |
|
611
|
|
|
* @param array List of decorator names |
|
612
|
|
|
* @see client/html/common/decorators/default |
|
613
|
|
|
* @see client/html/catalog/detail/decorators/global |
|
614
|
|
|
* @see client/html/catalog/detail/decorators/local |
|
615
|
|
|
*/ |
|
616
|
|
|
|
|
617
|
|
|
/** client/html/catalog/detail/decorators/global |
|
618
|
|
|
* Adds a list of globally available decorators only to the catalog detail html client |
|
619
|
|
|
* |
|
620
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
|
621
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
|
622
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
|
623
|
|
|
* modify what is returned to the caller. |
|
624
|
|
|
* |
|
625
|
|
|
* This option allows you to wrap global decorators |
|
626
|
|
|
* ("\Aimeos\Client\Html\Common\Decorator\*") around the html client. |
|
627
|
|
|
* |
|
628
|
|
|
* client/html/catalog/detail/decorators/global = array( 'decorator1' ) |
|
629
|
|
|
* |
|
630
|
|
|
* This would add the decorator named "decorator1" defined by |
|
631
|
|
|
* "\Aimeos\Client\Html\Common\Decorator\Decorator1" only to the html client. |
|
632
|
|
|
* |
|
633
|
|
|
* @param array List of decorator names |
|
634
|
|
|
* @see client/html/common/decorators/default |
|
635
|
|
|
* @see client/html/catalog/detail/decorators/excludes |
|
636
|
|
|
* @see client/html/catalog/detail/decorators/local |
|
637
|
|
|
*/ |
|
638
|
|
|
|
|
639
|
|
|
/** client/html/catalog/detail/decorators/local |
|
640
|
|
|
* Adds a list of local decorators only to the catalog detail html client |
|
641
|
|
|
* |
|
642
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
|
643
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
|
644
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
|
645
|
|
|
* modify what is returned to the caller. |
|
646
|
|
|
* |
|
647
|
|
|
* This option allows you to wrap local decorators |
|
648
|
|
|
* ("\Aimeos\Client\Html\Catalog\Decorator\*") around the html client. |
|
649
|
|
|
* |
|
650
|
|
|
* client/html/catalog/detail/decorators/local = array( 'decorator2' ) |
|
651
|
|
|
* |
|
652
|
|
|
* This would add the decorator named "decorator2" defined by |
|
653
|
|
|
* "\Aimeos\Client\Html\Catalog\Decorator\Decorator2" only to the html client. |
|
654
|
|
|
* |
|
655
|
|
|
* @param array List of decorator names |
|
656
|
|
|
* @see client/html/common/decorators/default |
|
657
|
|
|
* @see client/html/catalog/detail/decorators/excludes |
|
658
|
|
|
* @see client/html/catalog/detail/decorators/global |
|
659
|
|
|
*/ |
|
660
|
|
|
} |
|
661
|
|
|
|