1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2016 |
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 |
|
|
|
|
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
|
|
|
$iface = '\Aimeos\Controller\Frontend\Product\Iface'; |
36
|
|
|
if( !( $controller instanceof $iface ) ) |
37
|
|
|
{ |
38
|
|
|
$msg = sprintf( 'Class "%1$s" does not implement interface "%2$s"', get_class( $controller ), $iface ); |
39
|
|
|
throw new \Aimeos\Controller\Frontend\Exception( $msg ); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
$this->controller = $controller; |
43
|
|
|
|
44
|
|
|
parent::__construct( $context ); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Passes unknown methods to wrapped objects. |
50
|
|
|
* |
51
|
|
|
* @param string $name Name of the method |
52
|
|
|
* @param array $param List of method parameter |
53
|
|
|
* @return mixed Returns the value of the called method |
54
|
|
|
* @throws \Aimeos\Controller\Frontend\Exception If method call failed |
55
|
|
|
*/ |
56
|
|
|
public function __call( $name, array $param ) |
57
|
|
|
{ |
58
|
|
|
return @call_user_func_array( array( $this->controller, $name ), $param ); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Returns the given search filter with the conditions attached for filtering by attribute. |
64
|
|
|
* |
65
|
|
|
* @param \Aimeos\MW\Criteria\Iface $filter Criteria object used for product search |
66
|
|
|
* @param array $attrIds List of attribute IDs for faceted search |
67
|
|
|
* @param array $optIds List of OR-combined attribute IDs for faceted search |
68
|
|
|
* @param array $attrIds Associative list of OR-combined attribute IDs per attribute type for faceted search |
69
|
|
|
* @return \Aimeos\MW\Criteria\Iface Criteria object containing the conditions for searching |
70
|
|
|
* @since 2017.03 |
71
|
|
|
*/ |
72
|
|
|
public function addFilterAttribute( \Aimeos\MW\Criteria\Iface $filter, array $attrIds, array $optIds, array $oneIds ) |
73
|
|
|
{ |
74
|
|
|
return $this->controller->addFilterAttribute( $filter, $attrIds, $optIds, $oneIds ); |
|
|
|
|
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Returns the given search filter with the conditions attached for filtering by category. |
80
|
|
|
* |
81
|
|
|
* @param \Aimeos\MW\Criteria\Iface $filter Criteria object used for product search |
82
|
|
|
* @param string|array $catId Selected category by the user |
83
|
|
|
* @param integer $level Constant for current category only, categories of next level (LEVEL_LIST) or whole subtree (LEVEL_SUBTREE) |
84
|
|
|
* @param string|null $sort Sortation of the product list like "name", "code", "price" and "position", null for no sortation |
85
|
|
|
* @param string $direction Sort direction of the product list ("+", "-") |
86
|
|
|
* @param string $listtype List type of the product associated to the category, usually "default" |
87
|
|
|
* @return \Aimeos\MW\Criteria\Iface Criteria object containing the conditions for searching |
88
|
|
|
* @since 2017.03 |
89
|
|
|
*/ |
90
|
|
|
public function addFilterCategory( \Aimeos\MW\Criteria\Iface $filter, $catId, |
91
|
|
|
$level = \Aimeos\MW\Tree\Manager\Base::LEVEL_ONE, $sort = null, $direction = '+', $listtype = 'default' ) |
92
|
|
|
{ |
93
|
|
|
return $this->controller->addFilterCategory( $filter, $catId, $level, $sort, $direction, $listtype ); |
|
|
|
|
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Returns the given search filter with the conditions attached for filtering by text. |
99
|
|
|
* |
100
|
|
|
* @param \Aimeos\MW\Criteria\Iface $filter Criteria object used for product search |
101
|
|
|
* @param string $input Search string entered by the user |
102
|
|
|
* @param string|null $sort Sortation of the product list like "name", "code", "price" and "position", null for no sortation |
103
|
|
|
* @param string $direction Sort direction of the product list ("+", "-") |
104
|
|
|
* @param string $listtype List type of the text associated to the product, usually "default" |
105
|
|
|
* @return \Aimeos\MW\Criteria\Iface Criteria object containing the conditions for searching |
106
|
|
|
* @since 2017.03 |
107
|
|
|
*/ |
108
|
|
|
public function addFilterText( \Aimeos\MW\Criteria\Iface $filter, $input, $sort = null, $direction = '+', $listtype = 'default' ) |
109
|
|
|
{ |
110
|
|
|
return $this->controller->addFilterText( $filter, $input, $sort, $direction, $listtype ); |
|
|
|
|
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Returns the aggregated count of products from the product for the given key. |
116
|
|
|
* |
117
|
|
|
* @param \Aimeos\MW\Criteria\Iface $filter Critera object which contains the filter conditions |
118
|
|
|
* @param string $key Search key to aggregate for, e.g. "product.attribute.id" |
119
|
|
|
* @return array Associative list of key values as key and the product count for this key as value |
120
|
|
|
* @since 2015.08 |
121
|
|
|
*/ |
122
|
|
|
public function aggregate( \Aimeos\MW\Criteria\Iface $filter, $key ) |
123
|
|
|
{ |
124
|
|
|
return $this->controller->aggregate( $filter, $key ); |
|
|
|
|
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Returns the default product filter. |
130
|
|
|
* |
131
|
|
|
* @param string|null $sort Sortation of the product list like "name", "code", "price" and "position", null for no sortation |
132
|
|
|
* @param string $direction Sort direction of the product list ("+", "-") |
133
|
|
|
* @param integer $start Position in the list of found products where to begin retrieving the items |
134
|
|
|
* @param integer $size Number of products that should be returned |
135
|
|
|
* @param string $listtype Type of the product list, e.g. default, promotion, etc. |
136
|
|
|
* @return \Aimeos\MW\Criteria\Iface Criteria object containing the conditions for searching |
137
|
|
|
* @since 2015.08 |
138
|
|
|
*/ |
139
|
|
|
public function createFilter( $sort = null, $direction = '+', $start = 0, $size = 100, $listtype = 'default' ) |
140
|
|
|
{ |
141
|
|
|
return $this->controller->createFilter( $sort, $direction, $start, $size, $listtype ); |
|
|
|
|
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* Returns the product for the given product ID from the product |
147
|
|
|
* |
148
|
|
|
* @param string $productId Unique product ID |
149
|
|
|
* @param string[] $domains Domain names of items that are associated with the products and that should be fetched too |
150
|
|
|
* @return \Aimeos\MShop\Product\Item\Iface Product item including the referenced domains items |
151
|
|
|
* @since 2017.03 |
152
|
|
|
*/ |
153
|
|
|
public function getItem( $productId, array $domains = array( 'attribute', 'media', 'price', 'product', 'product/property', 'text' ) ) |
154
|
|
|
{ |
155
|
|
|
return $this->controller->getItem( $productId, $domains ); |
|
|
|
|
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* Returns the product for the given product ID from the product |
161
|
|
|
* |
162
|
|
|
* @param string[] $productIds List of unique product ID |
163
|
|
|
* @param string[] $domains Domain names of items that are associated with the products and that should be fetched too |
164
|
|
|
* @return \Aimeos\MShop\Product\Item\Iface[] Associative list of product IDs as keys and product items as values |
165
|
|
|
* @since 2017.03 |
166
|
|
|
*/ |
167
|
|
|
public function getItems( array $productIds, array $domains = array( 'media', 'price', 'text' ) ) |
168
|
|
|
{ |
169
|
|
|
return $this->controller->getItems( $productIds, $domains ); |
|
|
|
|
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* Returns the products from the product filtered by the given criteria object. |
175
|
|
|
* |
176
|
|
|
* @param \Aimeos\MW\Criteria\Iface $filter Critera object which contains the filter conditions |
177
|
|
|
* @param string[] $domains Domain names of items that are associated with the products and that should be fetched too |
178
|
|
|
* @param integer &$total Parameter where the total number of found products will be stored in |
179
|
|
|
* @return array Ordered list of product items implementing \Aimeos\MShop\Product\Item\Iface |
180
|
|
|
* @since 2015.08 |
181
|
|
|
*/ |
182
|
|
|
public function searchItems( \Aimeos\MW\Criteria\Iface $filter, array $domains = array( 'media', 'price', 'text' ), &$total = null ) |
183
|
|
|
{ |
184
|
|
|
return $this->controller->searchItems( $filter, $domains, $total ); |
|
|
|
|
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* Returns the frontend controller |
190
|
|
|
* |
191
|
|
|
* @return \Aimeos\Controller\Frontend\Product\Iface Frontend controller object |
192
|
|
|
*/ |
193
|
|
|
protected function getController() |
194
|
|
|
{ |
195
|
|
|
return $this->controller; |
196
|
|
|
} |
197
|
|
|
} |
198
|
|
|
|