Add OTC order date picker

This commit is contained in:
2026-06-16 15:08:56 +02:00
parent 3dd5f5f1b4
commit dd4c46768f
3 changed files with 39 additions and 4 deletions
+9 -1
View File
@@ -30,7 +30,7 @@ if (!is_array($data)) {
json_response(400, ['ok' => false, 'error' => 'JSON object expected']);
}
$required = ['products', 'totalPrice', 'paymentMethod', 'billing'];
$required = ['products', 'totalPrice', 'orderDate', 'paymentMethod', 'billing'];
foreach ($required as $field) {
if (!array_key_exists($field, $data)) {
json_response(422, ['ok' => false, 'error' => "Missing field: {$field}"]);
@@ -39,6 +39,7 @@ foreach ($required as $field) {
$products = $data['products'];
$totalPrice = parse_number($data['totalPrice']);
$orderDate = trim((string) $data['orderDate']);
$paymentMethodCode = trim((string) $data['paymentMethod']);
$billing = is_array($data['billing']) ? $data['billing'] : [];
@@ -50,6 +51,12 @@ if ($totalPrice === null || $totalPrice <= 0) {
json_response(422, ['ok' => false, 'error' => 'Invalid total price']);
}
$orderDateTime = DateTimeImmutable::createFromFormat('!Y-m-d', $orderDate);
$orderDateErrors = DateTimeImmutable::getLastErrors();
if ($orderDateTime === false || $orderDateErrors === false || $orderDateErrors['warning_count'] > 0 || $orderDateErrors['error_count'] > 0) {
json_response(422, ['ok' => false, 'error' => 'Invalid order date']);
}
$resolvedProducts = [];
$totalQty = 0.0;
foreach ($products as $product) {
@@ -94,6 +101,7 @@ try {
':payment_method_id' => $paymentMethodId,
':amount_net' => $totalPrice,
':total_amount' => $totalPrice,
':order_date' => $orderDateTime->format('Y-m-d H:i:s'),
]);
$orderId = (int) $order['id'];