1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2017-2018 |
6
|
|
|
* @package Controller |
7
|
|
|
* @subpackage Frontend |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
namespace Aimeos\Controller\Frontend\Stock\Decorator; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Base for stock 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\Stock\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\Stock\Iface::class; |
38
|
|
|
$this->controller = \Aimeos\MW\Common\Base::checkClass( $iface, $controller ); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Passes unknown methods to wrapped objects. |
44
|
|
|
* |
45
|
|
|
* @param string $name Name of the method |
46
|
|
|
* @param array $param List of method parameter |
47
|
|
|
* @return mixed Returns the value of the called method |
48
|
|
|
* @throws \Aimeos\Controller\Frontend\Exception If method call failed |
49
|
|
|
*/ |
50
|
|
|
public function __call( $name, array $param ) |
51
|
|
|
{ |
52
|
|
|
return @call_user_func_array( array( $this->controller, $name ), $param ); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Adds the SKUs of the products for filtering |
58
|
|
|
* |
59
|
|
|
* @param array|string $codes Codes of the products |
60
|
|
|
* @return \Aimeos\Controller\Frontend\Stock\Iface Stock controller for fluent interface |
61
|
|
|
* @since 2019.04 |
62
|
|
|
*/ |
63
|
|
|
public function code( $codes ) |
64
|
|
|
{ |
65
|
|
|
$this->controller->code( $codes ); |
66
|
|
|
return $this; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Adds generic condition for filtering |
72
|
|
|
* |
73
|
|
|
* @param string $operator Comparison operator, e.g. "==", "!=", "<", "<=", ">=", ">", "=~", "~=" |
74
|
|
|
* @param string $key Search key defined by the stock manager, e.g. "stock.dateback" |
75
|
|
|
* @param array|string $value Value or list of values to compare to |
76
|
|
|
* @return \Aimeos\Controller\Frontend\Stock\Iface Stock controller for fluent interface |
77
|
|
|
* @since 2019.04 |
78
|
|
|
*/ |
79
|
|
|
public function compare( $operator, $key, $value ) |
80
|
|
|
{ |
81
|
|
|
$this->controller->compare( $operator, $key, $value ); |
82
|
|
|
return $this; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Returns the stock item for the given SKU and type |
88
|
|
|
* |
89
|
|
|
* @param string $code Unique stock code |
90
|
|
|
* @param string $type Type assigned to the stock item |
91
|
|
|
* @return \Aimeos\MShop\Stock\Item\Iface Stock item |
92
|
|
|
* @since 2019.04 |
93
|
|
|
*/ |
94
|
|
|
public function find( $code, $type ) |
95
|
|
|
{ |
96
|
|
|
return $this->controller->find( $code, $type ); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Returns the stock item for the given stock ID |
102
|
|
|
* |
103
|
|
|
* @param string $id Unique stock ID |
104
|
|
|
* @return \Aimeos\MShop\Stock\Item\Iface Stock item |
105
|
|
|
* @since 2019.04 |
106
|
|
|
*/ |
107
|
|
|
public function get( $id ) |
108
|
|
|
{ |
109
|
|
|
return $this->controller->get( $id ); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Parses the given array and adds the conditions to the list of conditions |
115
|
|
|
* |
116
|
|
|
* @param array $conditions List of conditions, e.g. ['>' => ['stock.dateback' => '2000-01-01 00:00:00']] |
117
|
|
|
* @return \Aimeos\Controller\Frontend\Stock\Iface Stock controller for fluent interface |
118
|
|
|
* @since 2019.04 |
119
|
|
|
*/ |
120
|
|
|
public function parse( array $conditions ) |
121
|
|
|
{ |
122
|
|
|
$this->controller->parse( $conditions ); |
123
|
|
|
return $this; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Returns the stock items filtered by the previously assigned conditions |
129
|
|
|
* |
130
|
|
|
* @param integer &$total Parameter where the total number of found stock items will be stored in |
131
|
|
|
* @return \Aimeos\MShop\Stock\Item\Iface[] Ordered list of stock items |
132
|
|
|
* @since 2019.04 |
133
|
|
|
*/ |
134
|
|
|
public function search( &$total = null ) |
135
|
|
|
{ |
136
|
|
|
return $this->controller->search( $total ); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Sets the start value and the number of returned stock items for slicing the list of found stock items |
142
|
|
|
* |
143
|
|
|
* @param integer $start Start value of the first stock item in the list |
144
|
|
|
* @param integer $limit Number of returned stock items |
145
|
|
|
* @return \Aimeos\Controller\Frontend\Stock\Iface Stock controller for fluent interface |
146
|
|
|
* @since 2019.04 |
147
|
|
|
*/ |
148
|
|
|
public function slice( $start, $limit ) |
149
|
|
|
{ |
150
|
|
|
$this->controller->slice( $start, $limit ); |
151
|
|
|
return $this; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* Sets the sorting of the result list |
157
|
|
|
* |
158
|
|
|
* @param string|null $key Sorting of the result list like "stock.type", null for no sorting |
159
|
|
|
* @return \Aimeos\Controller\Frontend\Stock\Iface Stock controller for fluent interface |
160
|
|
|
* @since 2019.04 |
161
|
|
|
*/ |
162
|
|
|
public function sort( $key = null ) |
163
|
|
|
{ |
164
|
|
|
$this->controller->sort( $key ); |
165
|
|
|
return $this; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* Adds stock types for filtering |
171
|
|
|
* |
172
|
|
|
* @param array|string $types Stock type codes |
173
|
|
|
* @return \Aimeos\Controller\Frontend\Stock\Iface Stock controller for fluent interface |
174
|
|
|
* @since 2019.04 |
175
|
|
|
*/ |
176
|
|
|
public function type( $types ) |
177
|
|
|
{ |
178
|
|
|
$this->controller->type( $types ); |
179
|
|
|
return $this; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* Injects the reference of the outmost object |
185
|
|
|
* |
186
|
|
|
* @param \Aimeos\Controller\Frontend\Iface $object Reference to the outmost controller or decorator |
187
|
|
|
* @return \Aimeos\Controller\Frontend\Iface Controller object for chaining method calls |
188
|
|
|
*/ |
189
|
|
|
public function setObject( \Aimeos\Controller\Frontend\Iface $object ) |
190
|
|
|
{ |
191
|
|
|
parent::setObject( $object ); |
192
|
|
|
|
193
|
|
|
$this->controller->setObject( $object ); |
194
|
|
|
|
195
|
|
|
return $this; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* Returns the frontend controller |
201
|
|
|
* |
202
|
|
|
* @return \Aimeos\Controller\Frontend\Stock\Iface Frontend controller object |
203
|
|
|
*/ |
204
|
|
|
protected function getController() |
205
|
|
|
{ |
206
|
|
|
return $this->controller; |
207
|
|
|
} |
208
|
|
|
} |
209
|
|
|
|