|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2012 |
|
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2017 |
|
7
|
|
|
* @package Controller |
|
8
|
|
|
* @subpackage Frontend |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
namespace Aimeos\Controller\Frontend\Catalog; |
|
13
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Default implementation of the catalog frontend controller. |
|
17
|
|
|
* |
|
18
|
|
|
* @package Controller |
|
19
|
|
|
* @subpackage Frontend |
|
20
|
|
|
*/ |
|
21
|
|
|
class Standard |
|
22
|
|
|
extends \Aimeos\Controller\Frontend\Base |
|
|
|
|
|
|
23
|
|
|
implements Iface, \Aimeos\Controller\Frontend\Common\Iface |
|
|
|
|
|
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* Returns the manager for the given name |
|
27
|
|
|
* |
|
28
|
|
|
* @param string $name Name of the manager |
|
29
|
|
|
* @return \Aimeos\MShop\Common\Manager\Iface Manager object |
|
30
|
|
|
* @since 2015.08 |
|
31
|
|
|
*/ |
|
32
|
|
|
public function createManager( $name ) |
|
33
|
|
|
{ |
|
34
|
|
|
return \Aimeos\MShop\Factory::createManager( $this->getContext(), $name ); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Returns the default catalog filter |
|
40
|
|
|
* |
|
41
|
|
|
* @param boolean True to add default criteria, e.g. status > 0 |
|
42
|
|
|
* @return \Aimeos\MW\Criteria\Iface Criteria object for filtering |
|
43
|
|
|
* @since 2017.03 |
|
44
|
|
|
*/ |
|
45
|
|
|
public function createFilter( $default = true ) |
|
46
|
|
|
{ |
|
47
|
|
|
return \Aimeos\MShop\Factory::createManager( $this->getContext(), 'catalog' )->createSearch( $default ); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Returns the list of categries that are in the path to the root node including the one specified by its ID. |
|
53
|
|
|
* |
|
54
|
|
|
* @param integer $id Category ID to start from, null for root node |
|
55
|
|
|
* @param string[] $domains Domain names of items that are associated with the categories and that should be fetched too |
|
56
|
|
|
* @return array Associative list of items implementing \Aimeos\MShop\Catalog\Item\Iface with their IDs as keys |
|
57
|
|
|
* @since 2017.03 |
|
58
|
|
|
*/ |
|
59
|
|
|
public function getPath( $id, array $domains = array( 'text', 'media' ) ) |
|
60
|
|
|
{ |
|
61
|
|
|
return \Aimeos\MShop\Factory::createManager( $this->getContext(), 'catalog' )->getPath( $id, $domains ); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Returns the hierarchical catalog tree starting from the given ID. |
|
67
|
|
|
* |
|
68
|
|
|
* @param integer|null $id Category ID to start from, null for root node |
|
69
|
|
|
* @param string[] $domains Domain names of items that are associated with the categories and that should be fetched too |
|
70
|
|
|
* @param integer $level Constant from \Aimeos\MW\Tree\Manager\Base for the depth of the returned tree, LEVEL_ONE for |
|
71
|
|
|
* specific node only, LEVEL_LIST for node and all direct child nodes, LEVEL_TREE for the whole tree |
|
72
|
|
|
* @param \Aimeos\MW\Criteria\Iface|null $search Optional criteria object with conditions |
|
73
|
|
|
* @return \Aimeos\MShop\Catalog\Item\Iface Catalog node, maybe with children depending on the level constant |
|
74
|
|
|
* @since 2017.03 |
|
75
|
|
|
*/ |
|
76
|
|
|
public function getTree( $id = null, array $domains = array( 'text', 'media' ), |
|
77
|
|
|
$level = \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE, \Aimeos\MW\Criteria\Iface $search = null ) |
|
78
|
|
|
{ |
|
79
|
|
|
return \Aimeos\MShop\Factory::createManager( $this->getContext(), 'catalog' )->getTree( $id, $domains, $level, $search ); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Returns the default catalog filter |
|
85
|
|
|
* |
|
86
|
|
|
* @param boolean True to add default criteria, e.g. status > 0 |
|
87
|
|
|
* @return \Aimeos\MW\Criteria\Iface Criteria object for filtering |
|
88
|
|
|
* @since 2015.08 |
|
89
|
|
|
* @deprecated Use createFilter() instead |
|
90
|
|
|
*/ |
|
91
|
|
|
public function createCatalogFilter( $default = true ) |
|
92
|
|
|
{ |
|
93
|
|
|
return $this->createFilter( $default ); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Returns the list of categries that are in the path to the root node including the one specified by its ID. |
|
99
|
|
|
* |
|
100
|
|
|
* @param integer $id Category ID to start from, null for root node |
|
101
|
|
|
* @param string[] $domains Domain names of items that are associated with the categories and that should be fetched too |
|
102
|
|
|
* @return array Associative list of items implementing \Aimeos\MShop\Catalog\Item\Iface with their IDs as keys |
|
103
|
|
|
* @since 2015.08 |
|
104
|
|
|
* @deprecated Use getPath() instead |
|
105
|
|
|
*/ |
|
106
|
|
|
public function getCatalogPath( $id, array $domains = array( 'text', 'media' ) ) |
|
107
|
|
|
{ |
|
108
|
|
|
return $this->getPath( $id, $domains ); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Returns the hierarchical catalog tree starting from the given ID. |
|
114
|
|
|
* |
|
115
|
|
|
* @param integer|null $id Category ID to start from, null for root node |
|
116
|
|
|
* @param string[] $domains Domain names of items that are associated with the categories and that should be fetched too |
|
117
|
|
|
* @param integer $level Constant from \Aimeos\MW\Tree\Manager\Base for the depth of the returned tree, LEVEL_ONE for |
|
118
|
|
|
* specific node only, LEVEL_LIST for node and all direct child nodes, LEVEL_TREE for the whole tree |
|
119
|
|
|
* @param \Aimeos\MW\Criteria\Iface|null $search Optional criteria object with conditions |
|
120
|
|
|
* @return \Aimeos\MShop\Catalog\Item\Iface Catalog node, maybe with children depending on the level constant |
|
121
|
|
|
* @since 2015.08 |
|
122
|
|
|
* @deprecated Use getTree() instead |
|
123
|
|
|
*/ |
|
124
|
|
|
public function getCatalogTree( $id = null, array $domains = array( 'text', 'media' ), |
|
125
|
|
|
$level = \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE, \Aimeos\MW\Criteria\Iface $search = null ) |
|
126
|
|
|
{ |
|
127
|
|
|
return $this->getTree( $id, $domains, $level, $search ); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* Returns the product item for the given ID if it's available |
|
133
|
|
|
* |
|
134
|
|
|
* @param array $ids List of product IDs |
|
135
|
|
|
* @param array $domains Domain names of items that are associated with the products and that should be fetched too |
|
136
|
|
|
* @return string[] List of product items implementing \Aimeos\MShop\Product\Item\Iface |
|
137
|
|
|
* @throws \Aimeos\Controller\Frontend\Catalog\Exception If product isn't available |
|
138
|
|
|
* @since 2015.08 |
|
139
|
|
|
* @deprecated Use getItems() method in index controller instead |
|
140
|
|
|
*/ |
|
141
|
|
|
public function getProductItems( array $ids, array $domains = array( 'media', 'price', 'text' ) ) |
|
142
|
|
|
{ |
|
143
|
|
|
$cntl = \Aimeos\Controller\Frontend\Factory::createController( $this->getContext(), 'product' ); |
|
144
|
|
|
return $cntl->getItems( $ids, $domains ); |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* Returns the aggregated count of products for the given key. |
|
150
|
|
|
* |
|
151
|
|
|
* @param \Aimeos\MW\Criteria\Iface $filter Critera object which contains the filter conditions |
|
152
|
|
|
* @param string $key Search key to aggregate for, e.g. "index.attribute.id" |
|
153
|
|
|
* @return array Associative list of key values as key and the product count for this key as value |
|
154
|
|
|
* @since 2015.08 |
|
155
|
|
|
* @deprecated Use method in index controller instead |
|
156
|
|
|
*/ |
|
157
|
|
|
public function aggregateIndex( \Aimeos\MW\Criteria\Iface $filter, $key ) |
|
158
|
|
|
{ |
|
159
|
|
|
$cntl = \Aimeos\Controller\Frontend\Factory::createController( $this->getContext(), 'product' ); |
|
160
|
|
|
return $cntl->aggregate( $filter, $key ); |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* Returns the default index filter. |
|
166
|
|
|
* |
|
167
|
|
|
* @param string|null $sort Sortation of the product list like "name", "code", "price" and "position", null for no sortation |
|
168
|
|
|
* @param string $direction Sort direction of the product list ("+", "-") |
|
169
|
|
|
* @param integer $start Position in the list of found products where to begin retrieving the items |
|
170
|
|
|
* @param integer $size Number of products that should be returned |
|
171
|
|
|
* @param string $listtype Type of the product list, e.g. default, promotion, etc. |
|
172
|
|
|
* @return \Aimeos\MW\Criteria\Iface Criteria object containing the conditions for searching |
|
173
|
|
|
* @since 2015.08 |
|
174
|
|
|
* @deprecated Use method in index controller instead |
|
175
|
|
|
*/ |
|
176
|
|
|
public function createIndexFilter( $sort = null, $direction = '+', $start = 0, $size = 100, $listtype = 'default' ) |
|
177
|
|
|
{ |
|
178
|
|
|
$cntl = \Aimeos\Controller\Frontend\Factory::createController( $this->getContext(), 'product' ); |
|
179
|
|
|
return $cntl->createFilter( $sort, $direction, $start, $size, $listtype ); |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* Returns the index filter for the given category ID. |
|
185
|
|
|
* |
|
186
|
|
|
* @param integer $catid ID of the category to get the product list from |
|
187
|
|
|
* @param string|null $sort Sortation of the product list like "name", "code", "price" and "position", null for no sortation |
|
188
|
|
|
* @param string $direction Sort direction of the product list ("+", "-") |
|
189
|
|
|
* @param integer $start Position in the list of found products where to begin retrieving the items |
|
190
|
|
|
* @param integer $size Number of products that should be returned |
|
191
|
|
|
* @param string $listtype Type of the product list, e.g. default, promotion, etc. |
|
192
|
|
|
* @return \Aimeos\MW\Criteria\Iface Criteria object containing the conditions for searching |
|
193
|
|
|
* @since 2015.08 |
|
194
|
|
|
* @deprecated Use createIndexFilter() and addIndexFilterCategory() instead |
|
195
|
|
|
*/ |
|
196
|
|
|
public function createIndexFilterCategory( $catid, $sort = null, $direction = '+', $start = 0, $size = 100, $listtype = 'default' ) |
|
197
|
|
|
{ |
|
198
|
|
|
$cntl = \Aimeos\Controller\Frontend\Factory::createController( $this->getContext(), 'product' ); |
|
199
|
|
|
|
|
200
|
|
|
$filter = $cntl->createFilter( $sort, $direction, $start, $size, $listtype ); |
|
201
|
|
|
$filter = $cntl->addFilterCategory( $filter, $catid, \Aimeos\MW\Tree\Manager\Base::LEVEL_ONE, $sort, $direction, $listtype ); |
|
202
|
|
|
|
|
203
|
|
|
return $filter; |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
|
|
207
|
|
|
/** |
|
208
|
|
|
* Returns the index filter for the given search string. |
|
209
|
|
|
* |
|
210
|
|
|
* @param string $input Search string entered by the user |
|
211
|
|
|
* @param string|null $sort Sortation of the product list like "name", "price" and "relevance", null for no sortation |
|
212
|
|
|
* @param string $direction Sort direction of the product list ("+", "-") |
|
213
|
|
|
* @param integer $start Position in the list of found products where to begin retrieving the items |
|
214
|
|
|
* @param integer $size Number of products that should be returned |
|
215
|
|
|
* @param string $listtype List type of the text associated to the product, usually "default" |
|
216
|
|
|
* @return \Aimeos\MW\Criteria\Iface Criteria object containing the conditions for searching |
|
217
|
|
|
* @since 2015.08 |
|
218
|
|
|
* @deprecated Use createIndexFilter() and addIndexFilterText() instead |
|
219
|
|
|
*/ |
|
220
|
|
|
public function createIndexFilterText( $input, $sort = null, $direction = '+', $start = 0, $size = 100, $listtype = 'default' ) |
|
221
|
|
|
{ |
|
222
|
|
|
$cntl = \Aimeos\Controller\Frontend\Factory::createController( $this->getContext(), 'product' ); |
|
223
|
|
|
|
|
224
|
|
|
$filter = $cntl->createFilter( $sort, $direction, $start, $size, $listtype ); |
|
225
|
|
|
$filter = $cntl->addFilterText( $filter, $input, $sort, $direction, $listtype ); |
|
226
|
|
|
|
|
227
|
|
|
return $filter; |
|
228
|
|
|
} |
|
229
|
|
|
|
|
230
|
|
|
|
|
231
|
|
|
/** |
|
232
|
|
|
* Returns the given search filter with the conditions attached for filtering by category. |
|
233
|
|
|
* |
|
234
|
|
|
* @param \Aimeos\MW\Criteria\Iface $search Criteria object used for product search |
|
235
|
|
|
* @param string $catid Selected category by the user |
|
236
|
|
|
* @return \Aimeos\MW\Criteria\Iface Criteria object containing the conditions for searching |
|
237
|
|
|
* @since 2015.08 |
|
238
|
|
|
* @deprecated Use method in index controller instead |
|
239
|
|
|
*/ |
|
240
|
|
|
public function addIndexFilterCategory( \Aimeos\MW\Criteria\Iface $search, $catid ) |
|
241
|
|
|
{ |
|
242
|
|
|
$cntl = \Aimeos\Controller\Frontend\Factory::createController( $this->getContext(), 'product' ); |
|
243
|
|
|
return $cntl->addFilterCategory( $search, $catid ); |
|
244
|
|
|
} |
|
245
|
|
|
|
|
246
|
|
|
|
|
247
|
|
|
/** |
|
248
|
|
|
* Returns the given search filter with the conditions attached for filtering by text. |
|
249
|
|
|
* |
|
250
|
|
|
* @param \Aimeos\MW\Criteria\Iface $search Criteria object used for product search |
|
251
|
|
|
* @param string $input Search string entered by the user |
|
252
|
|
|
* @param string $listtype List type of the text associated to the product, usually "default" |
|
253
|
|
|
* @return \Aimeos\MW\Criteria\Iface Criteria object containing the conditions for searching |
|
254
|
|
|
* @since 2015.08 |
|
255
|
|
|
* @deprecated Use method in index controller instead |
|
256
|
|
|
*/ |
|
257
|
|
|
public function addIndexFilterText( \Aimeos\MW\Criteria\Iface $search, $input, $listtype = 'default' ) |
|
258
|
|
|
{ |
|
259
|
|
|
$cntl = \Aimeos\Controller\Frontend\Factory::createController( $this->getContext(), 'product' ); |
|
260
|
|
|
return $cntl->addFilterText( $search, $input, $listtype ); |
|
261
|
|
|
} |
|
262
|
|
|
|
|
263
|
|
|
|
|
264
|
|
|
/** |
|
265
|
|
|
* Returns the products from the index filtered by the given criteria object. |
|
266
|
|
|
* |
|
267
|
|
|
* @param \Aimeos\MW\Criteria\Iface $filter Critera object which contains the filter conditions |
|
268
|
|
|
* @param string[] $domains Domain names of items that are associated with the products and that should be fetched too |
|
269
|
|
|
* @param integer &$total Parameter where the total number of found products will be stored in |
|
270
|
|
|
* @return array Ordered list of product items implementing \Aimeos\MShop\Product\Item\Iface |
|
271
|
|
|
* @since 2015.08 |
|
272
|
|
|
* @deprecated Use method in index controller instead |
|
273
|
|
|
*/ |
|
274
|
|
|
public function getIndexItems( \Aimeos\MW\Criteria\Iface $filter, array $domains = array( 'media', 'price', 'text' ), &$total = null ) |
|
275
|
|
|
{ |
|
276
|
|
|
$cntl = \Aimeos\Controller\Frontend\Factory::createController( $this->getContext(), 'product' ); |
|
277
|
|
|
return $cntl->searchItems( $filter, $domains, $total ); |
|
278
|
|
|
} |
|
279
|
|
|
|
|
280
|
|
|
|
|
281
|
|
|
/** |
|
282
|
|
|
* Returns text filter for the given search string. |
|
283
|
|
|
* |
|
284
|
|
|
* @param string $input Search string entered by the user |
|
285
|
|
|
* @param string|null $sort Sortation of the product list like "name" and "relevance", null for no sortation |
|
286
|
|
|
* @param string $direction Sort direction of the product list ("asc", "desc") |
|
287
|
|
|
* @param integer $start Position in the list of found products where to begin retrieving the items |
|
288
|
|
|
* @param integer $size Number of products that should be returned |
|
289
|
|
|
* @param string $listtype List type of the text associated to the product, usually "default" |
|
290
|
|
|
* @param string $type Type of the text like "name", "short", "long", etc. |
|
291
|
|
|
* @return \Aimeos\MW\Criteria\Iface Criteria object containing the conditions for searching |
|
292
|
|
|
* @deprecated Use createFilter() method in index controller instead |
|
293
|
|
|
*/ |
|
294
|
|
|
public function createTextFilter( $input, $sort = null, $direction = '+', $start = 0, $size = 25, $listtype = 'default', $type = 'name' ) |
|
295
|
|
|
{ |
|
296
|
|
|
$locale = $this->getContext()->getLocale(); |
|
297
|
|
|
$langid = $locale->getLanguageId(); |
|
298
|
|
|
|
|
299
|
|
|
$search = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'index/text' )->createSearch( true ); |
|
300
|
|
|
|
|
301
|
|
|
$expr = array( |
|
302
|
|
|
$search->compare( '>', $search->createFunction( 'index.text.relevance', array( $listtype, $langid, $input ) ), 0 ), |
|
303
|
|
|
$search->compare( '>', $search->createFunction( 'index.text.value', array( $listtype, $langid, $type, 'product' ) ), '' ), |
|
304
|
|
|
); |
|
305
|
|
|
|
|
306
|
|
|
$sortations = array(); |
|
307
|
|
|
|
|
308
|
|
|
switch( $sort ) |
|
309
|
|
|
{ |
|
310
|
|
|
case 'name': |
|
311
|
|
|
$cmpfunc = $search->createFunction( 'index.text.value', array( $listtype, $langid, 'name', 'product' ) ); |
|
312
|
|
|
$expr[] = $search->compare( '>=', $cmpfunc, '' ); |
|
313
|
|
|
|
|
314
|
|
|
$sortfunc = $search->createFunction( 'sort:index.text.value', array( $listtype, $langid, 'name' ) ); |
|
315
|
|
|
$sortations[] = $search->sort( $direction, $sortfunc ); |
|
316
|
|
|
break; |
|
317
|
|
|
|
|
318
|
|
|
case 'relevance': |
|
319
|
|
|
// we don't need to sort by 'sort:index.text.relevance' because it's a boolean match (relevance is either 0 or 1) |
|
320
|
|
|
} |
|
321
|
|
|
|
|
322
|
|
|
$search->setConditions( $search->combine( '&&', $expr ) ); |
|
323
|
|
|
$search->setSortations( $sortations ); |
|
324
|
|
|
$search->setSlice( $start, $size ); |
|
325
|
|
|
|
|
326
|
|
|
return $search; |
|
327
|
|
|
} |
|
328
|
|
|
|
|
329
|
|
|
|
|
330
|
|
|
/** |
|
331
|
|
|
* Returns an list of product text strings matched by the filter. |
|
332
|
|
|
* |
|
333
|
|
|
* @param \Aimeos\MW\Criteria\Iface $filter Critera object which contains the filter conditions |
|
334
|
|
|
* @return array Associative list of the product ID as key and the product text as value |
|
335
|
|
|
* @deprecated Use searchItems() method in index controller to retrieve product items instead |
|
336
|
|
|
*/ |
|
337
|
|
|
public function getTextList( \Aimeos\MW\Criteria\Iface $filter ) |
|
338
|
|
|
{ |
|
339
|
|
|
return \Aimeos\MShop\Factory::createManager( $this->getContext(), 'index/text' )->searchTexts( $filter ); |
|
340
|
|
|
} |
|
341
|
|
|
} |
|
342
|
|
|
|