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