1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2016-2024 |
6
|
|
|
* @package Controller |
7
|
|
|
* @subpackage Frontend |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
namespace Aimeos\Controller\Frontend\Catalog\Decorator; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Base for catalog frontend controller decorators |
16
|
|
|
* |
17
|
|
|
* @package Controller |
18
|
|
|
* @subpackage Frontend |
19
|
|
|
*/ |
20
|
|
|
abstract class Base |
21
|
|
|
extends \Aimeos\Controller\Frontend\Base |
22
|
|
|
implements \Aimeos\Controller\Frontend\Common\Decorator\Iface, \Aimeos\Controller\Frontend\Catalog\Iface |
23
|
|
|
{ |
24
|
|
|
use \Aimeos\Controller\Frontend\Common\Decorator\Traits; |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
private \Aimeos\Controller\Frontend\Catalog\Iface $controller; |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Initializes the controller decorator. |
32
|
|
|
* |
33
|
|
|
* @param \Aimeos\Controller\Frontend\Iface $controller Controller object |
34
|
|
|
* @param \Aimeos\MShop\ContextIface $context Context object with required objects |
35
|
|
|
*/ |
36
|
|
|
public function __construct( \Aimeos\Controller\Frontend\Iface $controller, \Aimeos\MShop\ContextIface $context ) |
37
|
|
|
{ |
38
|
|
|
parent::__construct( $context ); |
39
|
|
|
|
40
|
|
|
$this->controller = $controller; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Passes unknown methods to wrapped objects. |
46
|
|
|
* |
47
|
|
|
* @param string $name Name of the method |
48
|
|
|
* @param array $param List of method parameter |
49
|
|
|
* @return mixed Returns the value of the called method |
50
|
|
|
* @throws \Aimeos\Controller\Frontend\Exception If method call failed |
51
|
|
|
*/ |
52
|
|
|
public function __call( string $name, array $param ) |
53
|
|
|
{ |
54
|
|
|
return @call_user_func_array( array( $this->controller, $name ), $param ); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Clones objects in controller and resets values |
60
|
|
|
*/ |
61
|
|
|
public function __clone() |
62
|
|
|
{ |
63
|
|
|
$this->controller = clone $this->controller; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Adds generic condition for filtering attributes |
69
|
|
|
* |
70
|
|
|
* @param string $operator Comparison operator, e.g. "==", "!=", "<", "<=", ">=", ">", "=~", "~=" |
71
|
|
|
* @param string $key Search key defined by the catalog manager, e.g. "catalog.status" |
72
|
|
|
* @param array|string $value Value or list of values to compare to |
73
|
|
|
* @return \Aimeos\Controller\Frontend\Catalog\Iface Catalog controller for fluent interface |
74
|
|
|
* @since 2019.04 |
75
|
|
|
*/ |
76
|
|
|
public function compare( string $operator, string $key, $value ) : \Aimeos\Controller\Frontend\Catalog\Iface |
77
|
|
|
{ |
78
|
|
|
$this->controller->compare( $operator, $key, $value ); |
79
|
|
|
return $this; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Returns the category for the given catalog code |
85
|
|
|
* |
86
|
|
|
* @param string $code Unique catalog code |
87
|
|
|
* @return \Aimeos\MShop\Catalog\Item\Iface Catalog item including the referenced domains items |
88
|
|
|
* @since 2019.04 |
89
|
|
|
*/ |
90
|
|
|
public function find( string $code ) : \Aimeos\MShop\Catalog\Item\Iface |
91
|
|
|
{ |
92
|
|
|
return $this->controller->find( $code ); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Creates a search function string for the given name and parameters |
98
|
|
|
* |
99
|
|
|
* @param string $name Name of the search function without parenthesis, e.g. "catalog:has" |
100
|
|
|
* @param array $params List of parameters for the search function with numeric keys starting at 0 |
101
|
|
|
* @return string Search function string that can be used in compare() |
102
|
|
|
*/ |
103
|
|
|
public function function( string $name, array $params ) : string |
104
|
|
|
{ |
105
|
|
|
return $this->controller->function( $name, $params ); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Returns the category for the given catalog ID |
111
|
|
|
* |
112
|
|
|
* @param string $id Unique catalog ID |
113
|
|
|
* @return \Aimeos\MShop\Catalog\Item\Iface Catalog item including the referenced domains items |
114
|
|
|
* @since 2019.04 |
115
|
|
|
*/ |
116
|
|
|
public function get( string $id ) : \Aimeos\MShop\Catalog\Item\Iface |
117
|
|
|
{ |
118
|
|
|
return $this->controller->get( $id ); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Returns the list of categories up to the root node including the node given by its ID |
124
|
|
|
* |
125
|
|
|
* @param string $id Current category ID |
126
|
|
|
* @return \Aimeos\MShop\Catalog\Item\Iface[] Associative list of categories |
127
|
|
|
* @since 2017.03 |
128
|
|
|
*/ |
129
|
|
|
public function getPath( string $id ) |
130
|
|
|
{ |
131
|
|
|
return $this->controller->getPath( $id ); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Returns the categories filtered by the previously assigned conditions |
137
|
|
|
* |
138
|
|
|
* @param int $level Tree level constant, e.g. ONE, LIST or TREE |
139
|
|
|
* @return \Aimeos\MShop\Catalog\Item\Iface Category tree |
140
|
|
|
* @since 2019.04 |
141
|
|
|
*/ |
142
|
|
|
public function getTree( int $level = \Aimeos\Controller\Frontend\Catalog\Iface::TREE ) : \Aimeos\MShop\Catalog\Item\Iface |
143
|
|
|
{ |
144
|
|
|
return $this->controller->getTree( $level ); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Adds a filter to return only items containing a reference to the given ID |
150
|
|
|
* |
151
|
|
|
* @param string $domain Domain name of the referenced item, e.g. "product" |
152
|
|
|
* @param string|null $type Type code of the reference, e.g. "default" or null for all types |
153
|
|
|
* @param string|null $refId ID of the referenced item of the given domain or null for all references |
154
|
|
|
* @return \Aimeos\Controller\Frontend\Catalog\Iface Catalog controller for fluent interface |
155
|
|
|
* @since 2019.10 |
156
|
|
|
*/ |
157
|
|
|
public function has( string $domain, string $type = null, string $refId = null ) : \Aimeos\Controller\Frontend\Catalog\Iface |
158
|
|
|
{ |
159
|
|
|
$this->controller->has( $domain, $type, $refId ); |
160
|
|
|
return $this; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* Parses the given array and adds the conditions to the list of conditions |
166
|
|
|
* |
167
|
|
|
* @param array $conditions List of conditions, e.g. ['>' => ['catalog.status' => 0]] |
168
|
|
|
* @return \Aimeos\Controller\Frontend\Catalog\Iface Catalog controller for fluent interface |
169
|
|
|
* @since 2019.04 |
170
|
|
|
*/ |
171
|
|
|
public function parse( array $conditions ) : \Aimeos\Controller\Frontend\Catalog\Iface |
172
|
|
|
{ |
173
|
|
|
$this->controller->parse( $conditions ); |
174
|
|
|
return $this; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* Returns the catalog item for the given category URL name |
180
|
|
|
* |
181
|
|
|
* @param string $name Catalog URL name |
182
|
|
|
* @return \Aimeos\MShop\Catalog\Item\Iface Catalog item including the referenced domains items |
183
|
|
|
* @since 2023.10 |
184
|
|
|
*/ |
185
|
|
|
public function resolve( string $name ) : \Aimeos\MShop\Catalog\Item\Iface |
186
|
|
|
{ |
187
|
|
|
return $this->controller->resolve( $name ); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* Sets the catalog ID of node that is used as root node |
193
|
|
|
* |
194
|
|
|
* @param string|null $id Catalog ID |
195
|
|
|
* @return \Aimeos\Controller\Frontend\Catalog\Iface Catalog controller for fluent interface |
196
|
|
|
* @since 2019.04 |
197
|
|
|
*/ |
198
|
|
|
public function root( string $id = null ) : \Aimeos\Controller\Frontend\Catalog\Iface |
199
|
|
|
{ |
200
|
|
|
$this->controller->root( $id ); |
201
|
|
|
return $this; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* Returns the categories filtered by the previously assigned conditions |
206
|
|
|
* |
207
|
|
|
* @param int &$total Parameter where the total number of found categories will be stored in |
208
|
|
|
* @return \Aimeos\Map Ordered list of items implementing \Aimeos\MShop\Catalog\Item\Iface |
209
|
|
|
* @since 2019.10 |
210
|
|
|
*/ |
211
|
|
|
public function search( int &$total = null ) : \Aimeos\Map |
212
|
|
|
{ |
213
|
|
|
return $this->controller->search( $total ); |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* Sets the start value and the number of returned products for slicing the list of found products |
219
|
|
|
* |
220
|
|
|
* @param int $start Start value of the first product in the list |
221
|
|
|
* @param int $limit Number of returned products |
222
|
|
|
* @return \Aimeos\Controller\Frontend\Catalog\Iface Catalog controller for fluent interface |
223
|
|
|
* @since 2019.10 |
224
|
|
|
*/ |
225
|
|
|
public function slice( int $start, int $limit ) : \Aimeos\Controller\Frontend\Catalog\Iface |
226
|
|
|
{ |
227
|
|
|
$this->controller->slice( $start, $limit ); |
228
|
|
|
return $this; |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* Sets the sorting of the result list |
234
|
|
|
* |
235
|
|
|
* @param string|null $key Search key for sorting of the result list and null for no sorting |
236
|
|
|
* @return \Aimeos\Controller\Frontend\Catalog\Iface Catalog controller for fluent interface |
237
|
|
|
* @since 2019.10 |
238
|
|
|
*/ |
239
|
|
|
public function sort( ?string $key = null ) : \Aimeos\Controller\Frontend\Catalog\Iface |
240
|
|
|
{ |
241
|
|
|
$this->controller->sort( $key ); |
242
|
|
|
return $this; |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* Sets the referenced domains that will be fetched too when retrieving items |
248
|
|
|
* |
249
|
|
|
* @param array $domains Domain names of the referenced items that should be fetched too |
250
|
|
|
* @return \Aimeos\Controller\Frontend\Catalog\Iface Catalog controller for fluent interface |
251
|
|
|
* @since 2019.04 |
252
|
|
|
*/ |
253
|
|
|
public function uses( array $domains ) : \Aimeos\Controller\Frontend\Catalog\Iface |
254
|
|
|
{ |
255
|
|
|
$this->controller->uses( $domains ); |
256
|
|
|
return $this; |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
|
260
|
|
|
/** |
261
|
|
|
* Limits categories returned to only visible ones depending on the given category IDs |
262
|
|
|
* |
263
|
|
|
* @param array $catIds List of category IDs |
264
|
|
|
* @return \Aimeos\Controller\Frontend\Catalog\Iface Catalog controller for fluent interface |
265
|
|
|
*/ |
266
|
|
|
public function visible( array $catIds ) : \Aimeos\Controller\Frontend\Catalog\Iface |
267
|
|
|
{ |
268
|
|
|
$this->controller->visible( $catIds ); |
269
|
|
|
return $this; |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
|
273
|
|
|
/** |
274
|
|
|
* Injects the reference of the outmost object |
275
|
|
|
* |
276
|
|
|
* @param \Aimeos\Controller\Frontend\Iface $object Reference to the outmost controller or decorator |
277
|
|
|
* @return \Aimeos\Controller\Frontend\Iface Controller object for chaining method calls |
278
|
|
|
*/ |
279
|
|
|
public function setObject( \Aimeos\Controller\Frontend\Iface $object ) : \Aimeos\Controller\Frontend\Iface |
280
|
|
|
{ |
281
|
|
|
parent::setObject( $object ); |
282
|
|
|
|
283
|
|
|
$this->controller->setObject( $object ); |
|
|
|
|
284
|
|
|
|
285
|
|
|
return $this; |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
|
289
|
|
|
/** |
290
|
|
|
* Returns the frontend controller |
291
|
|
|
* |
292
|
|
|
* @return \Aimeos\Controller\Frontend\Iface Frontend controller object |
293
|
|
|
*/ |
294
|
|
|
protected function getController() : \Aimeos\Controller\Frontend\Iface |
295
|
|
|
{ |
296
|
|
|
return $this->controller; |
297
|
|
|
} |
298
|
|
|
} |
299
|
|
|
|