1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2012 |
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2017 |
7
|
|
|
* @package Controller |
8
|
|
|
* @subpackage Frontend |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
namespace Aimeos\Controller\Frontend\Service; |
13
|
|
|
|
14
|
|
|
use \Psr\Http\Message\ServerRequestInterface; |
15
|
|
|
use \Psr\Http\Message\ResponseInterface; |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Default implementation of the service frontend controller. |
20
|
|
|
* |
21
|
|
|
* @package Controller |
22
|
|
|
* @subpackage Frontend |
23
|
|
|
*/ |
24
|
|
|
class Standard |
25
|
|
|
extends \Aimeos\Controller\Frontend\Base |
26
|
|
|
implements Iface, \Aimeos\Controller\Frontend\Common\Iface |
27
|
|
|
{ |
28
|
|
|
private $providers = []; |
|
|
|
|
29
|
|
|
|
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Returns a list of attributes that are invalid |
33
|
|
|
* |
34
|
|
|
* @param string $serviceId Unique service ID |
35
|
|
|
* @param string[] $attributes List of attribute codes as keys and strings entered by the customer as value |
36
|
|
|
* @return string[] List of attributes codes as keys and error messages as values for invalid or missing values |
37
|
|
|
*/ |
38
|
|
|
public function checkAttributes( $serviceId, array $attributes ) |
39
|
|
|
{ |
40
|
|
|
$manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'service' ); |
41
|
|
|
$provider = $manager->getProvider( $manager->getItem( $serviceId, [], true ) ); |
42
|
|
|
|
43
|
|
|
return array_filter( $provider->checkConfigFE( $attributes ) ); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Returns the service item for the given ID |
49
|
|
|
* |
50
|
|
|
* @param string $serviceId Unique service ID |
51
|
|
|
* @param string[] $ref List of domain names whose items should be fetched too |
52
|
|
|
* @return \Aimeos\MShop\Service\Provider\Iface Service provider object |
53
|
|
|
*/ |
54
|
|
|
public function getProvider( $serviceId, $ref = ['media', 'price', 'text'] ) |
55
|
|
|
{ |
56
|
|
|
$manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'service' ); |
57
|
|
|
return $manager->getProvider( $manager->getItem( $serviceId, $ref, true ) ); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Returns the service providers of the given type |
63
|
|
|
* |
64
|
|
|
* @param string|null $type Service type, e.g. "delivery" (shipping related), "payment" (payment related) or null for all |
65
|
|
|
* @param string[] $ref List of domain names whose items should be fetched too |
66
|
|
|
* @return \Aimeos\MShop\Service\Provider\Iface[] List of service IDs as keys and service provider objects as values |
67
|
|
|
*/ |
68
|
|
|
public function getProviders( $type = null, $ref = ['media', 'price', 'text'] ) |
69
|
|
|
{ |
70
|
|
|
$list = []; |
71
|
|
|
$manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'service' ); |
72
|
|
|
|
73
|
|
|
$search = $manager->createSearch( true ); |
74
|
|
|
$search->setSortations( array( $search->sort( '+', 'service.position' ) ) ); |
75
|
|
|
|
76
|
|
|
if( $type != null ) |
|
|
|
|
77
|
|
|
{ |
78
|
|
|
$expr = array( |
79
|
|
|
$search->getConditions(), |
80
|
|
|
$search->compare( '==', 'service.type.code', $type ), |
81
|
|
|
$search->compare( '==', 'service.type.domain', 'service' ), |
82
|
|
|
); |
83
|
|
|
$search->setConditions( $search->combine( '&&', $expr ) ); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
foreach( $manager->searchItems( $search, $ref ) as $id => $item ) { |
87
|
|
|
$list[$id] = $manager->getProvider( $item ); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
return $list; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Processes the service for the given order, e.g. payment and delivery services |
96
|
|
|
* |
97
|
|
|
* @param \Aimeos\MShop\Order\Item\Iface $orderItem Order which should be processed |
98
|
|
|
* @param string $serviceId Unique service item ID |
99
|
|
|
* @param array $urls Associative list of keys and the corresponding URLs |
100
|
|
|
* (keys are <type>.url-self, <type>.url-success, <type>.url-update where type can be "delivery" or "payment") |
101
|
|
|
* @param array $params Request parameters and order service attributes |
102
|
|
|
* @return \Aimeos\MShop\Common\Item\Helper\Form\Iface|null Form object with URL, parameters, etc. |
103
|
|
|
* or null if no form data is required |
104
|
|
|
*/ |
105
|
|
|
public function process( \Aimeos\MShop\Order\Item\Iface $orderItem, $serviceId, array $urls, array $params ) |
106
|
|
|
{ |
107
|
|
|
$manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'service' ); |
108
|
|
|
|
109
|
|
|
$provider = $manager->getProvider( $manager->getItem( $serviceId, [], true ) ); |
110
|
|
|
$provider->injectGlobalConfigBE( $urls ); |
111
|
|
|
|
112
|
|
|
return $provider->process( $orderItem, $params ); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Updates the order status sent by payment gateway notifications |
118
|
|
|
* |
119
|
|
|
* @param ServerRequestInterface $request Request object |
120
|
|
|
* @param ResponseInterface $response Response object that will contain HTTP status and response body |
121
|
|
|
* @param string $code Unique code of the service used for the current order |
122
|
|
|
* @return \Psr\Http\Message\ResponseInterface Response object |
123
|
|
|
*/ |
124
|
|
|
public function updatePush( ServerRequestInterface $request, ResponseInterface $response, $code ) |
125
|
|
|
{ |
126
|
|
|
$manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'service' ); |
127
|
|
|
$provider = $manager->getProvider( $manager->findItem( $code ) ); |
128
|
|
|
|
129
|
|
|
return $provider->updatePush( $request, $response ); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Updates the payment or delivery status for the given request |
135
|
|
|
* |
136
|
|
|
* @param ServerRequestInterface $request Request object with parameters and request body |
137
|
|
|
* @param ResponseInterface $response Response object that will contain HTTP status and response body |
138
|
|
|
* @param array $urls Associative list of keys and the corresponding URLs |
139
|
|
|
* (keys are <type>.url-self, <type>.url-success, <type>.url-update where type can be "delivery" or "payment") |
140
|
|
|
* @param string $code Unique code of the service used for the current order |
141
|
|
|
* @param string $orderid Unique ID of the order whose payment status should be updated |
142
|
|
|
* @return \Aimeos\MShop\Order\Item\Iface $orderItem Order item that has been updated |
143
|
|
|
*/ |
144
|
|
|
public function updateSync( ServerRequestInterface $request, ResponseInterface $response, array $urls, $code, $orderid ) |
145
|
|
|
{ |
146
|
|
|
$params = (array) $request->getAttributes() + (array) $request->getParsedBody() + (array) $request->getQueryParams(); |
147
|
|
|
$params['orderid'] = $orderid; |
148
|
|
|
|
149
|
|
|
$context = $this->getContext(); |
150
|
|
|
$manager = \Aimeos\MShop\Factory::createManager( $context, 'service' ); |
151
|
|
|
|
152
|
|
|
$provider = $manager->getProvider( $manager->findItem( $code ) ); |
153
|
|
|
$provider->injectGlobalConfigBE( $urls ); |
154
|
|
|
|
155
|
|
|
$body = (string) $request->getBody(); |
156
|
|
|
$output = null; |
157
|
|
|
$headers = []; |
158
|
|
|
|
159
|
|
|
if( ( $orderItem = $provider->updateSync( $params, $body, $output, $headers ) ) !== null ) |
160
|
|
|
{ |
161
|
|
|
if( $orderItem->getPaymentStatus() === \Aimeos\MShop\Order\Item\Base::PAY_UNFINISHED |
162
|
|
|
&& $provider->isImplemented( \Aimeos\MShop\Service\Provider\Payment\Base::FEAT_QUERY ) |
163
|
|
|
) { |
164
|
|
|
$provider->query( $orderItem ); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
// update stock, coupons, etc. |
168
|
|
|
\Aimeos\Controller\Frontend\Factory::createController( $context, 'order' )->update( $orderItem ); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
foreach( $headers as $name => $header ) { |
172
|
|
|
$response->withHeader( $name, $header ); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
$response->withBody( $response->createStreamFromString( $output ) ); |
176
|
|
|
|
177
|
|
|
return $orderItem; |
178
|
|
|
} |
179
|
|
|
} |
180
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.