Add OTC order date picker
This commit is contained in:
@@ -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'];
|
||||
|
||||
Reference in New Issue
Block a user