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\Product\Decorator; |
||
12 | |||
13 | |||
14 | /** |
||
15 | * Base for product 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\Product\Iface |
||
23 | { |
||
24 | use \Aimeos\Controller\Frontend\Common\Decorator\Traits; |
||
25 | |||
26 | |||
27 | private \Aimeos\Controller\Frontend\Product\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 | * Clones objects in decorator |
||
46 | */ |
||
47 | public function __clone() |
||
48 | { |
||
49 | $this->controller = clone $this->controller; |
||
50 | } |
||
51 | |||
52 | |||
53 | /** |
||
54 | * Passes unknown methods to wrapped objects. |
||
55 | * |
||
56 | * @param string $name Name of the method |
||
57 | * @param array $param List of method parameter |
||
58 | * @return mixed Returns the value of the called method |
||
59 | * @throws \Aimeos\Controller\Frontend\Exception If method call failed |
||
60 | */ |
||
61 | public function __call( string $name, array $param ) |
||
62 | { |
||
63 | return @call_user_func_array( array( $this->controller, $name ), $param ); |
||
64 | } |
||
65 | |||
66 | |||
67 | /** |
||
68 | * Returns the aggregated count of products for the given key. |
||
69 | * |
||
70 | * @param string $key Search key to aggregate for, e.g. "index.attribute.id" |
||
71 | * @param string|null $value Search key for aggregating the value column |
||
72 | * @param string|null $type Type of the aggregation, empty string for count or "sum" or "avg" (average) |
||
73 | * @return \Aimeos\Map Associative list of key values as key and the product count for this key as value |
||
74 | * @since 2019.04 |
||
75 | */ |
||
76 | public function aggregate( string $key, string $value = null, string $type = null ) : \Aimeos\Map |
||
77 | { |
||
78 | return $this->controller->aggregate( $key, $value, $type ); |
||
79 | } |
||
80 | |||
81 | |||
82 | /** |
||
83 | * Adds attribute IDs for filtering where products must reference all IDs |
||
84 | * |
||
85 | * @param array|string $attrIds Attribute ID or list of IDs |
||
86 | * @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface |
||
87 | * @since 2019.04 |
||
88 | */ |
||
89 | public function allOf( $attrIds ) : \Aimeos\Controller\Frontend\Product\Iface |
||
90 | { |
||
91 | $this->controller->allOf( $attrIds ); |
||
92 | return $this; |
||
93 | } |
||
94 | |||
95 | |||
96 | /** |
||
97 | * Adds catalog IDs for filtering |
||
98 | * |
||
99 | * @param array|string $catIds Catalog ID or list of IDs |
||
100 | * @param string $listtype List type of the products referenced by the categories |
||
101 | * @param int $level Constant from \Aimeos\MW\Tree\Manager\Base if products in subcategories are matched too |
||
102 | * @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface |
||
103 | * @since 2019.04 |
||
104 | */ |
||
105 | public function category( $catIds, string $listtype = 'default', int $level = \Aimeos\MW\Tree\Manager\Base::LEVEL_ONE ) : \Aimeos\Controller\Frontend\Product\Iface |
||
106 | { |
||
107 | $this->controller->category( $catIds, $listtype, $level ); |
||
108 | return $this; |
||
109 | } |
||
110 | |||
111 | |||
112 | /** |
||
113 | * Adds generic condition for filtering products |
||
114 | * |
||
115 | * @param string $operator Comparison operator, e.g. "==", "!=", "<", "<=", ">=", ">", "=~", "~=" |
||
116 | * @param string $key Search key defined by the product manager, e.g. "product.status" |
||
117 | * @param array|string $value Value or list of values to compare to |
||
118 | * @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface |
||
119 | * @since 2019.04 |
||
120 | */ |
||
121 | public function compare( string $operator, string $key, $value ) : \Aimeos\Controller\Frontend\Product\Iface |
||
122 | { |
||
123 | $this->controller->compare( $operator, $key, $value ); |
||
124 | return $this; |
||
125 | } |
||
126 | |||
127 | |||
128 | /** |
||
129 | * Returns the product for the given product code |
||
130 | * |
||
131 | * @param string $code Unique product code |
||
132 | * @return \Aimeos\MShop\Product\Item\Iface Product item including the referenced domains items |
||
133 | * @since 2019.04 |
||
134 | */ |
||
135 | public function find( string $code ) : \Aimeos\MShop\Product\Item\Iface |
||
136 | { |
||
137 | return $this->controller->find( $code ); |
||
138 | } |
||
139 | |||
140 | |||
141 | /** |
||
142 | * Creates a search function string for the given name and parameters |
||
143 | * |
||
144 | * @param string $name Name of the search function without parenthesis, e.g. "product:has" |
||
145 | * @param array $params List of parameters for the search function with numeric keys starting at 0 |
||
146 | * @return string Search function string that can be used in compare() |
||
147 | */ |
||
148 | public function function( string $name, array $params ) : string |
||
149 | { |
||
150 | return $this->controller->function( $name, $params ); |
||
151 | } |
||
152 | |||
153 | |||
154 | /** |
||
155 | * Returns the product for the given product ID |
||
156 | * |
||
157 | * @param string $id Unique product ID |
||
158 | * @return \Aimeos\MShop\Product\Item\Iface Product item including the referenced domains items |
||
159 | * @since 2019.04 |
||
160 | */ |
||
161 | public function get( string $id ) : \Aimeos\MShop\Product\Item\Iface |
||
162 | { |
||
163 | return $this->controller->get( $id ); |
||
164 | } |
||
165 | |||
166 | |||
167 | /** |
||
168 | * Adds a filter to return only items containing a reference to the given ID |
||
169 | * |
||
170 | * @param string $domain Domain name of the referenced item, e.g. "attribute" |
||
171 | * @param string|null $type Type code of the reference, e.g. "variant" or null for all types |
||
172 | * @param string|null $refId ID of the referenced item of the given domain or null for all references |
||
173 | * @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface |
||
174 | * @since 2019.04 |
||
175 | */ |
||
176 | public function has( string $domain, string $type = null, string $refId = null ) : \Aimeos\Controller\Frontend\Product\Iface |
||
177 | { |
||
178 | $this->controller->has( $domain, $type, $refId ); |
||
179 | return $this; |
||
180 | } |
||
181 | |||
182 | |||
183 | /** |
||
184 | * Adds attribute IDs for filtering where products must reference at least one ID |
||
185 | * |
||
186 | * @param array|string $attrIds Attribute ID or list of IDs |
||
187 | * @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface |
||
188 | * @since 2019.04 |
||
189 | */ |
||
190 | public function oneOf( $attrIds ) : \Aimeos\Controller\Frontend\Product\Iface |
||
191 | { |
||
192 | $this->controller->oneOf( $attrIds ); |
||
193 | return $this; |
||
194 | } |
||
195 | |||
196 | |||
197 | /** |
||
198 | * Parses the given array and adds the conditions to the list of conditions |
||
199 | * |
||
200 | * @param array $conditions List of conditions, e.g. ['&&' => [['>' => ['product.status' => 0]], ['==' => ['product.type' => 'default']]]] |
||
201 | * @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface |
||
202 | * @since 2019.04 |
||
203 | */ |
||
204 | public function parse( array $conditions ) : \Aimeos\Controller\Frontend\Product\Iface |
||
205 | { |
||
206 | $this->controller->parse( $conditions ); |
||
207 | return $this; |
||
208 | } |
||
209 | |||
210 | |||
211 | /** |
||
212 | * Adds price restrictions for filtering |
||
213 | * |
||
214 | * @param array|string|null $value Upper price limit, list of lower and upper price or NULL for no restrictions |
||
215 | * @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface |
||
216 | * @since 2020.10 |
||
217 | */ |
||
218 | public function price( $value = null ) : \Aimeos\Controller\Frontend\Product\Iface |
||
219 | { |
||
220 | $this->controller->price( $value ); |
||
221 | return $this; |
||
222 | } |
||
223 | |||
224 | |||
225 | /** |
||
226 | * Adds product IDs for filtering |
||
227 | * |
||
228 | * @param array|string $prodIds Product ID or list of IDs |
||
229 | * @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface |
||
230 | * @since 2019.04 |
||
231 | */ |
||
232 | public function product( $prodIds ) : \Aimeos\Controller\Frontend\Product\Iface |
||
233 | { |
||
234 | $this->controller->product( $prodIds ); |
||
235 | return $this; |
||
236 | } |
||
237 | |||
238 | |||
239 | /** |
||
240 | * Adds a filter to return only items containing the property |
||
241 | * |
||
242 | * @param string $type Type code of the property, e.g. "isbn" |
||
243 | * @param string|null $value Exact value of the property |
||
244 | * @param string|null $langId ISO country code (en or en_US) or null if not language specific |
||
245 | * @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface |
||
246 | * @since 2019.04 |
||
247 | */ |
||
248 | public function property( string $type, string $value = null, string $langId = null ) : \Aimeos\Controller\Frontend\Product\Iface |
||
249 | { |
||
250 | $this->controller->property( $type, $value, $langId ); |
||
251 | return $this; |
||
252 | } |
||
253 | |||
254 | |||
255 | /** |
||
256 | * Adds radius restrictions for filtering |
||
257 | * |
||
258 | * @param array $latlon Latitude and longitude value or empty for no restrictions |
||
259 | * @param float|null $dist Distance around latitude/longitude or NULL for no restrictions |
||
260 | * @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface |
||
261 | * @since 2021.10 |
||
262 | */ |
||
263 | public function radius( array $latlon, float $dist = null ) : \Aimeos\Controller\Frontend\Product\Iface |
||
264 | { |
||
265 | $this->controller->radius( $latlon, $dist ); |
||
266 | return $this; |
||
267 | } |
||
268 | |||
269 | |||
270 | /** |
||
271 | * Returns the product for the given product URL name |
||
272 | * |
||
273 | * @param string $name Product URL name |
||
274 | * @return \Aimeos\MShop\Product\Item\Iface Product item including the referenced domains items |
||
275 | * @since 2019.04 |
||
276 | */ |
||
277 | public function resolve( string $name ) : \Aimeos\MShop\Product\Item\Iface |
||
278 | { |
||
279 | return $this->controller->resolve( $name ); |
||
280 | } |
||
281 | |||
282 | |||
283 | /** |
||
284 | * Returns the products filtered by the previously assigned conditions |
||
285 | * |
||
286 | * @param int &$total Parameter where the total number of found products will be stored in |
||
287 | * @return \Aimeos\Map Ordered list of items implementing \Aimeos\MShop\Product\Item\Iface |
||
288 | * @since 2019.04 |
||
289 | */ |
||
290 | public function search( int &$total = null ) : \Aimeos\Map |
||
291 | { |
||
292 | return $this->controller->search( $total ); |
||
293 | } |
||
294 | |||
295 | |||
296 | /** |
||
297 | * Sets the start value and the number of returned products for slicing the list of found products |
||
298 | * |
||
299 | * @param int $start Start value of the first product in the list |
||
300 | * @param int $limit Number of returned products |
||
301 | * @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface |
||
302 | * @since 2019.04 |
||
303 | */ |
||
304 | public function slice( int $start, int $limit ) : \Aimeos\Controller\Frontend\Product\Iface |
||
305 | { |
||
306 | $this->controller->slice( $start, $limit ); |
||
307 | return $this; |
||
308 | } |
||
309 | |||
310 | |||
311 | /** |
||
312 | * Sets the sorting of the result list |
||
313 | * |
||
314 | * @param string|null $key Sorting of the result list like "name", "-name", "price", "-price", "code", "-code", "ctime, "-ctime" and "relevance", null for no sorting |
||
315 | * @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface |
||
316 | * @since 2019.04 |
||
317 | */ |
||
318 | public function sort( string $key = null ) : \Aimeos\Controller\Frontend\Product\Iface |
||
319 | { |
||
320 | $this->controller->sort( $key ); |
||
321 | return $this; |
||
322 | } |
||
323 | |||
324 | |||
325 | /** |
||
326 | * Adds supplier IDs for filtering |
||
327 | * |
||
328 | * @param array|string $supIds Supplier ID or list of IDs |
||
329 | * @param string $listtype List type of the products referenced by the suppliers |
||
330 | * @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface |
||
331 | * @since 2019.04 |
||
332 | */ |
||
333 | public function supplier( $supIds, string $listtype = 'default' ) : \Aimeos\Controller\Frontend\Product\Iface |
||
334 | { |
||
335 | $this->controller->supplier( $supIds, $listtype ); |
||
336 | return $this; |
||
337 | } |
||
338 | |||
339 | |||
340 | /** |
||
341 | * Adds input string for full text search |
||
342 | * |
||
343 | * @param string|null $text User input for full text search |
||
344 | * @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface |
||
345 | * @since 2019.04 |
||
346 | */ |
||
347 | public function text( string $text = null ) : \Aimeos\Controller\Frontend\Product\Iface |
||
348 | { |
||
349 | $this->controller->text( $text ); |
||
350 | return $this; |
||
351 | } |
||
352 | |||
353 | |||
354 | /** |
||
355 | * Sets the referenced domains that will be fetched too when retrieving items |
||
356 | * |
||
357 | * @param array $domains Domain names of the referenced items that should be fetched too |
||
358 | * @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface |
||
359 | * @since 2019.04 |
||
360 | */ |
||
361 | public function uses( array $domains ) : \Aimeos\Controller\Frontend\Product\Iface |
||
362 | { |
||
363 | $this->controller->uses( $domains ); |
||
364 | return $this; |
||
365 | } |
||
366 | |||
367 | |||
368 | /** |
||
369 | * Injects the reference of the outmost object |
||
370 | * |
||
371 | * @param \Aimeos\Controller\Frontend\Iface $object Reference to the outmost controller or decorator |
||
372 | * @return \Aimeos\Controller\Frontend\Iface Controller object for chaining method calls |
||
373 | */ |
||
374 | public function setObject( \Aimeos\Controller\Frontend\Iface $object ) : \Aimeos\Controller\Frontend\Iface |
||
375 | { |
||
376 | parent::setObject( $object ); |
||
377 | |||
378 | $this->controller->setObject( $object ); |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
379 | |||
380 | return $this; |
||
381 | } |
||
382 | |||
383 | |||
384 | /** |
||
385 | * Returns the frontend controller |
||
386 | * |
||
387 | * @return \Aimeos\Controller\Frontend\Iface Frontend controller object |
||
388 | */ |
||
389 | protected function getController() : \Aimeos\Controller\Frontend\Iface |
||
390 | { |
||
391 | return $this->controller; |
||
392 | } |
||
393 | } |
||
394 |