|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
HCSF - A multilingual CMS and Shopsystem |
|
5
|
|
|
Copyright (C) 2014 Marcus Haase - [email protected] |
|
6
|
|
|
|
|
7
|
|
|
This program is free software: you can redistribute it and/or modify |
|
8
|
|
|
it under the terms of the GNU General Public License as published by |
|
9
|
|
|
the Free Software Foundation, either version 3 of the License, or |
|
10
|
|
|
(at your option) any later version. |
|
11
|
|
|
|
|
12
|
|
|
This program is distributed in the hope that it will be useful, |
|
13
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15
|
|
|
GNU General Public License for more details. |
|
16
|
|
|
|
|
17
|
|
|
You should have received a copy of the GNU General Public License |
|
18
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace HaaseIT\HCSF\Controller\Shop; |
|
22
|
|
|
|
|
23
|
|
|
use HaaseIT\HCSF\HelperConfig; |
|
24
|
|
|
use HaaseIT\Toolbox\Tools; |
|
25
|
|
|
use HaaseIT\HCSF\Helper; |
|
26
|
|
|
use HaaseIT\HCSF\Customer\Helper as CHelper; |
|
27
|
|
|
use HaaseIT\HCSF\Shop\Helper as SHelper; |
|
28
|
|
|
use HaaseIT\Toolbox\DBTools; |
|
29
|
|
|
|
|
30
|
|
|
class Shoppingcart extends Base |
|
31
|
|
|
{ |
|
32
|
|
|
/** |
|
33
|
|
|
* @var \HaaseIT\Toolbox\Textcat |
|
34
|
|
|
*/ |
|
35
|
|
|
private $textcats; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Shoppingcart constructor. |
|
39
|
|
|
* @param \Zend\ServiceManager\ServiceManager $serviceManager |
|
40
|
|
|
*/ |
|
41
|
|
|
public function __construct(\Zend\ServiceManager\ServiceManager $serviceManager) |
|
42
|
|
|
{ |
|
43
|
|
|
parent::__construct($serviceManager); |
|
44
|
|
|
$this->textcats = $this->serviceManager->get('textcats'); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* |
|
49
|
|
|
*/ |
|
50
|
|
|
public function preparePage() |
|
|
|
|
|
|
51
|
|
|
{ |
|
52
|
|
|
$this->P = new \HaaseIT\HCSF\CorePage($this->serviceManager); |
|
53
|
|
|
$this->P->cb_pagetype = 'contentnosubnav'; |
|
54
|
|
|
|
|
55
|
|
|
if (HelperConfig::$shop['show_pricesonlytologgedin'] && !CHelper::getUserData()) { |
|
56
|
|
|
$this->P->oPayload->cl_html = $this->textcats->T('denied_notloggedin'); |
|
57
|
|
|
} else { |
|
58
|
|
|
$this->P->cb_customcontenttemplate = 'shop/shoppingcart'; |
|
59
|
|
|
|
|
60
|
|
|
// Check if there is a message to display above the shoppingcart |
|
61
|
|
|
$this->P->oPayload->cl_html = $this->getNotification(); |
|
62
|
|
|
|
|
63
|
|
|
// Display the shoppingcart |
|
64
|
|
|
if (isset($_SESSION['cart']) && count($_SESSION['cart']) >= 1) { |
|
65
|
|
|
$aErr = []; |
|
66
|
|
|
if (filter_input(INPUT_POST, 'doCheckout') === 'yes') { |
|
67
|
|
|
$aErr = $this->validateCheckout($aErr); |
|
68
|
|
|
if (count($aErr) === 0) { |
|
69
|
|
|
$this->doCheckout(); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
$aShoppingcart = SHelper::buildShoppingCartTable($_SESSION['cart'], false, '', $aErr); |
|
|
|
|
|
|
74
|
|
|
|
|
75
|
|
|
$this->P->cb_customdata = $aShoppingcart; |
|
76
|
|
|
} else { |
|
77
|
|
|
$this->P->oPayload->cl_html .= $this->textcats->T('shoppingcart_empty'); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @param array $aErr |
|
84
|
|
|
* @return array |
|
85
|
|
|
*/ |
|
86
|
|
|
private function validateCheckout($aErr = []) |
|
87
|
|
|
{ |
|
88
|
|
|
$aErr = CHelper::validateCustomerForm(HelperConfig::$lang, $aErr, true); |
|
89
|
|
View Code Duplication |
if (!CHelper::getUserData() && filter_input(INPUT_POST, 'tos') !== 'y') { |
|
|
|
|
|
|
90
|
|
|
$aErr['tos'] = true; |
|
91
|
|
|
} |
|
92
|
|
View Code Duplication |
if (!CHelper::getUserData() && filter_input(INPUT_POST, 'cancellationdisclaimer') !== 'y') { |
|
|
|
|
|
|
93
|
|
|
$aErr['cancellationdisclaimer'] = true; |
|
94
|
|
|
} |
|
95
|
|
|
$postpaymentmethod = filter_input(INPUT_POST, 'paymentmethod'); |
|
96
|
|
|
if ( |
|
97
|
|
|
$postpaymentmethod === null |
|
98
|
|
|
|| in_array($postpaymentmethod, HelperConfig::$shop['paymentmethods'], true) === false |
|
99
|
|
|
) { |
|
100
|
|
|
$aErr['paymentmethod'] = true; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
return $aErr; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* @param $aV |
|
108
|
|
|
* @return array |
|
109
|
|
|
*/ |
|
110
|
|
|
private function getItemImage($aV) |
|
111
|
|
|
{ |
|
112
|
|
|
// base64 encode img and prepare for db |
|
113
|
|
|
// image/png image/jpeg image/gif |
|
114
|
|
|
// data:{mimetype};base64,XXXX |
|
|
|
|
|
|
115
|
|
|
|
|
116
|
|
|
$aImagesToSend = []; |
|
117
|
|
|
$base64Img = false; |
|
118
|
|
|
$binImg = false; |
|
119
|
|
|
|
|
120
|
|
|
if (HelperConfig::$shop['email_orderconfirmation_embed_itemimages_method'] === 'glide') { |
|
121
|
|
|
$sPathToImage = '/'.HelperConfig::$core['directory_images'].'/'.HelperConfig::$shop['directory_images_items'].'/'; |
|
122
|
|
|
$sImageroot = PATH_BASEDIR . HelperConfig::$core['directory_glide_master']; |
|
123
|
|
|
|
|
124
|
|
|
if ( |
|
125
|
|
|
is_file($sImageroot.substr($sPathToImage.$aV['img'], strlen(HelperConfig::$core['directory_images']) + 1)) |
|
126
|
|
|
&& $aImgInfo = getimagesize($sImageroot.substr($sPathToImage.$aV['img'], strlen(HelperConfig::$core['directory_images']) + 1)) |
|
127
|
|
|
) { |
|
128
|
|
|
$glideserver = \League\Glide\ServerFactory::create([ |
|
129
|
|
|
'source' => $sImageroot, |
|
130
|
|
|
'cache' => PATH_GLIDECACHE, |
|
131
|
|
|
'max_image_size' => HelperConfig::$core['glide_max_imagesize'], |
|
132
|
|
|
]); |
|
133
|
|
|
$glideserver->setBaseUrl('/' . HelperConfig::$core['directory_images'] . '/'); |
|
134
|
|
|
$base64Img = $glideserver->getImageAsBase64($sPathToImage.$aV['img'], HelperConfig::$shop['email_orderconfirmation_embed_itemimages_glideparams']); |
|
135
|
|
|
$TMP = explode(',', $base64Img); |
|
136
|
|
|
$binImg = base64_decode($TMP[1]); |
|
137
|
|
|
unset($TMP); |
|
138
|
|
|
} |
|
139
|
|
|
} else { |
|
140
|
|
|
$sPathToImage = |
|
141
|
|
|
PATH_DOCROOT.HelperConfig::$core['directory_images'].'/' |
|
142
|
|
|
.HelperConfig::$shop['directory_images_items'].'/' |
|
143
|
|
|
.HelperConfig::$shop['directory_images_items_email'].'/'; |
|
144
|
|
|
if ($aImgInfo = getimagesize($sPathToImage.$aV['img'])) { |
|
145
|
|
|
$binImg = file_get_contents($sPathToImage.$aV['img']); |
|
146
|
|
|
$base64Img = 'data:' . $aImgInfo['mime'] . ';base64,'; |
|
147
|
|
|
$base64Img .= base64_encode($binImg); |
|
148
|
|
|
} |
|
149
|
|
|
} |
|
150
|
|
|
if (HelperConfig::$shop['email_orderconfirmation_embed_itemimages']) { |
|
151
|
|
|
$aImagesToSend['binimg'] = $binImg; |
|
152
|
|
|
} |
|
153
|
|
|
if ($base64Img) { |
|
|
|
|
|
|
154
|
|
|
$aImagesToSend['base64img'] = $base64Img; |
|
155
|
|
|
} |
|
156
|
|
|
return $aImagesToSend; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* @return array |
|
161
|
|
|
*/ |
|
162
|
|
|
private function prepareDataOrder() |
|
|
|
|
|
|
163
|
|
|
{ |
|
164
|
|
|
$cartpricesums = $_SESSION['cartpricesums']; |
|
165
|
|
|
return [ |
|
166
|
|
|
'o_custno' => filter_var(trim(Tools::getFormfield('custno')), FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW), |
|
167
|
|
|
'o_email' => filter_var(trim(Tools::getFormfield('email')), FILTER_SANITIZE_EMAIL), |
|
168
|
|
|
'o_corpname' => filter_var(trim(Tools::getFormfield('corpname')), FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW), |
|
169
|
|
|
'o_name' => filter_var(trim(Tools::getFormfield('name')), FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW), |
|
170
|
|
|
'o_street' => filter_var(trim(Tools::getFormfield('street')), FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW), |
|
171
|
|
|
'o_zip' => filter_var(trim(Tools::getFormfield('zip')), FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW), |
|
172
|
|
|
'o_town' => filter_var(trim(Tools::getFormfield('town')), FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW), |
|
173
|
|
|
'o_phone' => filter_var(trim(Tools::getFormfield('phone')), FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW), |
|
174
|
|
|
'o_cellphone' => filter_var(trim(Tools::getFormfield('cellphone')), FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW), |
|
175
|
|
|
'o_fax' => filter_var(trim(Tools::getFormfield('fax')), FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW), |
|
176
|
|
|
'o_country' => filter_var(trim(Tools::getFormfield('country')), FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW), |
|
177
|
|
|
'o_group' => trim(CHelper::getUserData('cust_group')), |
|
178
|
|
|
'o_remarks' => filter_var(trim(Tools::getFormfield('remarks')), FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW), |
|
179
|
|
|
'o_tos' => (filter_input(INPUT_POST, 'tos') === 'y' || CHelper::getUserData()) ? 'y' : 'n', |
|
180
|
|
|
'o_cancellationdisclaimer' => (filter_input(INPUT_POST, 'cancellationdisclaimer') === 'y' || CHelper::getUserData()) ? 'y' : 'n', |
|
181
|
|
|
'o_paymentmethod' => filter_var(trim(Tools::getFormfield('paymentmethod')), FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW), |
|
182
|
|
|
'o_sumvoll' => $cartpricesums['sumvoll'], |
|
183
|
|
|
'o_sumerm' => $cartpricesums['sumerm'], |
|
184
|
|
|
'o_sumnettoall' => $cartpricesums['sumnettoall'], |
|
185
|
|
|
'o_taxvoll' => $cartpricesums['taxvoll'], |
|
186
|
|
|
'o_taxerm' => $cartpricesums['taxerm'], |
|
187
|
|
|
'o_sumbruttoall' => $cartpricesums['sumbruttoall'], |
|
188
|
|
|
'o_mindermenge' => isset($cartpricesums['mindergebuehr']) ? $cartpricesums['mindergebuehr'] : '', |
|
189
|
|
|
'o_shippingcost' => SHelper::getShippingcost(), |
|
190
|
|
|
'o_orderdate' => date('Y-m-d'), |
|
191
|
|
|
'o_ordertimestamp' => time(), |
|
192
|
|
|
'o_authed' => CHelper::getUserData() ? 'y' : 'n', |
|
193
|
|
|
'o_sessiondata' => serialize($_SESSION), |
|
194
|
|
|
'o_postdata' => serialize($_POST), |
|
195
|
|
|
'o_remote_address' => filter_input(INPUT_SERVER, 'REMOTE_ADDR', FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW), |
|
196
|
|
|
'o_ordercompleted' => 'n', |
|
197
|
|
|
'o_paymentcompleted' => 'n', |
|
198
|
|
|
'o_srv_hostname' => filter_input(INPUT_SERVER, 'SERVER_NAME', FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW), |
|
199
|
|
|
'o_vatfull' => HelperConfig::$shop['vat']['full'], |
|
200
|
|
|
'o_vatreduced' => HelperConfig::$shop['vat']['reduced'], |
|
201
|
|
|
]; |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
/** |
|
205
|
|
|
* @param int $orderid |
|
206
|
|
|
* @param string $cartkey |
|
207
|
|
|
* @param array $values |
|
208
|
|
|
* @param string $image |
|
209
|
|
|
* @return array |
|
210
|
|
|
*/ |
|
211
|
|
|
private function buildOrderItemRow($orderid, $cartkey, array $values, $image) |
|
212
|
|
|
{ |
|
213
|
|
|
return [ |
|
214
|
|
|
'oi_o_id' => $orderid, |
|
215
|
|
|
'oi_cartkey' => $cartkey, |
|
216
|
|
|
'oi_amount' => $values['amount'], |
|
217
|
|
|
'oi_price_netto_list' => $values['price']['netto_list'], |
|
218
|
|
|
'oi_price_netto_use' => $values['price']['netto_use'], |
|
219
|
|
|
'oi_price_brutto_use' => $values['price']['brutto_use'], |
|
220
|
|
|
'oi_price_netto_sale' => isset($values['price']['netto_sale']) ? $values['price']['netto_sale'] : '', |
|
221
|
|
|
'oi_price_netto_rebated' => isset($values['price']['netto_rebated']) ? $values['price']['netto_rebated'] : '', |
|
222
|
|
|
'oi_vat' => HelperConfig::$shop['vat'][$values['vat']], |
|
223
|
|
|
'oi_rg' => $values['rg'], |
|
224
|
|
|
'oi_rg_rebate' => isset( |
|
225
|
|
|
HelperConfig::$shop['rebate_groups'][$values['rg']][trim(CHelper::getUserData('cust_group'))] |
|
226
|
|
|
) |
|
227
|
|
|
? HelperConfig::$shop['rebate_groups'][$values['rg']][trim(CHelper::getUserData('cust_group'))] |
|
228
|
|
|
: '', |
|
229
|
|
|
'oi_itemname' => $values['name'], |
|
230
|
|
|
'oi_img' => $image, |
|
231
|
|
|
]; |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
private function doCheckout() |
|
|
|
|
|
|
235
|
|
|
{ |
|
236
|
|
|
/** @var \Doctrine\DBAL\Connection $dbal */ |
|
237
|
|
|
$dbal = $this->serviceManager->get('dbal'); |
|
238
|
|
|
|
|
239
|
|
|
try { |
|
240
|
|
|
$dbal->beginTransaction(); |
|
241
|
|
|
|
|
242
|
|
|
$aDataOrder = $this->prepareDataOrder(); |
|
243
|
|
|
|
|
244
|
|
|
/** @var \Doctrine\DBAL\Query\QueryBuilder $querybuilder */ |
|
245
|
|
|
$querybuilder = $dbal->createQueryBuilder(); |
|
246
|
|
|
$querybuilder->insert('orders'); |
|
247
|
|
|
|
|
248
|
|
|
foreach ($aDataOrder as $colname => $col) { |
|
249
|
|
|
$querybuilder |
|
250
|
|
|
->setValue($colname, ':'.$colname) |
|
251
|
|
|
->setParameter(':'.$colname, $col); |
|
252
|
|
|
} |
|
253
|
|
|
|
|
254
|
|
|
$querybuilder->execute(); |
|
255
|
|
|
$iInsertID = $dbal->lastInsertId(); |
|
256
|
|
|
|
|
257
|
|
|
$aImagesToSend = []; |
|
258
|
|
|
foreach ($_SESSION['cart'] as $sK => $aV) { |
|
259
|
|
|
$aImagesToSend[$aV['img']] = $this->getItemImage($aV); |
|
260
|
|
|
$aDataOrderItem = $this->buildOrderItemRow($iInsertID, $sK, $aV, $aImagesToSend[$aV['img']]['base64img']); |
|
261
|
|
|
|
|
262
|
|
|
$querybuilder = $dbal->createQueryBuilder(); |
|
263
|
|
|
$querybuilder->insert('orders_items'); |
|
264
|
|
|
|
|
265
|
|
|
foreach ($aDataOrderItem as $colname => $col) { |
|
266
|
|
|
$querybuilder |
|
267
|
|
|
->setValue($colname, ':'.$colname) |
|
268
|
|
|
->setParameter(':'.$colname, $col); |
|
269
|
|
|
} |
|
270
|
|
|
|
|
271
|
|
|
$querybuilder->execute(); |
|
272
|
|
|
} |
|
273
|
|
|
$dbal->commit(); |
|
274
|
|
|
} catch (\Exception $e) { |
|
275
|
|
|
// If something raised an exception in our transaction block of statements, |
|
276
|
|
|
// roll back any work performed in the transaction |
|
277
|
|
|
print '<p>Unable to complete transaction!</p>'; |
|
278
|
|
|
error_log($e); |
|
279
|
|
|
$dbal->rollBack(); |
|
280
|
|
|
} |
|
281
|
|
|
$sMailbody_us = $this->buildOrderMailBody(false, $iInsertID); |
|
|
|
|
|
|
282
|
|
|
$sMailbody_they = $this->buildOrderMailBody(true, $iInsertID); |
|
283
|
|
|
|
|
284
|
|
|
// write to file |
|
285
|
|
|
$this->writeCheckoutToFile($sMailbody_us); |
|
286
|
|
|
|
|
287
|
|
|
// Send Mails |
|
288
|
|
|
$this->sendCheckoutMails($iInsertID, $sMailbody_us, $sMailbody_they, $aImagesToSend); |
|
|
|
|
|
|
289
|
|
|
|
|
290
|
|
|
unset($_SESSION['cart'], $_SESSION['cartpricesums'], $_SESSION['sondercart']); |
|
291
|
|
|
|
|
292
|
|
|
$postpaymentmethod = filter_input(INPUT_POST, 'paymentmethod'); |
|
293
|
|
|
if ( |
|
294
|
|
|
$postpaymentmethod !== null |
|
295
|
|
|
&& isset(HelperConfig::$shop['paypal_interactive']) |
|
296
|
|
|
&& $postpaymentmethod === 'paypal' |
|
297
|
|
|
&& in_array('paypal', HelperConfig::$shop['paymentmethods'], true) !== false |
|
298
|
|
|
&& HelperConfig::$shop['paypal_interactive'] |
|
299
|
|
|
) { |
|
300
|
|
|
$redirectto = '/_misc/paypal.html?id=' . $iInsertID; |
|
301
|
|
|
} elseif ( |
|
302
|
|
|
$postpaymentmethod !== null |
|
303
|
|
|
&& $postpaymentmethod === 'sofortueberweisung' |
|
304
|
|
|
&& in_array('sofortueberweisung', HelperConfig::$shop['paymentmethods'], true) !== false |
|
305
|
|
|
) { |
|
306
|
|
|
$redirectto = '/_misc/sofortueberweisung.html?id=' . $iInsertID; |
|
307
|
|
|
} else { |
|
308
|
|
|
$redirectto = '/_misc/checkedout.html?id=' . $iInsertID; |
|
309
|
|
|
} |
|
310
|
|
|
\HaaseIT\HCSF\Helper::redirectToPage($redirectto); |
|
311
|
|
|
} |
|
312
|
|
|
|
|
313
|
|
|
/** |
|
314
|
|
|
* @param int $iInsertID |
|
315
|
|
|
* @param string $sMailbody_us |
|
316
|
|
|
* @param string $sMailbody_they |
|
317
|
|
|
* @param array $aImagesToSend |
|
318
|
|
|
*/ |
|
319
|
|
|
private function sendCheckoutMails($iInsertID, $sMailbody_us, $sMailbody_they, $aImagesToSend) |
|
320
|
|
|
{ |
|
321
|
|
|
if ( |
|
322
|
|
|
isset(HelperConfig::$shop['email_orderconfirmation_attachment_cancellationform_' .HelperConfig::$lang]) |
|
323
|
|
|
&& file_exists( |
|
324
|
|
|
PATH_DOCROOT.HelperConfig::$core['directory_emailattachments'] |
|
325
|
|
|
.'/'.HelperConfig::$shop['email_orderconfirmation_attachment_cancellationform_' |
|
326
|
|
|
.HelperConfig::$lang] |
|
327
|
|
|
) |
|
328
|
|
|
) { |
|
329
|
|
|
$aFilesToSend[] = |
|
|
|
|
|
|
330
|
|
|
PATH_DOCROOT.HelperConfig::$core['directory_emailattachments'].'/' |
|
331
|
|
|
.HelperConfig::$shop['email_orderconfirmation_attachment_cancellationform_' .HelperConfig::$lang]; |
|
332
|
|
|
} else { |
|
333
|
|
|
$aFilesToSend = []; |
|
334
|
|
|
} |
|
335
|
|
|
|
|
336
|
|
|
Helper::mailWrapper( |
|
337
|
|
|
filter_input(INPUT_POST, 'email', FILTER_SANITIZE_EMAIL), |
|
338
|
|
|
$this->textcats->T('shoppingcart_mail_subject') . ' ' . $iInsertID, |
|
339
|
|
|
$sMailbody_they, |
|
340
|
|
|
$aImagesToSend, |
|
341
|
|
|
$aFilesToSend |
|
342
|
|
|
); |
|
343
|
|
|
Helper::mailWrapper( |
|
344
|
|
|
HelperConfig::$core['email_sender'], |
|
345
|
|
|
'Bestellung im Webshop Nr: ' . $iInsertID, |
|
346
|
|
|
$sMailbody_us, |
|
347
|
|
|
$aImagesToSend |
|
348
|
|
|
); |
|
349
|
|
|
} |
|
350
|
|
|
|
|
351
|
|
|
/** |
|
352
|
|
|
* @param string $sMailbody_us |
|
353
|
|
|
*/ |
|
354
|
|
|
private function writeCheckoutToFile($sMailbody_us) |
|
355
|
|
|
{ |
|
356
|
|
|
$fp = fopen(PATH_LOGS . 'shoplog_' . date('Y-m-d') . '.html', 'a'); |
|
357
|
|
|
// Write $somecontent to our opened file. |
|
358
|
|
|
fwrite($fp, $sMailbody_us . "\n\n-------------------------------------------------------------------------\n\n"); |
|
359
|
|
|
fclose($fp); |
|
360
|
|
|
} |
|
361
|
|
|
|
|
362
|
|
|
/** |
|
363
|
|
|
* @param string $field |
|
364
|
|
|
* @return string |
|
365
|
|
|
*/ |
|
366
|
|
|
private function getPostValue($field) |
|
367
|
|
|
{ |
|
368
|
|
|
$postvalue = filter_input(INPUT_POST, $field); |
|
369
|
|
|
return (!empty($postvalue) ? $postvalue : ''); |
|
370
|
|
|
} |
|
371
|
|
|
|
|
372
|
|
|
/** |
|
373
|
|
|
* @param bool $bCust |
|
374
|
|
|
* @param int $iId |
|
375
|
|
|
* @return mixed |
|
376
|
|
|
*/ |
|
377
|
|
|
private function buildOrderMailBody($bCust = true, $iId) |
|
|
|
|
|
|
378
|
|
|
{ |
|
379
|
|
|
$aM = [ |
|
380
|
|
|
'customdata' => SHelper::buildShoppingCartTable($_SESSION['cart'], true), |
|
381
|
|
|
'currency' => HelperConfig::$shop['waehrungssymbol'], |
|
382
|
|
|
]; |
|
383
|
|
|
if (isset(HelperConfig::$shop['custom_order_fields'])) { |
|
384
|
|
|
$aM['custom_order_fields'] = HelperConfig::$shop['custom_order_fields']; |
|
385
|
|
|
} |
|
386
|
|
|
|
|
387
|
|
|
$postcustno = trim(filter_input(INPUT_POST, 'custno', FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW)); |
|
388
|
|
|
$postcountry = trim(filter_input(INPUT_POST, 'country', FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW)); |
|
389
|
|
|
$postpaymentmethod = filter_input(INPUT_POST, 'paymentmethod', FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW); |
|
390
|
|
|
$serverservername = filter_input(INPUT_SERVER, 'SERVER_NAME', FILTER_SANITIZE_URL); |
|
391
|
|
|
$aData = [ |
|
392
|
|
|
'customerversion' => $bCust, |
|
393
|
|
|
//'shc_css' => file_get_contents(PATH_DOCROOT.'screen-shc.css'), |
|
|
|
|
|
|
394
|
|
|
'datetime' => date('d.m.Y - H:i'), |
|
395
|
|
|
'custno' => $postcustno !== null && strlen($postcustno) >= HelperConfig::$customer['minimum_length_custno'] ? $postcustno : '', |
|
396
|
|
|
'corpname' => $this->getPostValue('corpname'), |
|
397
|
|
|
'name' => $this->getPostValue('name'), |
|
398
|
|
|
'street' => $this->getPostValue('street'), |
|
399
|
|
|
'zip' => $this->getPostValue('zip'), |
|
400
|
|
|
'town' => $this->getPostValue('town'), |
|
401
|
|
|
'phone' => $this->getPostValue('phone'), |
|
402
|
|
|
'cellphone' => $this->getPostValue('cellphone'), |
|
403
|
|
|
'fax' => $this->getPostValue('fax'), |
|
404
|
|
|
'email' => $this->getPostValue('email'), |
|
405
|
|
|
'country' => !empty($postcountry) ? |
|
406
|
|
|
( |
|
407
|
|
|
isset( |
|
408
|
|
|
HelperConfig::$countries['countries_' .HelperConfig::$lang][$postcountry] |
|
409
|
|
|
) |
|
410
|
|
|
? HelperConfig::$countries['countries_' .HelperConfig::$lang][$postcountry] |
|
411
|
|
|
: $postcountry) |
|
412
|
|
|
: '', |
|
413
|
|
|
'remarks' => $this->getPostValue('remarks'), |
|
414
|
|
|
'tos' => $this->getPostValue('tos'), |
|
415
|
|
|
'cancellationdisclaimer' => $this->getPostValue('cancellationdisclaimer'), |
|
416
|
|
|
'paymentmethod' => $this->getPostValue('paymentmethod'), |
|
417
|
|
|
'shippingcost' => empty($_SESSION['shippingcost']) ? false : $_SESSION['shippingcost'], |
|
418
|
|
|
'paypallink' => $postpaymentmethod === 'paypal' ? $serverservername.'/_misc/paypal.html?id='.$iId : '', |
|
419
|
|
|
'sofortueberweisunglink' => $postpaymentmethod === 'sofortueberweisung' ? $serverservername.'/_misc/sofortueberweisung.html?id='.$iId : '', |
|
420
|
|
|
'SESSION' => !$bCust ? Tools::debug($_SESSION, '$_SESSION', true, true) : '', |
|
421
|
|
|
'POST' => !$bCust ? Tools::debug($_POST, '$_POST', true, true) : '', |
|
422
|
|
|
'orderid' => $iId, |
|
423
|
|
|
]; |
|
424
|
|
|
|
|
425
|
|
|
$aM['customdata']['mail'] = $aData; |
|
426
|
|
|
|
|
427
|
|
|
return $this->serviceManager->get('twig')->render('shop/mail-order-html.twig', $aM); |
|
428
|
|
|
} |
|
429
|
|
|
|
|
430
|
|
|
/** |
|
431
|
|
|
* @return string |
|
432
|
|
|
*/ |
|
433
|
|
|
private function getNotification() |
|
434
|
|
|
{ |
|
435
|
|
|
$return = ''; |
|
436
|
|
|
$getmsg = filter_input(INPUT_GET, 'msg'); |
|
437
|
|
|
$getcartkey = filter_input(INPUT_GET, 'cartkey', FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW); |
|
438
|
|
|
$getamount = filter_input(INPUT_GET, 'cartkey', FILTER_SANITIZE_NUMBER_INT); |
|
439
|
|
|
if (!empty($getmsg)) { |
|
440
|
|
|
if ( |
|
441
|
|
|
($getmsg === 'updated' && !empty($getcartkey) && !empty($getamount)) |
|
442
|
|
|
|| ($getmsg === 'removed' && !empty($getcartkey)) |
|
443
|
|
|
) { |
|
444
|
|
|
$return .= $this->textcats->T('shoppingcart_msg_' . $getmsg . '_1') . ' '; |
|
445
|
|
|
if (isset(HelperConfig::$shop['custom_order_fields']) && mb_strpos($getcartkey, '|') !== false) { |
|
446
|
|
|
$mCartkeys = explode('|', $getcartkey); |
|
447
|
|
|
foreach ($mCartkeys as $sKey => $sValue) { |
|
448
|
|
|
if ($sKey == 0) { |
|
449
|
|
|
$return .= $sValue . ', '; |
|
450
|
|
|
} else { |
|
451
|
|
|
$TMP = explode(':', $sValue); |
|
452
|
|
|
$return .= $this->textcats->T('shoppingcart_item_' . $TMP[0]) . ' ' . $TMP[1] . ', '; |
|
453
|
|
|
unset($TMP); |
|
454
|
|
|
} |
|
455
|
|
|
} |
|
456
|
|
|
$return = Tools::cutStringend($return, 2); |
|
457
|
|
|
} else { |
|
458
|
|
|
$return .= $getcartkey; |
|
459
|
|
|
} |
|
460
|
|
|
$return.= ' ' . $this->textcats->T('shoppingcart_msg_'.$getmsg.'_2'); |
|
461
|
|
|
if ($getmsg === 'updated') { |
|
462
|
|
|
$return .= ' '.$getamount; |
|
463
|
|
|
} |
|
464
|
|
|
$return .= '<br><br>'; |
|
465
|
|
|
} |
|
466
|
|
|
} |
|
467
|
|
|
|
|
468
|
|
|
return $return; |
|
469
|
|
|
} |
|
470
|
|
|
} |
|
471
|
|
|
|
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: