1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2016-2018 |
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
|
|
|
private $controller; |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Initializes the controller decorator. |
29
|
|
|
* |
30
|
|
|
* @param \Aimeos\Controller\Frontend\Iface $controller Controller object |
31
|
|
|
* @param \Aimeos\MShop\Context\Item\Iface $context Context object with required objects |
32
|
|
|
*/ |
33
|
|
|
public function __construct( \Aimeos\Controller\Frontend\Iface $controller, \Aimeos\MShop\Context\Item\Iface $context ) |
34
|
|
|
{ |
35
|
|
|
parent::__construct( $context ); |
36
|
|
|
|
37
|
|
|
$iface = \Aimeos\Controller\Frontend\Product\Iface::class; |
38
|
|
|
$this->controller = \Aimeos\MW\Common\Base::checkClass( $iface, $controller ); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Clones objects in decorator |
44
|
|
|
*/ |
45
|
|
|
public function __clone() |
46
|
|
|
{ |
47
|
|
|
$this->controller = clone $this->controller; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Passes unknown methods to wrapped objects. |
53
|
|
|
* |
54
|
|
|
* @param string $name Name of the method |
55
|
|
|
* @param array $param List of method parameter |
56
|
|
|
* @return mixed Returns the value of the called method |
57
|
|
|
* @throws \Aimeos\Controller\Frontend\Exception If method call failed |
58
|
|
|
*/ |
59
|
|
|
public function __call( $name, array $param ) |
60
|
|
|
{ |
61
|
|
|
return @call_user_func_array( array( $this->controller, $name ), $param ); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Returns the aggregated count of products for the given key. |
67
|
|
|
* |
68
|
|
|
* @param string $key Search key to aggregate for, e.g. "index.attribute.id" |
69
|
|
|
* @return array Associative list of key values as key and the product count for this key as value |
70
|
|
|
* @since 2019.04 |
71
|
|
|
*/ |
72
|
|
|
public function aggregate( $key ) |
73
|
|
|
{ |
74
|
|
|
return $this->controller->aggregate( $key ); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Adds attribute IDs for filtering where products must reference all IDs |
80
|
|
|
* |
81
|
|
|
* @param array|string $attrIds Attribute ID or list of IDs |
82
|
|
|
* @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface |
83
|
|
|
* @since 2019.04 |
84
|
|
|
*/ |
85
|
|
|
public function allOf( $attrIds ) |
86
|
|
|
{ |
87
|
|
|
$this->controller->allOf( $attrIds ); |
88
|
|
|
return $this; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Adds catalog IDs for filtering |
94
|
|
|
* |
95
|
|
|
* @param array|string $catIds Catalog ID or list of IDs |
96
|
|
|
* @param string $listtype List type of the products referenced by the categories |
97
|
|
|
* @param integer $level Constant from \Aimeos\MW\Tree\Manager\Base if products in subcategories are matched too |
98
|
|
|
* @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface |
99
|
|
|
* @since 2019.04 |
100
|
|
|
*/ |
101
|
|
|
public function category( $catIds, $listtype = 'default', $level = \Aimeos\MW\Tree\Manager\Base::LEVEL_ONE ) |
102
|
|
|
{ |
103
|
|
|
$this->controller->category( $catIds, $listtype, $level ); |
104
|
|
|
return $this; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Adds generic condition for filtering products |
110
|
|
|
* |
111
|
|
|
* @param string $operator Comparison operator, e.g. "==", "!=", "<", "<=", ">=", ">", "=~", "~=" |
112
|
|
|
* @param string $key Search key defined by the product manager, e.g. "product.status" |
113
|
|
|
* @param array|string $value Value or list of values to compare to |
114
|
|
|
* @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface |
115
|
|
|
* @since 2019.04 |
116
|
|
|
*/ |
117
|
|
|
public function compare( $operator, $key, $value ) |
118
|
|
|
{ |
119
|
|
|
$this->controller->compare( $operator, $key, $value ); |
120
|
|
|
return $this; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Returns the product for the given product code |
126
|
|
|
* |
127
|
|
|
* @param string $code Unique product code |
128
|
|
|
* @return \Aimeos\MShop\Product\Item\Iface Product item including the referenced domains items |
129
|
|
|
* @since 2019.04 |
130
|
|
|
*/ |
131
|
|
|
public function find( $code ) |
132
|
|
|
{ |
133
|
|
|
return $this->controller->find( $code ); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Returns the product for the given product ID |
139
|
|
|
* |
140
|
|
|
* @param string $id Unique product ID |
141
|
|
|
* @return \Aimeos\MShop\Product\Item\Iface Product item including the referenced domains items |
142
|
|
|
* @since 2019.04 |
143
|
|
|
*/ |
144
|
|
|
public function get( $id ) |
145
|
|
|
{ |
146
|
|
|
return $this->controller->get( $id ); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* Adds a filter to return only items containing a reference to the given ID |
152
|
|
|
* |
153
|
|
|
* @param string $domain Domain name of the referenced item, e.g. "attribute" |
154
|
|
|
* @param string|null $type Type code of the reference, e.g. "variant" or null for all types |
155
|
|
|
* @param string|null $refId ID of the referenced item of the given domain or null for all references |
156
|
|
|
* @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface |
157
|
|
|
* @since 2019.04 |
158
|
|
|
*/ |
159
|
|
|
public function has( $domain, $type = null, $refId = null ) |
160
|
|
|
{ |
161
|
|
|
$this->controller->has( $domain, $type, $refId ); |
162
|
|
|
return $this; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* Adds attribute IDs for filtering where products must reference at least one ID |
168
|
|
|
* |
169
|
|
|
* @param array|string $attrIds Attribute ID or list of IDs |
170
|
|
|
* @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface |
171
|
|
|
* @since 2019.04 |
172
|
|
|
*/ |
173
|
|
|
public function oneOf( $attrIds ) |
174
|
|
|
{ |
175
|
|
|
$this->controller->oneOf( $attrIds ); |
176
|
|
|
return $this; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* Parses the given array and adds the conditions to the list of conditions |
182
|
|
|
* |
183
|
|
|
* @param array $conditions List of conditions, e.g. ['&&' => [['>' => ['product.status' => 0]], ['==' => ['product.type' => 'default']]]] |
184
|
|
|
* @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface |
185
|
|
|
* @since 2019.04 |
186
|
|
|
*/ |
187
|
|
|
public function parse( array $conditions ) |
188
|
|
|
{ |
189
|
|
|
$this->controller->parse( $conditions ); |
190
|
|
|
return $this; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* Adds product IDs for filtering |
196
|
|
|
* |
197
|
|
|
* @param array|string $prodIds Product ID or list of IDs |
198
|
|
|
* @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface |
199
|
|
|
* @since 2019.04 |
200
|
|
|
*/ |
201
|
|
|
public function product( $prodIds ) |
202
|
|
|
{ |
203
|
|
|
$this->controller->product( $prodIds ); |
204
|
|
|
return $this; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* Adds a filter to return only items containing the property |
210
|
|
|
* |
211
|
|
|
* @param string $type Type code of the property, e.g. "isbn" |
212
|
|
|
* @param string|null $value Exact value of the property |
213
|
|
|
* @param string|null $langId ISO country code (en or en_US) or null if not language specific |
214
|
|
|
* @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface |
215
|
|
|
* @since 2019.04 |
216
|
|
|
*/ |
217
|
|
|
public function property( $type, $value = null, $langId = null ) |
218
|
|
|
{ |
219
|
|
|
$this->controller->property( $type, $value, $langId ); |
220
|
|
|
return $this; |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* Returns the product for the given product URL name |
226
|
|
|
* |
227
|
|
|
* @param string $name Product URL name |
228
|
|
|
* @return \Aimeos\MShop\Product\Item\Iface Product item including the referenced domains items |
229
|
|
|
* @since 2019.04 |
230
|
|
|
*/ |
231
|
|
|
public function resolve( $name ) |
232
|
|
|
{ |
233
|
|
|
return $this->controller->resolve( $name ); |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* Returns the products filtered by the previously assigned conditions |
239
|
|
|
* |
240
|
|
|
* @param integer &$total Parameter where the total number of found products will be stored in |
241
|
|
|
* @return \Aimeos\MShop\Product\Item\Iface[] Ordered list of product items |
242
|
|
|
* @since 2019.04 |
243
|
|
|
*/ |
244
|
|
|
public function search( &$total = null ) |
245
|
|
|
{ |
246
|
|
|
return $this->controller->search( $total ); |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* Sets the start value and the number of returned products for slicing the list of found products |
252
|
|
|
* |
253
|
|
|
* @param integer $start Start value of the first product in the list |
254
|
|
|
* @param integer $limit Number of returned products |
255
|
|
|
* @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface |
256
|
|
|
* @since 2019.04 |
257
|
|
|
*/ |
258
|
|
|
public function slice( $start, $limit ) |
259
|
|
|
{ |
260
|
|
|
$this->controller->slice( $start, $limit ); |
261
|
|
|
return $this; |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
|
265
|
|
|
/** |
266
|
|
|
* Sets the sorting of the result list |
267
|
|
|
* |
268
|
|
|
* @param string|null $key Sorting of the result list like "name", "-name", "price", "-price", "code", "-code", "ctime, "-ctime" and "relevance", null for no sorting |
269
|
|
|
* @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface |
270
|
|
|
* @since 2019.04 |
271
|
|
|
*/ |
272
|
|
|
public function sort( $key = null ) |
273
|
|
|
{ |
274
|
|
|
$this->controller->sort( $key ); |
275
|
|
|
return $this; |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
|
279
|
|
|
/** |
280
|
|
|
* Adds supplier IDs for filtering |
281
|
|
|
* |
282
|
|
|
* @param array|string $supIds Supplier ID or list of IDs |
283
|
|
|
* @param string $listtype List type of the products referenced by the suppliers |
284
|
|
|
* @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface |
285
|
|
|
* @since 2019.04 |
286
|
|
|
*/ |
287
|
|
|
public function supplier( $supIds, $listtype = 'default' ) |
288
|
|
|
{ |
289
|
|
|
$this->controller->supplier( $supIds, $listtype ); |
290
|
|
|
return $this; |
291
|
|
|
} |
292
|
|
|
|
293
|
|
|
|
294
|
|
|
/** |
295
|
|
|
* Adds input string for full text search |
296
|
|
|
* |
297
|
|
|
* @param string|null $text User input for full text search |
298
|
|
|
* @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface |
299
|
|
|
* @since 2019.04 |
300
|
|
|
*/ |
301
|
|
|
public function text( $text ) |
302
|
|
|
{ |
303
|
|
|
$this->controller->text( $text ); |
304
|
|
|
return $this; |
305
|
|
|
} |
306
|
|
|
|
307
|
|
|
|
308
|
|
|
/** |
309
|
|
|
* Sets the referenced domains that will be fetched too when retrieving items |
310
|
|
|
* |
311
|
|
|
* @param array $domains Domain names of the referenced items that should be fetched too |
312
|
|
|
* @return \Aimeos\Controller\Frontend\Product\Iface Product controller for fluent interface |
313
|
|
|
* @since 2019.04 |
314
|
|
|
*/ |
315
|
|
|
public function uses( array $domains ) |
316
|
|
|
{ |
317
|
|
|
$this->controller->text( $domains ); |
318
|
|
|
return $this; |
319
|
|
|
} |
320
|
|
|
|
321
|
|
|
|
322
|
|
|
/** |
323
|
|
|
* Returns the frontend controller |
324
|
|
|
* |
325
|
|
|
* @return \Aimeos\Controller\Frontend\Product\Iface Frontend controller object |
326
|
|
|
*/ |
327
|
|
|
protected function getController() |
328
|
|
|
{ |
329
|
|
|
return $this->controller; |
330
|
|
|
} |
331
|
|
|
} |
332
|
|
|
|