|
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 extends \Aimeos\Controller\Frontend\Common\Decorator\Base |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* Passes unknown methods to wrapped objects. |
|
24
|
|
|
* |
|
25
|
|
|
* @param string $name Name of the method |
|
26
|
|
|
* @param array $param List of method parameter |
|
27
|
|
|
* @return mixed Returns the value of the called method |
|
28
|
|
|
* @throws \Aimeos\Controller\Frontend\Exception If method call failed |
|
29
|
|
|
*/ |
|
30
|
|
|
public function __call( $name, array $param ) |
|
31
|
|
|
{ |
|
32
|
|
|
if( ( $result = call_user_func_array( array( $this->getController(), $name ), $param ) ) === false ) |
|
33
|
|
|
{ |
|
34
|
|
|
$cntl = get_class( $this->getController() ); |
|
35
|
|
|
throw new \Aimeos\Controller\Frontend\Exception( sprintf( 'Unable to call method "%1$s::%2$s"', $cntl, $name ) ); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
return $result; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Empties the basket and removing all products, addresses, services, etc. |
|
44
|
|
|
* @return void |
|
45
|
|
|
*/ |
|
46
|
|
|
public function clear() |
|
47
|
|
|
{ |
|
48
|
|
|
$this->getController()->clear(); |
|
|
|
|
|
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Returns the basket object. |
|
54
|
|
|
* |
|
55
|
|
|
* @return \Aimeos\MShop\Order\Item\Base\Iface Basket holding products, addresses and delivery/payment options |
|
56
|
|
|
*/ |
|
57
|
|
|
public function get() |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->getController()->get(); |
|
|
|
|
|
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Adds a categorized product to the basket of the user stored in the session. |
|
65
|
|
|
* |
|
66
|
|
|
* @param string $prodid ID of the base product to add |
|
67
|
|
|
* @param integer $quantity Amount of products that should by added |
|
68
|
|
|
* @param array $options Possible options are: 'stock'=>true|false and 'variant'=>true|false |
|
69
|
|
|
* The 'stock'=>false option allows adding products without being in stock. |
|
70
|
|
|
* The 'variant'=>false option allows adding the selection product to the basket |
|
71
|
|
|
* instead of the specific sub-product if the variant-building attribute IDs |
|
72
|
|
|
* doesn't match a specific sub-product or if the attribute IDs are missing. |
|
73
|
|
|
* @param array $variantAttributeIds List of variant-building attribute IDs that identify a specific product |
|
74
|
|
|
* in a selection products |
|
75
|
|
|
* @param array $configAttributeIds List of attribute IDs that doesn't identify a specific product in a |
|
76
|
|
|
* selection of products but are stored together with the product (e.g. for configurable products) |
|
77
|
|
|
* @param array $hiddenAttributeIds List of attribute IDs that should be stored along with the product in the order |
|
78
|
|
|
* @param array $customAttributeValues Associative list of attribute IDs and arbitrary values that should be stored |
|
79
|
|
|
* along with the product in the order |
|
80
|
|
|
* @param string $warehouse Unique code of the warehouse to deliver the products from |
|
81
|
|
|
* @throws \Aimeos\Controller\Frontend\Basket\Exception If the product isn't available |
|
82
|
|
|
* @return void |
|
83
|
|
|
*/ |
|
84
|
|
|
public function addProduct( $prodid, $quantity = 1, array $options = array(), array $variantAttributeIds = array(), |
|
85
|
|
|
array $configAttributeIds = array(), array $hiddenAttributeIds = array(), array $customAttributeValues = array(), |
|
86
|
|
|
$warehouse = 'default' ) |
|
87
|
|
|
{ |
|
88
|
|
|
$this->getController()->addProduct( |
|
|
|
|
|
|
89
|
|
|
$prodid, $quantity, $options, $variantAttributeIds, $configAttributeIds, |
|
90
|
|
|
$hiddenAttributeIds, $customAttributeValues, $warehouse |
|
91
|
|
|
); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Deletes a product item from the basket. |
|
97
|
|
|
* |
|
98
|
|
|
* @param integer $position Position number (key) of the order product item |
|
99
|
|
|
* @return void |
|
100
|
|
|
*/ |
|
101
|
|
|
public function deleteProduct( $position ) |
|
102
|
|
|
{ |
|
103
|
|
|
$this->getController()->deleteProduct( $position ); |
|
|
|
|
|
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Edits the quantity of a product item in the basket. |
|
109
|
|
|
* |
|
110
|
|
|
* @param integer $position Position number (key) of the order product item |
|
111
|
|
|
* @param integer $quantity New quantiy of the product item |
|
112
|
|
|
* @param array $configAttributeCodes Codes of the product config attributes that should be REMOVED |
|
113
|
|
|
* @return void |
|
114
|
|
|
*/ |
|
115
|
|
|
public function editProduct( $position, $quantity, array $configAttributeCodes = array() ) |
|
116
|
|
|
{ |
|
117
|
|
|
$this->getController()->editProduct( $position, $quantity, $configAttributeCodes ); |
|
|
|
|
|
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* Adds the given coupon code and updates the basket. |
|
123
|
|
|
* |
|
124
|
|
|
* @param string $code Coupon code entered by the user |
|
125
|
|
|
* @throws \Aimeos\Controller\Frontend\Basket\Exception if the coupon code is invalid or not allowed |
|
126
|
|
|
* @return void |
|
127
|
|
|
*/ |
|
128
|
|
|
public function addCoupon( $code ) |
|
129
|
|
|
{ |
|
130
|
|
|
$this->getController()->addCoupon( $code ); |
|
|
|
|
|
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* Removes the given coupon code and its effects from the basket. |
|
136
|
|
|
* |
|
137
|
|
|
* @param string $code Coupon code entered by the user |
|
138
|
|
|
* @throws \Aimeos\Controller\Frontend\Basket\Exception if the coupon code is invalid |
|
139
|
|
|
* @return void |
|
140
|
|
|
*/ |
|
141
|
|
|
public function deleteCoupon( $code ) |
|
142
|
|
|
{ |
|
143
|
|
|
$this->getController()->deleteCoupon( $code ); |
|
|
|
|
|
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* Sets the address of the customer in the basket. |
|
149
|
|
|
* |
|
150
|
|
|
* @param string $type Address type constant from \Aimeos\MShop\Order\Item\Base\Address\Base |
|
151
|
|
|
* @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 |
|
152
|
|
|
* @throws \Aimeos\Controller\Frontend\Basket\Exception If the billing or delivery address is not of any required type of |
|
153
|
|
|
* if one of the keys is invalid when using an array with key/value pairs |
|
154
|
|
|
* @return void |
|
155
|
|
|
*/ |
|
156
|
|
|
public function setAddress( $type, $value ) |
|
157
|
|
|
{ |
|
158
|
|
|
$this->getController()->setAddress( $type, $value ); |
|
|
|
|
|
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* Sets the delivery/payment service item based on the service ID. |
|
164
|
|
|
* |
|
165
|
|
|
* @param string $type Service type code like 'payment' or 'delivery' |
|
166
|
|
|
* @param string $id Unique ID of the service item |
|
167
|
|
|
* @param array $attributes Associative list of key/value pairs containing the attributes selected or |
|
168
|
|
|
* entered by the customer when choosing one of the delivery or payment options |
|
169
|
|
|
* @throws \Aimeos\Controller\Frontend\Basket\Exception If there is no price to the service item attached |
|
170
|
|
|
* @return void |
|
171
|
|
|
*/ |
|
172
|
|
|
public function setService( $type, $id, array $attributes = array() ) |
|
173
|
|
|
{ |
|
174
|
|
|
$this->getController()->setService( $type, $id, $attributes ); |
|
|
|
|
|
|
175
|
|
|
} |
|
176
|
|
|
} |
|
177
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: