Complete port of all 163 API endpoints from Lucee/CFML to PHP 8.3. Shared helpers in api/helpers.php (DB, auth, request/response, security). PDO prepared statements throughout. Same JSON response shapes as CFML.
91 lines
4.2 KiB
PHP
91 lines
4.2 KiB
PHP
<?php
|
|
/**
|
|
* Shared function to load full cart payload for an order.
|
|
* Used by setLineItem, setOrderType, getOrCreateCart.
|
|
*/
|
|
|
|
function loadCartPayload(int $OrderID): array {
|
|
$qOrder = queryOne("
|
|
SELECT
|
|
o.ID, o.UUID, o.UserID, o.BusinessID, o.DeliveryMultiplier,
|
|
o.OrderTypeID, o.DeliveryFee, o.StatusID, o.AddressID, o.PaymentID,
|
|
o.Remarks, o.AddedOn, o.LastEditedOn, o.SubmittedOn,
|
|
o.ServicePointID, o.GrantID, o.GrantOwnerBusinessID,
|
|
o.GrantEconomicsType, o.GrantEconomicsValue, o.TabID,
|
|
sp.Name AS ServicePointName,
|
|
COALESCE(b.DeliveryFlatFee, 0) AS BusinessDeliveryFee,
|
|
COALESCE(b.TaxRate, 0) AS TaxRate,
|
|
COALESCE(b.PayfritFee, 0.05) AS PayfritFee
|
|
FROM Orders o
|
|
LEFT JOIN Businesses b ON b.ID = o.BusinessID
|
|
LEFT JOIN ServicePoints sp ON sp.ID = o.ServicePointID
|
|
WHERE o.ID = ?
|
|
LIMIT 1
|
|
", [$OrderID]);
|
|
|
|
if (!$qOrder) {
|
|
return ['OK' => false, 'ERROR' => 'not_found', 'MESSAGE' => 'Order not found', 'DETAIL' => ''];
|
|
}
|
|
|
|
$order = [
|
|
'OrderID' => (int) $qOrder['ID'],
|
|
'UUID' => $qOrder['UUID'] ?? '',
|
|
'UserID' => (int) $qOrder['UserID'],
|
|
'BusinessID' => (int) $qOrder['BusinessID'],
|
|
'DeliveryMultiplier' => (float) $qOrder['DeliveryMultiplier'],
|
|
'OrderTypeID' => (int) $qOrder['OrderTypeID'],
|
|
'DeliveryFee' => (float) $qOrder['DeliveryFee'],
|
|
'BusinessDeliveryFee' => (float) $qOrder['BusinessDeliveryFee'],
|
|
'TaxRate' => (float) $qOrder['TaxRate'],
|
|
'PayfritFee' => (float) $qOrder['PayfritFee'],
|
|
'StatusID' => (int) $qOrder['StatusID'],
|
|
'AddressID' => (int) ($qOrder['AddressID'] ?? 0),
|
|
'PaymentID' => (int) ($qOrder['PaymentID'] ?? 0),
|
|
'Remarks' => $qOrder['Remarks'] ?? '',
|
|
'AddedOn' => $qOrder['AddedOn'],
|
|
'LastEditedOn' => $qOrder['LastEditedOn'],
|
|
'SubmittedOn' => $qOrder['SubmittedOn'],
|
|
'ServicePointID' => (int) ($qOrder['ServicePointID'] ?? 0),
|
|
'ServicePointName' => $qOrder['ServicePointName'] ?? '',
|
|
'GrantID' => (int) ($qOrder['GrantID'] ?? 0),
|
|
'GrantOwnerBusinessID' => (int) ($qOrder['GrantOwnerBusinessID'] ?? 0),
|
|
'GrantEconomicsType' => $qOrder['GrantEconomicsType'] ?? '',
|
|
'GrantEconomicsValue' => (float) ($qOrder['GrantEconomicsValue'] ?? 0),
|
|
'TabID' => (int) ($qOrder['TabID'] ?? 0),
|
|
];
|
|
|
|
$qLI = queryTimed("
|
|
SELECT
|
|
oli.ID, oli.ParentOrderLineItemID, oli.OrderID, oli.ItemID,
|
|
oli.StatusID, oli.Price, oli.Quantity, oli.Remark, oli.IsDeleted, oli.AddedOn,
|
|
i.Name, i.ParentItemID, i.IsCheckedByDefault,
|
|
parent.Name AS ItemParentName
|
|
FROM OrderLineItems oli
|
|
INNER JOIN Items i ON i.ID = oli.ItemID
|
|
LEFT JOIN Items parent ON parent.ID = i.ParentItemID
|
|
WHERE oli.OrderID = ?
|
|
ORDER BY oli.ID
|
|
", [$OrderID]);
|
|
|
|
$rows = [];
|
|
foreach ($qLI as $r) {
|
|
$rows[] = [
|
|
'OrderLineItemID' => (int) $r['ID'],
|
|
'ParentOrderLineItemID' => (int) $r['ParentOrderLineItemID'],
|
|
'OrderID' => (int) $r['OrderID'],
|
|
'ItemID' => (int) $r['ItemID'],
|
|
'StatusID' => (int) $r['StatusID'],
|
|
'Price' => (float) $r['Price'],
|
|
'Quantity' => (int) $r['Quantity'],
|
|
'Remark' => $r['Remark'] ?? '',
|
|
'IsDeleted' => (int) $r['IsDeleted'],
|
|
'AddedOn' => $r['AddedOn'],
|
|
'Name' => $r['Name'] ?? '',
|
|
'ParentItemID' => (int) $r['ParentItemID'],
|
|
'ItemParentName' => $r['ItemParentName'] ?? '',
|
|
'IsCheckedByDefault' => (int) $r['IsCheckedByDefault'],
|
|
];
|
|
}
|
|
|
|
return ['OK' => true, 'ERROR' => '', 'ORDER' => $order, 'ORDERLINEITEMS' => $rows];
|
|
}
|