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\Catalog\Session\Pinned; |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Default implementation of catalog session pinned section for HTML clients. |
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
|
|
|
/** |
26
|
|
|
* Returns the HTML code for insertion into the body. |
27
|
|
|
* |
28
|
|
|
* @param string $uid Unique identifier for the output if the content is placed more than once on the same page |
29
|
|
|
* @return string HTML code |
30
|
|
|
*/ |
31
|
|
|
public function body( string $uid = '' ) : string |
32
|
|
|
{ |
33
|
|
|
$view = $this->view(); |
34
|
|
|
$context = $this->context(); |
35
|
|
|
$session = $context->session(); |
36
|
|
|
|
37
|
|
|
/** client/html/catalog/session/pinned |
38
|
|
|
* All parameters defined for the catalog session pinned subpart |
39
|
|
|
* |
40
|
|
|
* This returns all settings related to the catalog session pinned subpart. |
41
|
|
|
* Please refer to the single settings for details. |
42
|
|
|
* |
43
|
|
|
* @param array Associative list of name/value settings |
44
|
|
|
*/ |
45
|
|
|
$config = $context->config()->get( 'client/html/catalog/session/pinned', [] ); |
46
|
|
|
$key = $this->getParamHash( [], $uid . ':catalog:session-pinned-body', $config ); |
47
|
|
|
|
48
|
|
|
if( ( $html = $session->get( $key ) ) === null ) |
49
|
|
|
{ |
50
|
|
|
/** client/html/catalog/session/pinned/template-body |
51
|
|
|
* Relative path to the HTML body template of the catalog session pinned client. |
52
|
|
|
* |
53
|
|
|
* The template file contains the HTML code and processing instructions |
54
|
|
|
* to generate the result shown in the body of the frontend. The |
55
|
|
|
* configuration string is the path to the template file relative |
56
|
|
|
* to the templates directory (usually in templates/client/html). |
57
|
|
|
* |
58
|
|
|
* You can overwrite the template file configuration in extensions and |
59
|
|
|
* provide alternative templates. These alternative templates should be |
60
|
|
|
* named like the default one but suffixed by |
61
|
|
|
* an unique name. You may use the name of your project for this. If |
62
|
|
|
* you've implemented an alternative client class as well, it |
63
|
|
|
* should be suffixed by the name of the new class. |
64
|
|
|
* |
65
|
|
|
* @param string Relative path to the template creating code for the HTML page body |
66
|
|
|
* @since 2014.03 |
67
|
|
|
* @see client/html/catalog/session/pinned/template-header |
68
|
|
|
*/ |
69
|
|
|
$tplconf = 'client/html/catalog/session/pinned/template-body'; |
70
|
|
|
$default = 'catalog/session/pinned-body'; |
71
|
|
|
|
72
|
|
|
$html = $view->render( $view->config( $tplconf, $default ) ); |
73
|
|
|
|
74
|
|
|
$cached = $session->get( 'aimeos/catalog/session/pinned/cache', [] ) + array( $key => true ); |
75
|
|
|
$session->set( 'aimeos/catalog/session/pinned/cache', $cached ); |
76
|
|
|
$session->set( $key, $html ); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
$view->block()->set( 'catalog/session/pinned', $html ); |
80
|
|
|
|
81
|
|
|
return $html; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Processes the input, e.g. store given values. |
87
|
|
|
* |
88
|
|
|
* A view must be available and this method doesn't generate any output |
89
|
|
|
* besides setting view variables if necessary. |
90
|
|
|
*/ |
91
|
|
|
public function init() |
92
|
|
|
{ |
93
|
|
|
$refresh = false; |
94
|
|
|
$view = $this->view(); |
95
|
|
|
$context = $this->context(); |
96
|
|
|
$session = $context->session(); |
97
|
|
|
$pinned = $session->get( 'aimeos/catalog/session/pinned/list', [] ); |
98
|
|
|
|
99
|
|
|
if( $view->request()->getMethod() === 'POST' ) |
100
|
|
|
{ |
101
|
|
|
switch( $view->param( 'pin_action' ) ) |
102
|
|
|
{ |
103
|
|
|
case 'add': |
104
|
|
|
|
105
|
|
|
foreach( (array) $view->param( 'pin_id', [] ) as $id ) { |
106
|
|
|
$pinned[$id] = $id; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** client/html/catalog/session/pinned/maxitems |
110
|
|
|
* Maximum number of products displayed in the "pinned" section |
111
|
|
|
* |
112
|
|
|
* This option limits the number of products that are shown in the |
113
|
|
|
* "pinned" section after the users added the product to their list |
114
|
|
|
* of pinned products. It must be a positive integer value greater |
115
|
|
|
* than 0. |
116
|
|
|
* |
117
|
|
|
* Note: The higher the value is the more data has to be transfered |
118
|
|
|
* to the client each time the user loads a page with the list of |
119
|
|
|
* pinned products. |
120
|
|
|
* |
121
|
|
|
* @param integer Number of products |
122
|
|
|
* @since 2014.09 |
123
|
|
|
*/ |
124
|
|
|
$max = $context->config()->get( 'client/html/catalog/session/pinned/maxitems', 50 ); |
125
|
|
|
|
126
|
|
|
$pinned = array_slice( $pinned, -$max, $max, true ); |
127
|
|
|
$refresh = true; |
128
|
|
|
break; |
129
|
|
|
|
130
|
|
|
case 'delete': |
131
|
|
|
|
132
|
|
|
foreach( (array) $view->param( 'pin_id', [] ) as $id ) { |
133
|
|
|
unset( $pinned[$id] ); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
$refresh = true; |
137
|
|
|
break; |
138
|
|
|
} |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
|
142
|
|
|
if( $refresh ) |
143
|
|
|
{ |
144
|
|
|
$session->set( 'aimeos/catalog/session/pinned/list', $pinned ); |
145
|
|
|
|
146
|
|
|
foreach( $session->get( 'aimeos/catalog/session/pinned/cache', [] ) as $key => $value ) { |
147
|
|
|
$session->set( $key, null ); |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Sets the necessary parameter values in the view. |
155
|
|
|
* |
156
|
|
|
* @param \Aimeos\Base\View\Iface $view The view object which generates the HTML output |
157
|
|
|
* @param array &$tags Result array for the list of tags that are associated to the output |
158
|
|
|
* @param string|null &$expire Result variable for the expiration date of the output (null for no expiry) |
159
|
|
|
* @return \Aimeos\Base\View\Iface Modified view object |
160
|
|
|
*/ |
161
|
|
|
public function data( \Aimeos\Base\View\Iface $view, array &$tags = [], ?string &$expire = null ) : \Aimeos\Base\View\Iface |
162
|
|
|
{ |
163
|
|
|
$items = []; |
164
|
|
|
$context = $this->context(); |
165
|
|
|
$config = $context->config(); |
166
|
|
|
$session = $context->session(); |
167
|
|
|
|
168
|
|
|
$domains = $config->get( 'client/html/catalog/domains', ['catalog', 'media', 'price', 'text'] ); |
169
|
|
|
|
170
|
|
|
/** client/html/catalog/session/pinned/domains |
171
|
|
|
* A list of domain names whose items should be available in the pinned view template for the product |
172
|
|
|
* |
173
|
|
|
* The templates rendering product details usually add the images, |
174
|
|
|
* prices and texts, etc. associated to the product |
175
|
|
|
* item. If you want to display additional or less content, you can |
176
|
|
|
* configure your own list of domains (attribute, media, price, product, |
177
|
|
|
* text, etc. are domains) whose items are fetched from the storage. |
178
|
|
|
* Please keep in mind that the more domains you add to the configuration, |
179
|
|
|
* the more time is required for fetching the content! |
180
|
|
|
* |
181
|
|
|
* @param array List of domain names |
182
|
|
|
* @since 2015.04 |
183
|
|
|
* @see client/html/catalog/domains |
184
|
|
|
* @see client/html/catalog/lists/domains |
185
|
|
|
* @see client/html/catalog/detail/domains |
186
|
|
|
*/ |
187
|
|
|
$domains = $config->get( 'client/html/catalog/session/pinned/domains', $domains ); |
188
|
|
|
|
189
|
|
|
if( ( $pinned = $session->get( 'aimeos/catalog/session/pinned/list', [] ) ) !== [] ) |
190
|
|
|
{ |
191
|
|
|
$result = \Aimeos\Controller\Frontend::create( $context, 'product' ) |
192
|
|
|
->uses( $domains )->product( $pinned )->slice( 0, count( $pinned ) )->search(); |
193
|
|
|
|
194
|
|
|
foreach( array_reverse( $pinned ) as $id ) |
195
|
|
|
{ |
196
|
|
|
if( isset( $result[$id] ) ) { |
197
|
|
|
$items[$id] = $result[$id]; |
198
|
|
|
} |
199
|
|
|
} |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
$view->pinnedProductItems = $items; |
203
|
|
|
$view->pinnedParams = $this->getClientParams( $view->param() ); |
204
|
|
|
|
205
|
|
|
return parent::data( $view, $tags, $expire ); |
206
|
|
|
} |
207
|
|
|
} |
208
|
|
|
|