Skip to content

Commit 3dc3f90

Browse files
committed
sf: account/history controller minor improvements
1 parent b4df904 commit 3dc3f90

File tree

2 files changed

+59
-54
lines changed

2 files changed

+59
-54
lines changed

public_html/storefront/controller/pages/account/order_details.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* AbanteCart, Ideal OpenSource Ecommerce Solution
66
* http://www.AbanteCart.com
77
*
8-
* Copyright © 2011-2025 Belavier Commerce LLC
8+
* Copyright © 2011-2026 Belavier Commerce LLC
99
*
1010
* This source file is subject to Open Software License (OSL 3.0)
1111
* License details are bundled with this package in the file LICENSE.txt.
@@ -265,14 +265,16 @@ public function main()
265265
$histories = [];
266266
$results = $mdlOrder->getOrderHistories($orderId);
267267
foreach ($results as $result) {
268-
$histories[] = [
269-
'date_added' => dateISO2Display(
270-
$result['date_added'],
271-
$this->language->get('date_format_short') . ' ' . $this->language->get('time_format')
272-
),
273-
'status' => $result['status'],
274-
'comment' => nl2br(strip_tags(html_entity_decode($result['comment']))),
275-
];
268+
$histories[] = array_merge(
269+
$result,
270+
[
271+
'date_added' => dateISO2Display(
272+
$result['date_added'],
273+
$this->language->get('date_format_short') . ' ' . $this->language->get('time_format')
274+
),
275+
'comment' => nl2br(strip_tags(html_entity_decode($result['comment']))),
276+
]
277+
);
276278
}
277279
$this->data['histories'] = $histories;
278280
$this->data['continue'] = $guest

public_html/storefront/model/account/order.php

Lines changed: 48 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
/** @noinspection PhpMultipleClassDeclarationsInspection */
3+
24
/*
35
* $Id$
46
*
@@ -30,7 +32,7 @@ class ModelAccountOrder extends Model
3032
*/
3133
public function getOrder($orderId, $orderStatusId = '', $mode = '')
3234
{
33-
$orderId = (int)$orderId;
35+
$orderId = (int) $orderId;
3436
if (!$orderId) {
3537
return [];
3638
}
@@ -44,15 +46,15 @@ public function getOrder($orderId, $orderStatusId = '', $mode = '')
4446
$status_check = "";
4547
} else {
4648
//only specific status
47-
$status_check = " AND order_status_id = '" . (int)$orderStatusId . "'";
49+
$status_check = " AND order_status_id = '" . (int) $orderStatusId . "'";
4850
}
4951
}
5052

5153
$sql = "SELECT *
5254
FROM `" . $this->db->table("orders") . "`
53-
WHERE order_id = '" . (int)$orderId . "' ";
55+
WHERE order_id = '" . (int) $orderId . "' ";
5456
if ($mode == '') {
55-
$sql .= " AND customer_id = '" . (int)$this->customer->getId() . "'";
57+
$sql .= " AND customer_id = '" . (int) $this->customer->getId() . "'";
5658
}
5759
$sql .= $status_check;
5860
$result = $this->db->query($sql);
@@ -66,29 +68,29 @@ public function getOrder($orderId, $orderStatusId = '', $mode = '')
6668
/** @var ModelLocalisationZone $zMdl */
6769
$zMdl = $this->load->model('localisation/zone');
6870
$countryInfo = $cMdl->getCountry($orderRow['shipping_country_id']);
69-
$shippingIsoCode2 = $countryInfo['iso_code_2'] ?: '';
70-
$shippingIsoCode3 = $countryInfo['iso_code_3'] ?: '';
71+
$shippingIsoCode2 = $countryInfo['iso_code_2'] ? : '';
72+
$shippingIsoCode3 = $countryInfo['iso_code_3'] ? : '';
7173
$zoneInfo = $zMdl->getZone($orderRow['shipping_zone_id']);
72-
$shippingZoneCode = $zoneInfo['code'] ?: '';
74+
$shippingZoneCode = $zoneInfo['code'] ? : '';
7375

7476
$countryInfo = $cMdl->getCountry($orderRow['payment_country_id']);
75-
$paymentIsoCode2 = $countryInfo['iso_code_2'] ?: '';
76-
$paymentIsoCode3 = $countryInfo['iso_code_3'] ?: '';
77+
$paymentIsoCode2 = $countryInfo['iso_code_2'] ? : '';
78+
$paymentIsoCode3 = $countryInfo['iso_code_3'] ? : '';
7779
$zoneInfo = $zMdl->getZone($orderRow['payment_zone_id']);
78-
$payment_zone_code = $zoneInfo['code'] ?: '';
80+
$payment_zone_code = $zoneInfo['code'] ? : '';
7981

