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-2018 |
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
|
|
|
/** |
29
|
|
|
* Returns the service for the given code |
30
|
|
|
* |
31
|
|
|
* @param string $code Unique service code |
32
|
|
|
* @param string[] $domains Domain names of items that are associated with the service and that should be fetched too |
33
|
|
|
* @return \Aimeos\MShop\Service\Item\Iface Service item including the referenced domains items |
34
|
|
|
* @since 2019.04 |
35
|
|
|
*/ |
36
|
|
|
public function find( $code, $ref = ['media', 'price', 'text'] ) |
37
|
|
|
{ |
38
|
|
|
return \Aimeos\MShop::create( $this->getContext(), 'service' )->findItem( $code, $ref, null, null, true ); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Returns the service for the given ID |
44
|
|
|
* |
45
|
|
|
* @param string $id Unique service ID |
46
|
|
|
* @param string[] $domains Domain names of items that are associated with the services and that should be fetched too |
47
|
|
|
* @return \Aimeos\MShop\Service\Item\Iface Service item including the referenced domains items |
48
|
|
|
* @since 2019.04 |
49
|
|
|
*/ |
50
|
|
|
public function get( $id, $ref = ['media', 'price', 'text'] ) |
51
|
|
|
{ |
52
|
|
|
return \Aimeos\MShop::create( $this->getContext(), 'service' )->getItem( $id, $ref, true ); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Returns the service item for the given ID |
58
|
|
|
* |
59
|
|
|
* @param string $serviceId Unique service ID |
60
|
|
|
* @param string[] $ref List of domain names whose items should be fetched too |
61
|
|
|
* @return \Aimeos\MShop\Service\Provider\Iface Service provider object |
62
|
|
|
*/ |
63
|
|
|
public function getProvider( $serviceId, $ref = ['media', 'price', 'text'] ) |
64
|
|
|
{ |
65
|
|
|
$manager = \Aimeos\MShop::create( $this->getContext(), 'service' ); |
66
|
|
|
$item = $manager->getItem( $serviceId, $ref, true ); |
67
|
|
|
|
68
|
|
|
return $manager->getProvider( $item, $item->getType() ); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Returns the service providers of the given type |
74
|
|
|
* |
75
|
|
|
* @param string|null $type Service type, e.g. "delivery" (shipping related), "payment" (payment related) or null for all |
76
|
|
|
* @param string[] $ref List of domain names whose items should be fetched too |
77
|
|
|
* @return \Aimeos\MShop\Service\Provider\Iface[] List of service IDs as keys and service provider objects as values |
78
|
|
|
*/ |
79
|
|
|
public function getProviders( $type = null, $ref = ['media', 'price', 'text'] ) |
80
|
|
|
{ |
81
|
|
|
$list = []; |
82
|
|
|
$manager = \Aimeos\MShop::create( $this->getContext(), 'service' ); |
83
|
|
|
|
84
|
|
|
$search = $manager->createSearch( true ); |
85
|
|
|
$search->setSortations( [$search->sort( '+', 'service.position' )] ); |
86
|
|
|
|
87
|
|
|
if( $type != null ) |
88
|
|
|
{ |
89
|
|
|
$expr = array( |
90
|
|
|
$search->getConditions(), |
91
|
|
|
$search->compare( '==', 'service.type', $type ), |
92
|
|
|
); |
93
|
|
|
$search->setConditions( $search->combine( '&&', $expr ) ); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
foreach( $manager->searchItems( $search, $ref ) as $id => $item ) { |
97
|
|
|
$list[$id] = $manager->getProvider( $item, $item->getType() ); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
return $list; |
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\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
|
|
|
$manager = \Aimeos\MShop::create( $this->getContext(), 'service' ); |
118
|
|
|
$item = $manager->getItem( $serviceId, [], true ); |
119
|
|
|
|
120
|
|
|
$provider = $manager->getProvider( $item, $item->getType() ); |
121
|
|
|
$provider->injectGlobalConfigBE( $urls ); |
122
|
|
|
|
123
|
|
|
return $provider->process( $orderItem, $params ); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Updates the order status sent by payment gateway notifications |
129
|
|
|
* |
130
|
|
|
* @param ServerRequestInterface $request Request object |
131
|
|
|
* @param ResponseInterface $response Response object that will contain HTTP status and response body |
132
|
|
|
* @param string $code Unique code of the service used for the current order |
133
|
|
|
* @return \Psr\Http\Message\ResponseInterface Response object |
134
|
|
|
*/ |
135
|
|
|
public function updatePush( ServerRequestInterface $request, ResponseInterface $response, $code ) |
136
|
|
|
{ |
137
|
|
|
$manager = \Aimeos\MShop::create( $this->getContext(), 'service' ); |
138
|
|
|
$item = $manager->findItem( $code ); |
139
|
|
|
|
140
|
|
|
$provider = $manager->getProvider( $item, $item->getType() ); |
141
|
|
|
|
142
|
|
|
return $provider->updatePush( $request, $response ); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Updates the payment or delivery status for the given request |
148
|
|
|
* |
149
|
|
|
* @param ServerRequestInterface $request Request object with parameters and request body |
150
|
|
|
* @param string $code Unique code of the service used for the current order |
151
|
|
|
* @param string $orderid ID of the order whose payment status should be updated |
152
|
|
|
* @return \Aimeos\MShop\Order\Item\Iface $orderItem Order item that has been updated |
153
|
|
|
*/ |
154
|
|
|
public function updateSync( ServerRequestInterface $request, $code, $orderid ) |
155
|
|
|
{ |
156
|
|
|
$context = $this->getContext(); |
157
|
|
|
$orderManager = \Aimeos\MShop::create( $context, 'order' ); |
158
|
|
|
$serviceManager = \Aimeos\MShop::create( $context, 'service' ); |
159
|
|
|
|
160
|
|
|
$orderItem = $orderManager->getItem( $orderid ); |
161
|
|
|
$serviceItem = $serviceManager->findItem( $code ); |
162
|
|
|
|
163
|
|
|
$provider = $serviceManager->getProvider( $serviceItem, $serviceItem->getType() ); |
164
|
|
|
|
165
|
|
|
|
166
|
|
|
if( ( $orderItem = $provider->updateSync( $request, $orderItem ) ) !== null ) |
167
|
|
|
{ |
168
|
|
|
if( $orderItem->getPaymentStatus() === \Aimeos\MShop\Order\Item\Base::PAY_UNFINISHED |
169
|
|
|
&& $provider->isImplemented( \Aimeos\MShop\Service\Provider\Payment\Base::FEAT_QUERY ) |
170
|
|
|
) { |
171
|
|
|
$provider->query( $orderItem ); |
172
|
|
|
} |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
return $orderItem; |
176
|
|
|
} |
177
|
|
|
} |
178
|
|
|
|