update
This commit is contained in:
@@ -264,6 +264,67 @@ final class OrdersController
|
||||
return Response::html($html);
|
||||
}
|
||||
|
||||
public function updateDetails(Request $request): Response
|
||||
{
|
||||
$orderId = max(0, (int) $request->input('id', 0));
|
||||
if ($orderId <= 0) {
|
||||
return Response::html('Not found', 404);
|
||||
}
|
||||
|
||||
$csrfToken = (string) $request->input('_token', '');
|
||||
if (!Csrf::validate($csrfToken)) {
|
||||
Flash::set('order.error', $this->translator->get('auth.errors.csrf_expired'));
|
||||
return Response::redirect('/orders/' . $orderId);
|
||||
}
|
||||
|
||||
$details = $this->orders->findDetails($orderId);
|
||||
if (!is_array($details['order'] ?? null)) {
|
||||
return Response::html('Not found', 404);
|
||||
}
|
||||
|
||||
$deliveryMethodRaw = trim((string) $request->input('delivery_method', ''));
|
||||
$paymentMethodRaw = trim((string) $request->input('payment_method', ''));
|
||||
$isCod = (string) $request->input('is_cod', '') === '1';
|
||||
|
||||
if ($deliveryMethodRaw === '' && $paymentMethodRaw === '') {
|
||||
Flash::set('order.error', 'Podaj formę dostawy lub formę płatności.');
|
||||
return Response::redirect('/orders/' . $orderId);
|
||||
}
|
||||
|
||||
$deliveryMethod = $deliveryMethodRaw !== '' ? $deliveryMethodRaw : null;
|
||||
$paymentMethod = $paymentMethodRaw !== '' ? $paymentMethodRaw : null;
|
||||
|
||||
$externalPaymentTypeId = null;
|
||||
$currentOrder = (array) $details['order'];
|
||||
$currentExternal = strtoupper(trim((string) ($currentOrder['external_payment_type_id'] ?? '')));
|
||||
$currentlyCod = StringHelper::isCodPayment($currentExternal);
|
||||
if ($isCod && !$currentlyCod) {
|
||||
$externalPaymentTypeId = 'CASH_ON_DELIVERY';
|
||||
} elseif (!$isCod && $currentlyCod) {
|
||||
$externalPaymentTypeId = '';
|
||||
}
|
||||
|
||||
$user = $this->auth->user();
|
||||
$actorName = is_array($user) ? trim((string) ($user['name'] ?? $user['email'] ?? '')) : null;
|
||||
|
||||
$changed = $this->orders->updateDeliveryAndPayment(
|
||||
$orderId,
|
||||
$deliveryMethod,
|
||||
$paymentMethod,
|
||||
$externalPaymentTypeId,
|
||||
'user',
|
||||
$actorName !== '' ? $actorName : null
|
||||
);
|
||||
|
||||
if ($changed) {
|
||||
Flash::set('order.success', 'Dane zamówienia zostały zaktualizowane.');
|
||||
} else {
|
||||
Flash::set('order.error', 'Brak zmian do zapisania.');
|
||||
}
|
||||
|
||||
return Response::redirect('/orders/' . $orderId);
|
||||
}
|
||||
|
||||
public function updateStatus(Request $request): Response
|
||||
{
|
||||
$isAjax = strtolower($request->header('X-Requested-With')) === 'xmlhttprequest';
|
||||
@@ -405,9 +466,28 @@ final class OrdersController
|
||||
$documents
|
||||
),
|
||||
'ordered_at' => (string) ($row['ordered_at'] ?? ''),
|
||||
'_row_class' => $this->agedRowClass((string) ($row['ordered_at'] ?? '')),
|
||||
];
|
||||
}
|
||||
|
||||
private function agedRowClass(string $orderedAt): string
|
||||
{
|
||||
if ($orderedAt === '') {
|
||||
return '';
|
||||
}
|
||||
$ts = strtotime($orderedAt);
|
||||
if ($ts === false) {
|
||||
return '';
|
||||
}
|
||||
$ageDays = (int) floor((time() - $ts) / 86400);
|
||||
if ($ageDays < 4) {
|
||||
return '';
|
||||
}
|
||||
$level = $ageDays >= 7 ? 7 : $ageDays;
|
||||
|
||||
return 'order-row-aged order-row-aged-' . $level;
|
||||
}
|
||||
|
||||
private function statusBadge(string $statusCode, string $statusLabel, string $colorHex = ''): string
|
||||
{
|
||||
$label = $statusLabel !== '' ? $statusLabel : '-';
|
||||
|
||||
Reference in New Issue
Block a user