8082
$orderRow['ext_fields'] = $orderRow['ext_fields']
8183
? json_decode($orderRow['ext_fields'], true)
8284
: [];
8385
return
8486
$orderRow +
8587
[
86-
'shipping_zone_code' => $shippingZoneCode,
88+
'shipping_zone_code' => $shippingZoneCode,
8789
'shipping_iso_code_2' => $shippingIsoCode2,
8890
'shipping_iso_code_3' => $shippingIsoCode3,
89-
'payment_zone_code' => $payment_zone_code,
90-
'payment_iso_code_2' => $paymentIsoCode2,
91-
'payment_iso_code_3' => $paymentIsoCode3,
91+
'payment_zone_code' => $payment_zone_code,
92+
'payment_iso_code_2' => $paymentIsoCode2,
93+
'payment_iso_code_3' => $paymentIsoCode3,
9294
];
9395
}
9496

@@ -101,12 +103,12 @@ public function getOrder($orderId, $orderStatusId = '', $mode = '')
101103
*/
102104
public function getOrders($start = 0, $limit = 20)
103105
{
104-
$language_id = (int)$this->config->get('storefront_language_id');
106+
$language_id = (int) $this->config->get('storefront_language_id');
105107
if ($start < 0) {
106108
$start = 0;
107109
}
108110
$query = $this->db->query(
109-
"SELECT ".$this->db->getSqlCalcTotalRows()."
111+
"SELECT " . $this->db->getSqlCalcTotalRows() . "
110112
o.order_id,
111113
o.firstname,
112114
o.lastname,
@@ -118,12 +120,13 @@ public function getOrders($start = 0, $limit = 20)
118120
FROM `" . $this->db->table("orders") . "` o
119121
LEFT JOIN " . $this->db->table("order_statuses") . " os
120122
ON (o.order_status_id = os.order_status_id
121-
AND os.language_id = '" . (int)$language_id . "')
122-
WHERE customer_id = '" . (int)$this->customer->getId() . "'
123+
AND os.language_id = '" . $language_id . "')
124+
WHERE customer_id = '" . (int) $this->customer->getId() . "'
123125
AND o.order_status_id > '0'
124126
ORDER BY o.order_id DESC
125-
LIMIT " . (int)$start . "," . (int)$limit);
126-
if($query->num_rows) {
127+
LIMIT " . (int) $start . "," . (int) $limit
128+
);
129+
if ($query->num_rows) {
127130
$totalNumRows = $this->db->getTotalNumRows();
128131
$query->rows[0]['total_num_rows'] = $totalNumRows;
129132
}
@@ -141,7 +144,7 @@ public function getOrderProducts($order_id)
141144
$query = $this->db->query(
142145
"SELECT *
143146
FROM " . $this->db->table("order_products") . "
144-
WHERE order_id = '" . (int)$order_id . "'"
147+
WHERE order_id = '" . (int) $order_id . "'"
145148
);
146149
return $query->rows;
147150
}
@@ -162,8 +165,8 @@ public function getOrderOptions($order_id, $order_product_id)
162165
ON pov.product_option_value_id = oo.product_option_value_id
163166
LEFT JOIN " . $this->db->table('product_options') . " po
164167
ON po.product_option_id = pov.product_option_id
165-
WHERE oo.order_id = '" . (int)$order_id . "'
166-
AND oo.order_product_id = '" . (int)$order_product_id . "'
168+
WHERE oo.order_id = '" . (int) $order_id . "'
169+
AND oo.order_product_id = '" . (int) $order_product_id . "'
167170
ORDER BY po.sort_order"
168171
);
169172
return $query->rows;
@@ -180,7 +183,7 @@ public function getOrderTotals($order_id)
180183
$query = $this->db->query(
181184
"SELECT *
182185
FROM " . $this->db->table("order_totals") . "
183-
WHERE order_id = '" . (int)$order_id . "'
186+
WHERE order_id = '" . (int) $order_id . "'
184187
ORDER BY sort_order"
185188
);
186189
return $query->rows;
@@ -194,14 +197,14 @@ public function getOrderTotals($order_id)
194197
*/
195198
public function getOrderStatus($order_id)
196199
{
197-
$language_id = (int)$this->config->get('storefront_language_id');
200+
$language_id = (int) $this->config->get('storefront_language_id');
198201
$query = $this->db->query(
199202
"SELECT os.name AS status
200203
FROM " . $this->db->table("orders") . " o,
201204
" . $this->db->table("order_statuses") . " os
202-
WHERE o.order_id = '" . (int)$order_id . "'
205+
WHERE o.order_id = '" . (int) $order_id . "'
203206
AND o.order_status_id = os.order_status_id
204-
AND os.language_id = '" . (int)$language_id . "'"
207+
AND os.language_id = '" . $language_id . "'"
205208
);
206209
return $query->row['status'];
207210
}
@@ -214,18 +217,15 @@ public function getOrderStatus($order_id)
214217
*/
215218
public function getOrderHistories($order_id)
216219
{
217-
$language_id = (int)$this->config->get('storefront_language_id');
220+
$language_id = (int) $this->config->get('storefront_language_id');
218221
$query = $this->db->query(
219-
"SELECT date_added,
220-
os.name AS status,
221-
oh.comment,
222-
oh.notify
222+
"SELECT os.name AS status, oh.*
223223
FROM " . $this->db->table("order_history") . " oh
224224
LEFT JOIN " . $this->db->table("order_statuses") . " os
225225
ON oh.order_status_id = os.order_status_id
226-
WHERE oh.order_id = '" . (int)$order_id . "'
226+
WHERE oh.order_id = '" . (int) $order_id . "'
227227
AND oh.notify = '1'
228-
AND os.language_id = '" . (int)$language_id . "'
228+
AND os.language_id = '" . $language_id . "'
229229
ORDER BY oh.date_added"
230230
);
231231
return $query->rows;
@@ -242,7 +242,7 @@ public function getOrderDownloads($order_id)
242242
$query = $this->db->query(
243243
"SELECT *
244244
FROM " . $this->db->table("order_downloads") . "
245-
WHERE order_id = '" . (int)$order_id . "'
245+
WHERE order_id = '" . (int) $order_id . "'
246246
ORDER BY sort_order"
247247
);
248248
return $query->rows;
@@ -257,9 +257,9 @@ public function getTotalOrders()
257257
$query = $this->db->query(
258258
"SELECT COUNT(*) AS total
259259
FROM `" . $this->db->table("orders") . "`
260-
WHERE customer_id = '" . (int)$this->customer->getId() . "' AND order_status_id > '0'"
260+
WHERE customer_id = '" . (int) $this->customer->getId() . "' AND order_status_id > '0'"
261261
);
262-
return (int)$query->row['total'];
262+
return (int) $query->row['total'];
263263
}
264264

265265
/**
@@ -270,28 +270,29 @@ public function getTotalOrders()
270270
*/
271271
public function getTotalOrderProductsByOrderId(int|array $orderId)
272272
{
273-
if(is_int($orderId)) {
273+
if (is_int($orderId)) {
274274
$sql = "SELECT COUNT(*) AS total
275275
FROM " . $this->db->table("order_products") . "
276276
WHERE order_id = " . $orderId;
277-
$query = $this->db->query( $sql );
278-
return (int)$query->row['total'];
279-
}else{
277+
$query = $this->db->query($sql);
278+
return (int) $query->row['total'];
279+
} else {
280280
$orderIds = filterIntegerIdList($orderId);
281-
if($orderIds) {
281+
if ($orderIds) {
282282
$sql = "SELECT COUNT(*) AS total, order_id
283283
FROM " . $this->db->table("order_products") . "
284-
WHERE order_id IN (" . implode(',',$orderIds) . ")
284+
WHERE order_id IN (" . implode(',', $orderIds) . ")
285285
GROUP BY order_id";
286286
$query = $this->db->query($sql);
287-
return array_column( $query->rows, 'total','order_id' );
287+
return array_column($query->rows, 'total', 'order_id');
288288
}
289289
}
290290
return [];
291291
}
292292

293293
/**
294294
* @param array $list
295+
*
295296
* @return array
296297
* @throws AException
297298
*/
@@ -304,7 +305,9 @@ public function prepareExtendedFields(array $list = [])
304305
$sql = "SELECT *
305306
FROM " . $this->db->table('fields') . " f
306307
LEFT JOIN " . $this->db->table('field_descriptions') . " fd
307-
ON fd.field_id = f.field_id AND fd.language_id = '" . (int)$this->config->get('storefront_language_id') . "'
308+
ON fd.field_id = f.field_id AND fd.language_id = '" . (int) $this->config->get(
309+
'storefront_language_id'
310+
) . "'
308311
WHERE f.field_name IN ('" . implode("','", $names) . "')";
309312
$result = $this->db->query($sql);
310313
$output = [];

0 commit comments

Comments
 (0)