|
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\Customer\Helper as CHelper; |
|
24
|
|
|
use HaaseIT\HCSF\HelperConfig; |
|
25
|
|
|
use HaaseIT\HCSF\Shop\Helper as SHelper; |
|
26
|
|
|
use Zend\ServiceManager\ServiceManager; |
|
27
|
|
|
|
|
28
|
|
|
class Myorders extends Base |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* @var \HaaseIT\Toolbox\Textcat |
|
32
|
|
|
*/ |
|
33
|
|
|
private $textcats; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var \PDO |
|
37
|
|
|
*/ |
|
38
|
|
|
private $db; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Myorders constructor. |
|
42
|
|
|
* @param ServiceManager $serviceManager |
|
43
|
|
|
*/ |
|
44
|
|
|
public function __construct(ServiceManager $serviceManager) |
|
45
|
|
|
{ |
|
46
|
|
|
parent::__construct($serviceManager); |
|
47
|
|
|
$this->textcats = $serviceManager->get('textcats'); |
|
48
|
|
|
$this->db = $serviceManager->get('db'); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function preparePage() |
|
|
|
|
|
|
52
|
|
|
{ |
|
53
|
|
|
$this->P = new \HaaseIT\HCSF\CorePage($this->serviceManager); |
|
54
|
|
|
$this->P->cb_pagetype = 'content'; |
|
55
|
|
|
|
|
56
|
|
|
if (!CHelper::getUserData()) { |
|
57
|
|
|
$this->P->oPayload->cl_html = $this->textcats->T("denied_notloggedin"); |
|
58
|
|
|
} else { |
|
59
|
|
|
require_once PATH_BASEDIR . 'src/shop/functions.shoppingcart.php'; |
|
60
|
|
|
|
|
61
|
|
|
$this->P->cb_customcontenttemplate = 'shop/myorders'; |
|
62
|
|
|
|
|
63
|
|
|
if (isset($_GET["action"], $_GET["id"]) && $_GET["action"] === 'show') { |
|
64
|
|
|
$iId = \filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT); |
|
65
|
|
|
|
|
66
|
|
|
$sql = "SELECT * FROM " . 'orders WHERE o_id = :id AND o_custno = \'' . $_SESSION['user']['cust_no'] . '\' AND o_ordercompleted != \'d\''; |
|
67
|
|
|
$hResult = $this->db->prepare($sql); |
|
68
|
|
|
$hResult->bindValue(':id', $iId); |
|
69
|
|
|
$hResult->execute(); |
|
70
|
|
|
|
|
71
|
|
|
if ($hResult->rowCount() == 1) { |
|
72
|
|
|
$aOrder = $hResult->fetch(); |
|
73
|
|
|
|
|
74
|
|
|
$this->P->cb_customdata['orderdata']['ordertimestamp'] = date( |
|
75
|
|
|
HelperConfig::$core["locale_format_date_time"], |
|
76
|
|
|
$aOrder["o_ordertimestamp"] |
|
77
|
|
|
); |
|
78
|
|
|
$this->P->cb_customdata['orderdata']['orderremarks'] = $aOrder["o_remarks"]; |
|
79
|
|
|
$this->P->cb_customdata['orderdata']['paymentmethod'] = $this->textcats->T("order_paymentmethod_" . $aOrder["o_paymentmethod"]); |
|
80
|
|
|
$this->P->cb_customdata['orderdata']['paymentcompleted'] = (($aOrder["o_paymentcompleted"] == 'y') ? $this->textcats->T("myorders_paymentstatus_completed") : $this->textcats->T("myorders_paymentstatus_open")); |
|
81
|
|
|
$this->P->cb_customdata['orderdata']['orderstatus'] = SHelper::showOrderStatusText($this->textcats, $aOrder["o_ordercompleted"]); |
|
82
|
|
|
$this->P->cb_customdata['orderdata']['shippingservice'] = $aOrder["o_shipping_service"]; |
|
83
|
|
|
$this->P->cb_customdata['orderdata']['trackingno'] = $aOrder["o_shipping_trackingno"]; |
|
84
|
|
|
|
|
85
|
|
|
$sql = 'SELECT * FROM orders_items WHERE oi_o_id = :id'; |
|
86
|
|
|
$hResult = $this->db->prepare($sql); |
|
87
|
|
|
$hResult->bindValue(':id', $iId); |
|
88
|
|
|
$hResult->execute(); |
|
89
|
|
|
|
|
90
|
|
|
$aItems = $hResult->fetchAll(); |
|
91
|
|
|
|
|
92
|
|
|
$aItemsforShoppingcarttable = []; |
|
93
|
|
|
foreach ($aItems as $aValue) { |
|
94
|
|
|
$aPrice = [ |
|
95
|
|
|
'netto_use' => $aValue["oi_price_netto_use"], |
|
96
|
|
|
'brutto_use' => $aValue["oi_price_brutto_use"], |
|
97
|
|
|
]; |
|
98
|
|
|
$aItemsforShoppingcarttable[$aValue["oi_cartkey"]] = [ |
|
99
|
|
|
'amount' => $aValue["oi_amount"], |
|
100
|
|
|
'price' => $aPrice, |
|
101
|
|
|
'vat' => $aValue["oi_vat"], |
|
102
|
|
|
//'rg' => $aValue["oi_rg"], |
|
|
|
|
|
|
103
|
|
|
'name' => $aValue["oi_itemname"], |
|
104
|
|
|
'img' => $aValue["oi_img"], |
|
105
|
|
|
]; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
$aShoppingcart = SHelper::buildShoppingCartTable( |
|
109
|
|
|
$aItemsforShoppingcarttable, |
|
110
|
|
|
true, |
|
111
|
|
|
'', |
|
112
|
|
|
'', |
|
113
|
|
|
$aOrder["o_vatfull"], |
|
114
|
|
|
$aOrder["o_vatreduced"] |
|
115
|
|
|
); |
|
116
|
|
|
} else { |
|
117
|
|
|
$this->P->cb_customdata['ordernotfound'] = true; |
|
118
|
|
|
} |
|
119
|
|
|
} else { |
|
120
|
|
|
$COList = [ |
|
121
|
|
|
['title' => $this->textcats->T("order_head_orderdate"), 'key' => 'o_ordertime', 'width' => 110, 'linked' => false,], |
|
122
|
|
|
['title' => $this->textcats->T("order_head_paymenthethod"), 'key' => 'o_paymentmethod', 'width' => 125, 'linked' => false,], |
|
123
|
|
|
['title' => $this->textcats->T("order_head_paid"), 'key' => 'o_paymentcompleted', 'width' => 60, 'linked' => false,], |
|
124
|
|
|
['title' => $this->textcats->T("order_head_status"), 'key' => 'o_order_status', 'width' => 80, 'linked' => false,], |
|
125
|
|
|
['title' => $this->textcats->T("order_head_shipping_service"), 'key' => 'o_shipping_service', 'width' => 90, 'linked' => false,], |
|
126
|
|
|
['title' => $this->textcats->T("order_head_shipping_trackingno"), 'key' => 'o_shipping_trackingno', 'width' => 130, 'linked' => false,], |
|
127
|
|
|
[ |
|
128
|
|
|
'title' => $this->textcats->T("order_show"), |
|
129
|
|
|
'key' => 'o_id', |
|
130
|
|
|
'width' => 120, |
|
131
|
|
|
'linked' => true, |
|
132
|
|
|
'ltarget' => '/_misc/myorders.html', |
|
133
|
|
|
'lkeyname' => 'id', |
|
134
|
|
|
'lgetvars' => ['action' => 'show',], |
|
135
|
|
|
], |
|
136
|
|
|
]; |
|
137
|
|
|
|
|
138
|
|
|
$this->P->cb_customdata['listmyorders'] = $this->showMyOrders($COList); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
if (isset($aShoppingcart)) { |
|
142
|
|
|
$this->P->cb_customdata['shoppingcart'] = $aShoppingcart['shoppingcart']; |
|
143
|
|
|
} |
|
144
|
|
|
} |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
private function showMyOrders($COList) |
|
148
|
|
|
{ |
|
149
|
|
|
$return = ''; |
|
150
|
|
|
$sql = 'SELECT * FROM orders WHERE o_custno = :custno ORDER BY o_ordertimestamp DESC'; |
|
151
|
|
|
|
|
152
|
|
|
$hResult = $this->db->prepare($sql); |
|
153
|
|
|
$hResult->bindValue(':custno', CHelper::getUserData('cust_no')); |
|
154
|
|
|
$hResult->execute(); |
|
155
|
|
|
|
|
156
|
|
|
if ($hResult->rowCount() >= 1) { |
|
157
|
|
|
$aData = []; |
|
158
|
|
|
while ($aRow = $hResult->fetch()) { |
|
159
|
|
|
$sStatus = SHelper::showOrderStatusText($this->textcats, $aRow["o_ordercompleted"]); |
|
160
|
|
|
|
|
161
|
|
|
if ($aRow["o_paymentmethod"] === 'prepay') { |
|
162
|
|
|
$sPaymentmethod = $this->textcats->T("order_paymentmethod_prepay"); |
|
163
|
|
|
} elseif ($aRow["o_paymentmethod"] === 'paypal') { |
|
164
|
|
|
$sPaymentmethod = $this->textcats->T("order_paymentmethod_paypal"); |
|
165
|
|
|
} elseif ($aRow["o_paymentmethod"] === 'debit') { |
|
166
|
|
|
$sPaymentmethod = $this->textcats->T("order_paymentmethod_debit"); |
|
167
|
|
|
} elseif ($aRow["o_paymentmethod"] === 'invoice') { |
|
168
|
|
|
$sPaymentmethod = $this->textcats->T("order_paymentmethod_invoice"); |
|
169
|
|
|
} else { |
|
170
|
|
|
$sPaymentmethod = ucwords($aRow["o_paymentmethod"]); |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
if ($aRow["o_paymentcompleted"] === 'y') { |
|
174
|
|
|
$sPaymentstatus = ucwords($this->textcats->T("misc_yes")); |
|
175
|
|
|
} else { |
|
176
|
|
|
$sPaymentstatus = ucwords($this->textcats->T("misc_no")); |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
$aData[] = [ |
|
180
|
|
|
'o_id' => $aRow["o_id"], |
|
181
|
|
|
'o_order_status' => $sStatus, |
|
182
|
|
|
'o_ordertime' => date( |
|
183
|
|
|
HelperConfig::$customer['locale_format_date_time'], |
|
184
|
|
|
$aRow["o_ordertimestamp"] |
|
185
|
|
|
), |
|
186
|
|
|
'o_paymentmethod' => $sPaymentmethod, |
|
187
|
|
|
'o_paymentcompleted' => $sPaymentstatus, |
|
188
|
|
|
'o_shipping_service' => $aRow["o_shipping_service"], |
|
189
|
|
|
'o_shipping_trackingno' => $aRow["o_shipping_trackingno"], |
|
190
|
|
|
]; |
|
191
|
|
|
} |
|
192
|
|
|
$return .= \HaaseIT\Toolbox\Tools::makeListtable($COList, $aData, $this->serviceManager->get('twig')); |
|
193
|
|
|
} else { |
|
194
|
|
|
$return .= $this->textcats->T("myorders_no_orders_to_display"); |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
return $return; |
|
198
|
|
|
} |
|
199
|
|
|
} |
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: