|
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\Basket\Decorator; |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Base for basket frontend controller decorators |
|
16
|
|
|
* |
|
17
|
|
|
* @package Controller |
|
18
|
|
|
* @subpackage Frontend |
|
19
|
|
|
*/ |
|
20
|
|
|
abstract class Base |
|
21
|
|
|
extends \Aimeos\Controller\Frontend\Basket\Base |
|
22
|
|
|
implements \Aimeos\Controller\Frontend\Common\Decorator\Iface, \Aimeos\Controller\Frontend\Basket\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\Basket\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 values like comments to the basket |
|
58
|
|
|
* |
|
59
|
|
|
* @param array $values Order base values like comment |
|
60
|
|
|
* @return \Aimeos\Controller\Frontend\Basket\Iface Basket frontend object for fluent interface |
|
61
|
|
|
*/ |
|
62
|
|
|
public function add( array $values ) |
|
63
|
|
|
{ |
|
64
|
|
|
$this->controller->add( $values ); |
|
65
|
|
|
return $this; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Empties the basket and removing all products, addresses, services, etc. |
|
71
|
|
|
* |
|
72
|
|
|
* @return \Aimeos\Controller\Frontend\Basket\Iface Basket frontend object for fluent interface |
|
73
|
|
|
*/ |
|
74
|
|
|
public function clear() |
|
75
|
|
|
{ |
|
76
|
|
|
$this->controller->clear(); |
|
77
|
|
|
return $this; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Returns the basket object. |
|
83
|
|
|
* |
|
84
|
|
|
* @return \Aimeos\MShop\Order\Item\Base\Iface Basket holding products, addresses and delivery/payment options |
|
85
|
|
|
*/ |
|
86
|
|
|
public function get() |
|
87
|
|
|
{ |
|
88
|
|
|
return $this->controller->get(); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Explicitely persists the basket content |
|
94
|
|
|
* |
|
95
|
|
|
* @return \Aimeos\Controller\Frontend\Basket\Iface Basket frontend object for fluent interface |
|
96
|
|
|
*/ |
|
97
|
|
|
public function save() |
|
98
|
|
|
{ |
|
99
|
|
|
$this->controller->save(); |
|
100
|
|
|
return $this; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Sets the new basket type |
|
106
|
|
|
* |
|
107
|
|
|
* @param string $type Basket type |
|
108
|
|
|
* @return \Aimeos\Controller\Frontend\Basket\Iface Basket frontend object for fluent interface |
|
109
|
|
|
*/ |
|
110
|
|
|
public function setType( $type ) |
|
111
|
|
|
{ |
|
112
|
|
|
$this->controller->setType( $type ); |
|
113
|
|
|
return $this; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* Creates a new order base object from the current basket |
|
119
|
|
|
* |
|
120
|
|
|
* @return \Aimeos\MShop\Order\Item\Base\Iface Order base object including products, addresses and services |
|
121
|
|
|
*/ |
|
122
|
|
|
public function store() |
|
123
|
|
|
{ |
|
124
|
|
|
return $this->controller->store(); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* Returns the order base object for the given ID |
|
130
|
|
|
* |
|
131
|
|
|
* @param string $id Unique ID of the order base object |
|
132
|
|
|
* @param integer $parts Constants which parts of the order base object should be loaded |
|
133
|
|
|
* @param boolean $default True to add default criteria (user logged in), false if not |
|
134
|
|
|
* @return \Aimeos\MShop\Order\Item\Base\Iface Order base object including the given parts |
|
135
|
|
|
*/ |
|
136
|
|
|
public function load( $id, $parts = \Aimeos\MShop\Order\Item\Base\Base::PARTS_ALL, $default = true ) |
|
137
|
|
|
{ |
|
138
|
|
|
return $this->controller->load( $id, $parts, $default ); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* Adds a product to the basket of the customer stored in the session |
|
144
|
|
|
* |
|
145
|
|
|
* @param \Aimeos\MShop\Product\Item\Iface $product Product to add including texts, media, prices, attributes, etc. |
|
146
|
|
|
* @param integer $quantity Amount of products that should by added |
|
147
|
|
|
* @param array $variant List of variant-building attribute IDs that identify an article in a selection product |
|
148
|
|
|
* @param array $config List of configurable attribute IDs the customer has chosen from |
|
149
|
|
|
* @param array $custom Associative list of attribute IDs as keys and arbitrary values that will be added to the ordered product |
|
150
|
|
|
* @param string $stocktype Unique code of the stock type to deliver the products from |
|
151
|
|
|
* @param string|null $supplier Unique supplier code the product is from |
|
152
|
|
|
* @return \Aimeos\Controller\Frontend\Basket\Iface Basket frontend object for fluent interface |
|
153
|
|
|
* @throws \Aimeos\Controller\Frontend\Basket\Exception If the product isn't available |
|
154
|
|
|
*/ |
|
155
|
|
|
public function addProduct( \Aimeos\MShop\Product\Item\Iface $product, $quantity = 1, |
|
156
|
|
|
array $variant = [], array $config = [], array $custom = [], $stocktype = 'default', $supplier = null ) |
|
157
|
|
|
{ |
|
158
|
|
|
$this->controller->addProduct( $product, $quantity, $variant, $config, $custom, $stocktype, $supplier ); |
|
159
|
|
|
return $this; |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* Deletes a product item from the basket. |
|
165
|
|
|
* |
|
166
|
|
|
* @param integer $position Position number (key) of the order product item |
|
167
|
|
|
* @return \Aimeos\Controller\Frontend\Basket\Iface Basket frontend object for fluent interface |
|
168
|
|
|
*/ |
|
169
|
|
|
public function deleteProduct( $position ) |
|
170
|
|
|
{ |
|
171
|
|
|
$this->controller->deleteProduct( $position ); |
|
172
|
|
|
return $this; |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* Edits the quantity of a product item in the basket. |
|
178
|
|
|
* |
|
179
|
|
|
* @param integer $position Position number (key) of the order product item |
|
180
|
|
|
* @param integer $quantity New quantiy of the product item |
|
181
|
|
|
* @return \Aimeos\Controller\Frontend\Basket\Iface Basket frontend object for fluent interface |
|
182
|
|
|
*/ |
|
183
|
|
|
public function updateProduct( $position, $quantity ) |
|
184
|
|
|
{ |
|
185
|
|
|
$this->controller->updateProduct( $position, $quantity ); |
|
186
|
|
|
return $this; |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
|
|
190
|
|
|
/** |
|
191
|
|
|
* Adds the given coupon code and updates the basket. |
|
192
|
|
|
* |
|
193
|
|
|
* @param string $code Coupon code entered by the user |
|
194
|
|
|
* @return \Aimeos\Controller\Frontend\Basket\Iface Basket frontend object for fluent interface |
|
195
|
|
|
* @throws \Aimeos\Controller\Frontend\Basket\Exception if the coupon code is invalid or not allowed |
|
196
|
|
|
*/ |
|
197
|
|
|
public function addCoupon( $code ) |
|
198
|
|
|
{ |
|
199
|
|
|
$this->controller->addCoupon( $code ); |
|
200
|
|
|
return $this; |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
|
|
204
|
|
|
/** |
|
205
|
|
|
* Removes the given coupon code and its effects from the basket. |
|
206
|
|
|
* |
|
207
|
|
|
* @param string $code Coupon code entered by the user |
|
208
|
|
|
* @return \Aimeos\Controller\Frontend\Basket\Iface Basket frontend object for fluent interface |
|
209
|
|
|
* @throws \Aimeos\Controller\Frontend\Basket\Exception if the coupon code is invalid |
|
210
|
|
|
*/ |
|
211
|
|
|
public function deleteCoupon( $code ) |
|
212
|
|
|
{ |
|
213
|
|
|
$this->controller->deleteCoupon( $code ); |
|
214
|
|
|
return $this; |
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
|
|
|
|
218
|
|
|
/** |
|
219
|
|
|
* Adds an address of the customer to the basket |
|
220
|
|
|
* |
|
221
|
|
|
* @param string $type Address type code like 'payment' or 'delivery' |
|
222
|
|
|
* @param array $values Associative list of key/value pairs with address details |
|
223
|
|
|
* @return \Aimeos\Controller\Frontend\Basket\Iface Basket frontend object for fluent interface |
|
224
|
|
|
*/ |
|
225
|
|
|
public function addAddress( $type, array $values = [], $position = null ) |
|
226
|
|
|
{ |
|
227
|
|
|
$this->controller->addAddress( $type, $values, $position ); |
|
228
|
|
|
return $this; |
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
|
|
/** |
|
232
|
|
|
* Removes the address of the given type and position if available |
|
233
|
|
|
* |
|
234
|
|
|
* @param string $type Address type code like 'payment' or 'delivery' |
|
235
|
|
|
* @param integer|null $position Position of the address in the list to overwrite |
|
236
|
|
|
* @return \Aimeos\Controller\Frontend\Basket\Iface Basket frontend object for fluent interface |
|
237
|
|
|
*/ |
|
238
|
|
|
public function deleteAddress( $type, $position = null ) |
|
239
|
|
|
{ |
|
240
|
|
|
$this->controller->deleteAddress( $type, $position ); |
|
241
|
|
|
return $this; |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
|
|
245
|
|
|
/** |
|
246
|
|
|
* Adds the delivery/payment service including the given configuration |
|
247
|
|
|
* |
|
248
|
|
|
* @param \Aimeos\MShop\Service\Item\Iface $service Service item selected by the customer |
|
249
|
|
|
* @param array $config Associative list of key/value pairs with the options selected by the customer |
|
250
|
|
|
* @param integer|null $position Position of the address in the list to overwrite |
|
251
|
|
|
* @return \Aimeos\Controller\Frontend\Basket\Iface Basket frontend object for fluent interface |
|
252
|
|
|
* @throws \Aimeos\Controller\Frontend\Basket\Exception If given service attributes are invalid |
|
253
|
|
|
*/ |
|
254
|
|
|
public function addService( \Aimeos\MShop\Service\Item\Iface $service, array $config = [], $position = null ) |
|
255
|
|
|
{ |
|
256
|
|
|
$this->controller->addService( $service, $config, $position ); |
|
257
|
|
|
return $this; |
|
258
|
|
|
} |
|
259
|
|
|
|
|
260
|
|
|
|
|
261
|
|
|
/** |
|
262
|
|
|
* Removes the delivery or payment service items from the basket |
|
263
|
|
|
* |
|
264
|
|
|
* @param string $type Service type code like 'payment' or 'delivery' |
|
265
|
|
|
* @param integer|null $position Position of the address in the list to overwrite |
|
266
|
|
|
* @return \Aimeos\Controller\Frontend\Basket\Iface Basket frontend object for fluent interface |
|
267
|
|
|
*/ |
|
268
|
|
|
public function deleteService( $type, $position = null ) |
|
269
|
|
|
{ |
|
270
|
|
|
$this->controller->deleteService( $type, $position ); |
|
271
|
|
|
return $this; |
|
272
|
|
|
} |
|
273
|
|
|
|
|
274
|
|
|
|
|
275
|
|
|
/** |
|
276
|
|
|
* Returns the frontend controller |
|
277
|
|
|
* |
|
278
|
|
|
* @return \Aimeos\Controller\Frontend\Basket\Iface Frontend controller object |
|
279
|
|
|
*/ |
|
280
|
|
|
protected function getController() |
|
281
|
|
|
{ |
|
282
|
|
|
return $this->controller; |
|
283
|
|
|
} |
|
284
|
|
|
} |
|
285
|
|
|
|