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\Service\Decorator; |
12
|
|
|
|
13
|
|
|
use \Psr\Http\Message\ServerRequestInterface; |
14
|
|
|
use \Psr\Http\Message\ResponseInterface; |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Base for service frontend controller decorators |
19
|
|
|
* |
20
|
|
|
* @package Controller |
21
|
|
|
* @subpackage Frontend |
22
|
|
|
*/ |
23
|
|
|
abstract class Base |
24
|
|
|
extends \Aimeos\Controller\Frontend\Base |
25
|
|
|
implements \Aimeos\Controller\Frontend\Common\Decorator\Iface, \Aimeos\Controller\Frontend\Service\Iface |
26
|
|
|
{ |
27
|
|
|
private $controller; |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Initializes the controller decorator. |
32
|
|
|
* |
33
|
|
|
* @param \Aimeos\Controller\Frontend\Iface $controller Controller object |
34
|
|
|
* @param \Aimeos\MShop\Context\Item\Iface $context Context object with required objects |
35
|
|
|
*/ |
36
|
|
|
public function __construct( \Aimeos\Controller\Frontend\Iface $controller, \Aimeos\MShop\Context\Item\Iface $context ) |
37
|
|
|
{ |
38
|
|
|
$iface = '\Aimeos\Controller\Frontend\Service\Iface'; |
39
|
|
|
if( !( $controller instanceof $iface ) ) |
40
|
|
|
{ |
41
|
|
|
$msg = sprintf( 'Class "%1$s" does not implement interface "%2$s"', get_class( $controller ), $iface ); |
42
|
|
|
throw new \Aimeos\Controller\Frontend\Exception( $msg ); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
$this->controller = $controller; |
46
|
|
|
|
47
|
|
|
parent::__construct( $context ); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Passes unknown methods to wrapped objects. |
53
|
|
|
* |
54
|
|
|
* @param string $name Name of the method |
55
|
|
|
* @param array $param List of method parameter |
56
|
|
|
* @return mixed Returns the value of the called method |
57
|
|
|
* @throws \Aimeos\Controller\Frontend\Exception If method call failed |
58
|
|
|
*/ |
59
|
|
|
public function __call( $name, array $param ) |
60
|
|
|
{ |
61
|
|
|
return @call_user_func_array( array( $this->controller, $name ), $param ); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Returns a list of attributes that are invalid |
67
|
|
|
* |
68
|
|
|
* @param string $serviceId Unique service ID |
69
|
|
|
* @param string[] $attributes List of attribute codes as keys and strings entered by the customer as value |
70
|
|
|
* @return string[] List of attributes codes as keys and error messages as values for invalid or missing values |
71
|
|
|
*/ |
72
|
|
|
public function checkAttributes( $serviceId, array $attributes ) |
73
|
|
|
{ |
74
|
|
|
return $this->controller->checkAttributes( $serviceId, $attributes ); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Returns the service item for the given ID |
80
|
|
|
* |
81
|
|
|
* @param string $serviceId Unique service ID |
82
|
|
|
* @param array $ref List of domains for which the items referenced by the services should be fetched too |
83
|
|
|
* @return \Aimeos\MShop\Service\Provider\Iface Service provider object |
84
|
|
|
*/ |
85
|
|
|
public function getProvider( $serviceId, $ref = ['media', 'price', 'text'] ) |
86
|
|
|
{ |
87
|
|
|
return $this->controller->getProvider( $serviceId, $ref ); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Returns the service providers for the given type |
93
|
|
|
* |
94
|
|
|
* @param string|null $type Service type, e.g. "delivery" (shipping related), "payment" (payment related) or null for all |
95
|
|
|
* @param array $ref List of domains for which the items referenced by the services should be fetched too |
96
|
|
|
* @return \Aimeos\MShop\Service\Provider\Iface[] List of service IDs as keys and service provider objects as values |
97
|
|
|
*/ |
98
|
|
|
public function getProviders( $type = null, $ref = ['media', 'price', 'text'] ) |
99
|
|
|
{ |
100
|
|
|
return $this->controller->getProviders( $type, $ref ); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Processes the service for the given order, e.g. payment and delivery services |
106
|
|
|
* |
107
|
|
|
* @param \Aimeos\MShop\Order\Item\Iface $orderItem Order which should be processed |
108
|
|
|
* @param string $serviceId Unique service item ID |
109
|
|
|
* @param array $urls Associative list of keys and the corresponding URLs |
110
|
|
|
* (keys are <type>.url-self, <type>.url-success, <type>.url-update where type can be "delivery" or "payment") |
111
|
|
|
* @param array $params Request parameters and order service attributes |
112
|
|
|
* @return \Aimeos\MShop\Common\Item\Helper\Form\Iface|null Form object with URL, parameters, etc. |
113
|
|
|
* or null if no form data is required |
114
|
|
|
*/ |
115
|
|
|
public function process( \Aimeos\MShop\Order\Item\Iface $orderItem, $serviceId, array $urls, array $params ) |
116
|
|
|
{ |
117
|
|
|
return $this->controller->process( $orderItem, $serviceId, $urls, $params ); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Updates the payment or delivery status for the given request |
123
|
|
|
* |
124
|
|
|
* @param ServerRequestInterface $request Request object with parameters and request body |
125
|
|
|
* @param ResponseInterface &$response Response object that will contain HTTP status and response body |
126
|
|
|
* @param array $urls Associative list of keys and the corresponding URLs |
127
|
|
|
* (keys are <type>.url-self, <type>.url-success, <type>.url-update where type can be "delivery" or "payment") |
128
|
|
|
* @return \Aimeos\MShop\Order\Item\Iface $orderItem Order item that has been updated |
129
|
|
|
*/ |
130
|
|
|
public function updateSync( ServerRequestInterface $request, ResponseInterface &$response, array $urls ) |
131
|
|
|
{ |
132
|
|
|
return $this->controller->updateSync( $request, $response, $urls ); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* Returns the service items that are available for the service type and the content of the basket. |
138
|
|
|
* |
139
|
|
|
* @param string $type Service type, e.g. "delivery" (shipping related) or "payment" (payment related) |
140
|
|
|
* @param \Aimeos\MShop\Order\Item\Base\Iface $basket Basket of the user |
141
|
|
|
* @param array $ref List of domains for which the items referenced by the services should be fetched too |
142
|
|
|
* @return array List of service items implementing \Aimeos\MShop\Service\Item\Iface with referenced items |
143
|
|
|
* @deprecated Use getProviders() instead |
144
|
|
|
*/ |
145
|
|
|
public function getServices( $type, \Aimeos\MShop\Order\Item\Base\Iface $basket, |
146
|
|
|
$ref = array( 'media', 'price', 'text' ) ) |
147
|
|
|
{ |
148
|
|
|
return $this->controller->getServices( $type, $basket, $ref ); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* Returns the list of attribute definitions which must be used to render the input form where the customer can |
154
|
|
|
* enter or chose the required data necessary by the service provider. |
155
|
|
|
* |
156
|
|
|
* @param string $type Service type, e.g. "delivery" (shipping related) or "payment" (payment related) |
157
|
|
|
* @param string $serviceId Identifier of one of the service option returned by getService() |
158
|
|
|
* @param \Aimeos\MShop\Order\Item\Base\Iface $basket Basket object |
159
|
|
|
* @return array List of attribute definitions implementing \Aimeos\MW\Criteria\Attribute\Iface |
160
|
|
|
* @deprecated Use getProvider() instead |
161
|
|
|
*/ |
162
|
|
|
public function getServiceAttributes( $type, $serviceId, \Aimeos\MShop\Order\Item\Base\Iface $basket ) |
163
|
|
|
{ |
164
|
|
|
return $this->controller->getServiceAttributes( $type, $serviceId, $basket ); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* Returns the price of the service. |
170
|
|
|
* |
171
|
|
|
* @param string $type Service type, e.g. "delivery" (shipping related) or "payment" (payment related) |
172
|
|
|
* @param string $serviceId Identifier of one of the service option returned by getService() |
173
|
|
|
* @param \Aimeos\MShop\Order\Item\Base\Iface $basket Basket with products |
174
|
|
|
* @return \Aimeos\MShop\Price\Item\Iface Price item |
175
|
|
|
* @throws \Aimeos\Controller\Frontend\Service\Exception If no active service provider for this ID is available |
176
|
|
|
* @throws \Aimeos\MShop\Exception If service provider isn't available |
177
|
|
|
* @throws \Exception If an error occurs |
178
|
|
|
* @deprecated Use getProvider() instead |
179
|
|
|
*/ |
180
|
|
|
public function getServicePrice( $type, $serviceId, \Aimeos\MShop\Order\Item\Base\Iface $basket ) |
181
|
|
|
{ |
182
|
|
|
return $this->controller->getServicePrice( $type, $serviceId, $basket ); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* Returns a list of attributes that are invalid. |
188
|
|
|
* |
189
|
|
|
* @param string $type Service type, e.g. "delivery" (shipping related) or "payment" (payment related) |
190
|
|
|
* @param string $serviceId Identifier of the service option chosen by the customer |
191
|
|
|
* @param array $attributes List of key/value pairs with name of the attribute from attribute definition object as |
192
|
|
|
* key and the string entered by the customer as value |
193
|
|
|
* @return array List of key/value pairs of attributes keys and an error message for values that are invalid or |
194
|
|
|
* missing |
195
|
|
|
* @deprecated Use checkAttributes() instead |
196
|
|
|
*/ |
197
|
|
|
public function checkServiceAttributes( $type, $serviceId, array $attributes ) |
198
|
|
|
{ |
199
|
|
|
return $this->controller->checkServiceAttributes( $type, $serviceId, $attributes ); |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* Returns the frontend controller |
205
|
|
|
* |
206
|
|
|
* @return \Aimeos\Controller\Frontend\Service\Iface Frontend controller object |
207
|
|
|
*/ |
208
|
|
|
protected function getController() |
209
|
|
|
{ |
210
|
|
|
return $this->controller; |
211
|
|
|
} |
212
|
|
|
} |
213
|
|
|
|