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\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 |
|
|
|
|
23
|
|
|
{ |
24
|
|
|
private $context; |
|
|
|
|
25
|
|
|
private $controller; |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Initializes the controller decorator. |
30
|
|
|
* |
31
|
|
|
* @param \Aimeos\Controller\Frontend\Iface $controller Controller object |
32
|
|
|
* @param \Aimeos\MShop\Context\Item\Iface $context Context object with required objects |
33
|
|
|
*/ |
34
|
|
|
public function __construct( \Aimeos\Controller\Frontend\Iface $controller, \Aimeos\MShop\Context\Item\Iface $context ) |
35
|
|
|
{ |
36
|
|
|
$this->context = $context; |
37
|
|
|
$this->controller = $controller; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Passes unknown methods to wrapped objects. |
43
|
|
|
* |
44
|
|
|
* @param string $name Name of the method |
45
|
|
|
* @param array $param List of method parameter |
46
|
|
|
* @return mixed Returns the value of the called method |
47
|
|
|
* @throws \Aimeos\Controller\Frontend\Exception If method call failed |
48
|
|
|
*/ |
49
|
|
|
public function __call( $name, array $param ) |
50
|
|
|
{ |
51
|
|
|
return call_user_func_array( array( $this->controller, $name ), $param ); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Empties the basket and removing all products, addresses, services, etc. |
57
|
|
|
* @return void |
58
|
|
|
*/ |
59
|
|
|
public function clear() |
60
|
|
|
{ |
61
|
|
|
$this->getController()->clear(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Returns the basket object. |
67
|
|
|
* |
68
|
|
|
* @return \Aimeos\MShop\Order\Item\Base\Iface Basket holding products, addresses and delivery/payment options |
69
|
|
|
*/ |
70
|
|
|
public function get() |
71
|
|
|
{ |
72
|
|
|
return $this->getController()->get(); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Explicitely persists the basket content |
78
|
|
|
*/ |
79
|
|
|
public function save() |
80
|
|
|
{ |
81
|
|
|
$this->getController()->save(); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Adds a categorized product to the basket of the user stored in the session. |
87
|
|
|
* |
88
|
|
|
* @param string $prodid ID of the base product to add |
89
|
|
|
* @param integer $quantity Amount of products that should by added |
90
|
|
|
* @param array $options Possible options are: 'stock'=>true|false and 'variant'=>true|false |
91
|
|
|
* The 'stock'=>false option allows adding products without being in stock. |
92
|
|
|
* The 'variant'=>false option allows adding the selection product to the basket |
93
|
|
|
* instead of the specific sub-product if the variant-building attribute IDs |
94
|
|
|
* doesn't match a specific sub-product or if the attribute IDs are missing. |
95
|
|
|
* @param array $variantAttributeIds List of variant-building attribute IDs that identify a specific product |
96
|
|
|
* in a selection products |
97
|
|
|
* @param array $configAttributeIds List of attribute IDs that doesn't identify a specific product in a |
98
|
|
|
* selection of products but are stored together with the product (e.g. for configurable products) |
99
|
|
|
* @param array $hiddenAttributeIds List of attribute IDs that should be stored along with the product in the order |
100
|
|
|
* @param array $customAttributeValues Associative list of attribute IDs and arbitrary values that should be stored |
101
|
|
|
* along with the product in the order |
102
|
|
|
* @param string $stocktype Unique code of the stock type to deliver the products from |
103
|
|
|
* @throws \Aimeos\Controller\Frontend\Basket\Exception If the product isn't available |
104
|
|
|
* @return void |
105
|
|
|
*/ |
106
|
|
|
public function addProduct( $prodid, $quantity = 1, array $options = array(), array $variantAttributeIds = array(), |
107
|
|
|
array $configAttributeIds = array(), array $hiddenAttributeIds = array(), array $customAttributeValues = array(), |
108
|
|
|
$stocktype = 'default' ) |
109
|
|
|
{ |
110
|
|
|
$this->getController()->addProduct( |
111
|
|
|
$prodid, $quantity, $options, $variantAttributeIds, $configAttributeIds, |
112
|
|
|
$hiddenAttributeIds, $customAttributeValues, $stocktype |
113
|
|
|
); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Deletes a product item from the basket. |
119
|
|
|
* |
120
|
|
|
* @param integer $position Position number (key) of the order product item |
121
|
|
|
* @return void |
122
|
|
|
*/ |
123
|
|
|
public function deleteProduct( $position ) |
124
|
|
|
{ |
125
|
|
|
$this->getController()->deleteProduct( $position ); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Edits the quantity of a product item in the basket. |
131
|
|
|
* |
132
|
|
|
* @param integer $position Position number (key) of the order product item |
133
|
|
|
* @param integer $quantity New quantiy of the product item |
134
|
|
|
* @param array $options Possible options are: 'stock'=>true|false |
135
|
|
|
* @param array $configAttributeCodes Codes of the product config attributes that should be REMOVED |
136
|
|
|
* @return void |
137
|
|
|
*/ |
138
|
|
|
public function editProduct( $position, $quantity, array $options = array(), array $configAttributeCodes = array() ) |
139
|
|
|
{ |
140
|
|
|
$this->getController()->editProduct( $position, $quantity, $options, $configAttributeCodes ); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Adds the given coupon code and updates the basket. |
146
|
|
|
* |
147
|
|
|
* @param string $code Coupon code entered by the user |
148
|
|
|
* @throws \Aimeos\Controller\Frontend\Basket\Exception if the coupon code is invalid or not allowed |
149
|
|
|
* @return void |
150
|
|
|
*/ |
151
|
|
|
public function addCoupon( $code ) |
152
|
|
|
{ |
153
|
|
|
$this->getController()->addCoupon( $code ); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Removes the given coupon code and its effects from the basket. |
159
|
|
|
* |
160
|
|
|
* @param string $code Coupon code entered by the user |
161
|
|
|
* @throws \Aimeos\Controller\Frontend\Basket\Exception if the coupon code is invalid |
162
|
|
|
* @return void |
163
|
|
|
*/ |
164
|
|
|
public function deleteCoupon( $code ) |
165
|
|
|
{ |
166
|
|
|
$this->getController()->deleteCoupon( $code ); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* Sets the address of the customer in the basket. |
172
|
|
|
* |
173
|
|
|
* @param string $type Address type constant from \Aimeos\MShop\Order\Item\Base\Address\Base |
174
|
|
|
* @param \Aimeos\MShop\Common\Item\Address\Iface|array|null $value Address object or array with key/value pairs of address or null to remove address from basket |
175
|
|
|
* @throws \Aimeos\Controller\Frontend\Basket\Exception If the billing or delivery address is not of any required type of |
176
|
|
|
* if one of the keys is invalid when using an array with key/value pairs |
177
|
|
|
* @return void |
178
|
|
|
*/ |
179
|
|
|
public function setAddress( $type, $value ) |
180
|
|
|
{ |
181
|
|
|
$this->getController()->setAddress( $type, $value ); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* Sets the delivery/payment service item based on the service ID. |
187
|
|
|
* |
188
|
|
|
* @param string $type Service type code like 'payment' or 'delivery' |
189
|
|
|
* @param string $id Unique ID of the service item |
190
|
|
|
* @param array $attributes Associative list of key/value pairs containing the attributes selected or |
191
|
|
|
* entered by the customer when choosing one of the delivery or payment options |
192
|
|
|
* @throws \Aimeos\Controller\Frontend\Basket\Exception If there is no price to the service item attached |
193
|
|
|
* @return void |
194
|
|
|
*/ |
195
|
|
|
public function setService( $type, $id, array $attributes = array() ) |
196
|
|
|
{ |
197
|
|
|
$this->getController()->setService( $type, $id, $attributes ); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* Returns the context item |
203
|
|
|
* |
204
|
|
|
* @return \Aimeos\MShop\Context\Item\Iface Context item object |
205
|
|
|
*/ |
206
|
|
|
protected function getContext() |
207
|
|
|
{ |
208
|
|
|
return $this->context; |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* Returns the frontend controller |
214
|
|
|
* |
215
|
|
|
* @return \Aimeos\Controller\Frontend\Common\Iface Frontend controller object |
216
|
|
|
*/ |
217
|
|
|
protected function getController() |
218
|
|
|
{ |
219
|
|
|
return $this->controller; |
220
|
|
|
} |
221
|
|
|
} |
222
|
|
|
|