1
|
|
|
<?php namespace App\Http\Controllers\Frontend; |
2
|
|
|
|
3
|
|
|
use App\Http\Controllers\Controller; |
4
|
|
|
use Illuminate\Http\Request; |
5
|
|
|
use Hideyo\Ecommerce\Framework\Services\SendingMethod\SendingMethodFacade as SendingMethodService; |
6
|
|
|
use Hideyo\Ecommerce\Framework\Services\PaymentMethod\PaymentMethodFacade as PaymentMethodService; |
7
|
|
|
use Hideyo\Ecommerce\Framework\Services\Client\ClientFacade as ClientService; |
8
|
|
|
use Hideyo\Ecommerce\Framework\Services\Order\OrderFacade as OrderService; |
9
|
|
|
use Hideyo\Ecommerce\Framework\Services\Order\Events\OrderChangeStatus; |
10
|
|
|
use Cart; |
11
|
|
|
use Validator; |
12
|
|
|
use Notification; |
13
|
|
|
use BrowserDetect; |
|
|
|
|
14
|
|
|
use Mail; |
15
|
|
|
use Event; |
16
|
|
|
|
17
|
|
|
class CheckoutController extends Controller |
18
|
|
|
{ |
19
|
|
|
public function checkout() |
20
|
|
|
{ |
21
|
|
|
$sendingMethodsList = SendingMethodService::selectAllActiveByShopId(config()->get('app.shop_id')); |
22
|
|
|
|
23
|
|
|
if (!Cart::getContent()->count()) { |
24
|
|
|
return redirect()->to('cart'); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
$paymentMethodsList = Cart::getConditionsByType('sending_method')->first()->getAttributes()['data']['related_payment_methods_list']; |
28
|
|
|
|
29
|
|
|
if(!Cart::getConditionsByType('sending_method')->count()) { |
30
|
|
|
Notification::error('Selecteer een verzendwijze'); |
31
|
|
|
return redirect()->to('cart'); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
if(!Cart::getConditionsByType('payment_method')->count()) { |
35
|
|
|
Notification::error('Selecteer een betaalwijze'); |
36
|
|
|
return redirect()->to('cart'); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
if (auth('web')->guest()) { |
40
|
|
|
$noAccountUser = session()->get('noAccountUser'); |
41
|
|
|
if ($noAccountUser) { |
42
|
|
|
if (!isset($noAccountUser['delivery'])) { |
43
|
|
|
$noAccountUser['delivery'] = $noAccountUser; |
44
|
|
|
session()->put('noAccountUser', $noAccountUser); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
return view('frontend.checkout.no-account')->with(array( |
48
|
|
|
'noAccountUser' => $noAccountUser, |
49
|
|
|
'sendingMethodsList' => $sendingMethodsList, |
50
|
|
|
'paymentMethodsList' => $paymentMethodsList)); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
return view('frontend.checkout.login')->with(array( 'sendingMethodsList' => $sendingMethodsList, 'paymentMethodsList' => $paymentMethodsList)); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
$user = auth('web')->user(); |
57
|
|
|
|
58
|
|
|
if (!$user->clientDeliveryAddress()->count()) { |
|
|
|
|
59
|
|
|
ClientService::setBillOrDeliveryAddress(config()->get('app.shop_id'), $user->id, $user->clientBillAddress->id, 'delivery'); |
|
|
|
|
60
|
|
|
return redirect()->to('cart/checkout'); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
return view('frontend.checkout.index')->with(array( |
64
|
|
|
'user' => $user, |
65
|
|
|
'sendingMethodsList' => $sendingMethodsList, |
66
|
|
|
'paymentMethodsList' => $paymentMethodsList)); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function postCheckoutLogin(Request $request) |
70
|
|
|
{ |
71
|
|
|
$validateLogin = ClientService::validateLogin($request->all()); |
72
|
|
|
|
73
|
|
|
if ($validateLogin->fails()) { |
74
|
|
|
foreach ($validateLogin->errors()->all() as $error) { |
75
|
|
|
Notification::error($error); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
return redirect()->to('cart/checkout') |
79
|
|
|
->withErrors(true, 'login')->withInput(); |
|
|
|
|
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
$userdata = array( |
83
|
|
|
'email' => $request->get('email'), |
84
|
|
|
'password' => $request->get('password'), |
85
|
|
|
'confirmed' => 1, |
86
|
|
|
'active' => 1, |
87
|
|
|
'shop_id' => config()->get('app.shop_id') |
88
|
|
|
); |
89
|
|
|
|
90
|
|
|
if (auth('web')->attempt($userdata)) { |
91
|
|
|
return redirect()->to('cart/checkout'); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
Notification::error(trans('message.error.data-is-incorrect')); |
95
|
|
|
return redirect()->to('cart/checkout')->withErrors(true, 'login')->withInput(); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function postCheckoutRegister(Request $request) |
99
|
|
|
{ |
100
|
|
|
if (!Cart::getContent()->count()) { |
101
|
|
|
return redirect()->to('cart/checkout'); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
$noAccount = true; |
105
|
|
|
if ($request->get('password')) { |
106
|
|
|
$noAccount = false; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
$validateRegister = ClientService::validateRegister($request->all(), $noAccount); |
|
|
|
|
110
|
|
|
|
111
|
|
|
if($validateRegister->fails()) { |
112
|
|
|
foreach ($validator->errors()->all() as $error) { |
|
|
|
|
113
|
|
|
Notification::error($error); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
return redirect()->to('cart/checkout') |
117
|
|
|
->withErrors(true, 'register')->withInput();; |
|
|
|
|
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
if ($request->get('password')) { |
121
|
|
|
$registerAttempt = ClientService::validateRegister($request->all(), config()->get('app.shop_id')); |
122
|
|
|
|
123
|
|
|
if ($registerAttempt) { |
|
|
|
|
124
|
|
|
$register = ClientService::register($request->all(), config()->get('app.shop_id'), true); |
125
|
|
|
} else { |
126
|
|
|
$client = ClientService::findByEmail($request->get('email'), config()->get('app.shop_id')); |
127
|
|
|
|
128
|
|
|
if ($client->account_created) { |
129
|
|
|
Notification::error('Je hebt al een account. Login aan de linkerkant of vraag een nieuw wachtwoord aan.'); |
130
|
|
|
return redirect()->to('cart/checkout')->withInput()->withErrors('Dit emailadres is al in gebruik. Je kan links inloggen.', 'register'); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
$register = ClientService::createAccount($request->all(), config()->get('app.shop_id')); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
if ($register) { |
137
|
|
|
$data = $register; |
138
|
|
|
$data['shop'] = app('shop'); |
139
|
|
|
|
140
|
|
|
Mail::send('frontend.email.register-mail', array('password' => $request->get('password'), 'user' => $data->toArray(), 'billAddress' => $data->clientBillAddress->toArray()), function ($message) use ($data) { |
141
|
|
|
|
142
|
|
|
$message->to($data['email'])->from($data['shop']->email, $data['shop']->title)->subject('Je bent geregistreerd.'); |
143
|
|
|
}); |
144
|
|
|
|
145
|
|
|
$userdata = array( |
146
|
|
|
'email' => $request->get('email'), |
147
|
|
|
'password' => $request->get('password'), |
148
|
|
|
'confirmed' => 1, |
149
|
|
|
'active' => 1 |
150
|
|
|
); |
151
|
|
|
|
152
|
|
|
auth('web')->attempt($userdata); |
153
|
|
|
|
154
|
|
|
return redirect()->to('cart/checkout')->withErrors('Je bent geregistreerd. Er is een bevestigingsmail gestuurd.', 'login'); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
Notification::error('Je hebt al een account'); |
158
|
|
|
return redirect()->to('cart/checkout')->withErrors(true, 'register')->withInput(); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
$userdata = $request->all(); |
162
|
|
|
unset($userdata['password']); |
163
|
|
|
$registerAttempt = ClientService::validateRegisterNoAccount($userdata, config()->get('app.shop_id')); |
164
|
|
|
|
165
|
|
|
if ($registerAttempt) { |
166
|
|
|
$register = ClientService::register($userdata, config()->get('app.shop_id')); |
167
|
|
|
$userdata['client_id'] = $register->id; |
168
|
|
|
} else { |
169
|
|
|
$client = ClientService::findByEmail($userdata['email'], config()->get('app.shop_id')); |
170
|
|
|
if ($client) { |
171
|
|
|
$userdata['client_id'] = $client->id; |
172
|
|
|
} |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
session()->put('noAccountUser', $userdata); |
176
|
|
|
return redirect()->to('cart/checkout'); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
public function postComplete(Request $request) |
180
|
|
|
{ |
181
|
|
|
$noAccountUser = session()->get('noAccountUser'); |
182
|
|
|
if (auth('web')->guest() and !$noAccountUser) { |
183
|
|
|
return view('frontend.checkout.login'); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
if (!Cart::getContent()->count()) { |
187
|
|
|
return redirect()->to('cart/checkout'); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
$data = array( |
191
|
|
|
'products' => Cart::getContent()->toArray(), |
192
|
|
|
'price_with_tax' => Cart::getTotalWithTax(false), |
193
|
|
|
'price_without_tax' => Cart::getTotalWithoutTax(false), |
194
|
|
|
'comments' => $request->get('comments'), |
195
|
|
|
'browser_detect' => serialize(BrowserDetect::toArray()) |
196
|
|
|
); |
197
|
|
|
|
198
|
|
|
if (auth('web')->check()) { |
199
|
|
|
$data['user_id'] = auth('web')->user()->id; |
|
|
|
|
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
if ($noAccountUser){ |
203
|
|
|
$data['user_id'] = $noAccountUser['client_id']; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
if(Cart::getConditionsByType('sending_method')->count()) { |
207
|
|
|
$data['sending_method'] = Cart::getConditionsByType('sending_method'); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
if(Cart::getConditionsByType('sending_method_country_price')->count()) { |
211
|
|
|
$data['sending_method_country_price'] = Cart::getConditionsByType('sending_method_country_price'); |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
if(Cart::getConditionsByType('payment_method')->count()) { |
215
|
|
|
$data['payment_method'] = Cart::getConditionsByType('payment_method'); |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
$orderInsertAttempt = OrderService::createOrderFrontend($data, config()->get('app.shop_id'), $noAccountUser); |
219
|
|
|
|
220
|
|
|
if ($orderInsertAttempt AND $orderInsertAttempt->count()) { |
221
|
|
|
if ($orderInsertAttempt->OrderPaymentMethod and $orderInsertAttempt->OrderPaymentMethod->paymentMethod->order_confirmed_order_status_id) { |
222
|
|
|
$orderStatus = OrderService::updateStatus($orderInsertAttempt->id, $orderInsertAttempt->OrderPaymentMethod->paymentMethod->order_confirmed_order_status_id); |
223
|
|
|
if ($orderInsertAttempt->OrderPaymentMethod->paymentMethod->order_confirmed_order_status_id) { |
224
|
|
|
Event::dispatch(new OrderChangeStatus($orderStatus)); |
|
|
|
|
225
|
|
|
} |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
session()->put('orderData', $orderInsertAttempt); |
229
|
|
|
|
230
|
|
|
if ($orderInsertAttempt->OrderPaymentMethod and $orderInsertAttempt->OrderPaymentMethod->paymentMethod->payment_external) { |
231
|
|
|
return redirect()->to('cart/payment'); |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
app('cart')->clear(); |
235
|
|
|
app('cart')->clearCartConditions(); |
236
|
|
|
session()->flush('noAccountUser'); |
237
|
|
|
$body = ""; |
238
|
|
|
return view('frontend.checkout.complete')->with(array('body' => $body)); |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
return redirect()->to('cart/checkout'); |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
public function getEditAddress(Request $request, $type) { |
|
|
|
|
245
|
|
|
|
246
|
|
|
if (!Cart::getContent()->count()) { |
247
|
|
|
return redirect()->to('cart/checkout'); |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
if (auth('web')->guest()) { |
251
|
|
|
$noAccountUser = session()->get('noAccountUser'); |
252
|
|
|
if ($noAccountUser) { |
253
|
|
|
|
254
|
|
|
$address = $noAccountUser; |
255
|
|
|
if ($type == 'delivery') { |
256
|
|
|
$address = $noAccountUser['delivery']; |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
return view('frontend.checkout.edit-address-no-account')->with(array('type' => $type, 'noAccountUser' => $noAccountUser, 'clientAddress' => $address)); |
260
|
|
|
} |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
$user = auth('web')->user(); |
264
|
|
|
|
265
|
|
|
if ($type == 'delivery') { |
266
|
|
|
$address = $user->clientDeliveryAddress->toArray(); |
|
|
|
|
267
|
|
|
} else { |
268
|
|
|
$address = $user->clientBillAddress->toArray(); |
|
|
|
|
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
return view('frontend.checkout.edit-address')->with(array('type' => $type, 'user' => $user, 'clientAddress' => $address)); |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
public function postEditAddress(Request $request, $type) |
275
|
|
|
{ |
276
|
|
|
if (!Cart::getContent()->count()) { |
277
|
|
|
return redirect()->to('cart/checkout'); |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
$validate = ClientService::validateAddress($request->all()); |
281
|
|
|
|
282
|
|
|
if ($validate->fails()) { |
283
|
|
|
foreach ($validate->errors()->all() as $error) { |
284
|
|
|
Notification::error($error); |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
return redirect()->to('cart/edit-address/'.$type) |
288
|
|
|
->with(array('type' => $type))->withInput(); |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
if (auth('web')->guest()) { |
292
|
|
|
$noAccountUser = session()->get('noAccountUser'); |
293
|
|
|
if ($noAccountUser) { |
294
|
|
|
if ($type == 'bill') { |
295
|
|
|
$noAccountUser = array_merge($noAccountUser, $request->all()); |
296
|
|
|
} elseif ($type == 'delivery') { |
297
|
|
|
$noAccountUser['delivery'] = array_merge($noAccountUser['delivery'], $request->all()); |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
session()->put('noAccountUser', $noAccountUser); |
301
|
|
|
} |
302
|
|
|
} else { |
303
|
|
|
$user = auth('web')->user(); |
304
|
|
|
$id = $user->clientBillAddress->id; |
|
|
|
|
305
|
|
|
if ($type == 'delivery') { |
306
|
|
|
$id = $user->clientDeliveryAddress->id; |
|
|
|
|
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
if ($user->clientDeliveryAddress->id == $user->clientBillAddress->id) { |
310
|
|
|
$clientAddress = ClientService::createAddress($request->all(), $user->id); |
|
|
|
|
311
|
|
|
ClientService::setBillOrDeliveryAddress(config()->get('app.shop_id'), $user->id, $clientAddress->id, $type); |
312
|
|
|
} else { |
313
|
|
|
$clientAddress = ClientService::editAddress($user->id, $id, $request->all()); |
|
|
|
|
314
|
|
|
} |
315
|
|
|
} |
316
|
|
|
|
317
|
|
|
return redirect()->to('cart/checkout'); |
318
|
|
|
} |
319
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths