update
This commit is contained in:
@@ -16,6 +16,7 @@ use App\Modules\Email\EmailSendingService;
|
||||
use App\Modules\Settings\EmailMailboxRepository;
|
||||
use App\Modules\Settings\EmailTemplateRepository;
|
||||
use App\Modules\Settings\ReceiptConfigRepository;
|
||||
use App\Modules\Automation\AutomationService;
|
||||
use App\Modules\Settings\ShopproApiClient;
|
||||
use App\Modules\Settings\ShopproIntegrationsRepository;
|
||||
use App\Modules\Shipments\ShipmentPackageRepository;
|
||||
@@ -35,7 +36,8 @@ final class OrdersController
|
||||
private readonly ?EmailMailboxRepository $emailMailboxRepo = null,
|
||||
private readonly string $storagePath = '',
|
||||
private readonly ?\App\Modules\Printing\PrintJobRepository $printJobRepo = null,
|
||||
private readonly ?ShopproIntegrationsRepository $shopproIntegrations = null
|
||||
private readonly ?ShopproIntegrationsRepository $shopproIntegrations = null,
|
||||
private readonly ?AutomationService $automation = null
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -275,8 +277,25 @@ final class OrdersController
|
||||
$user = $this->auth->user();
|
||||
$actorName = is_array($user) ? trim((string) ($user['name'] ?? $user['email'] ?? '')) : null;
|
||||
|
||||
$oldDetails = $this->orders->findDetails($orderId);
|
||||
$oldOrder = is_array($oldDetails['order'] ?? null) ? $oldDetails['order'] : [];
|
||||
$oldStatus = strtolower(trim((string) ($oldOrder['external_status_id'] ?? '')));
|
||||
|
||||
$success = $this->orders->updateOrderStatus($orderId, $newStatus, 'user', $actorName !== '' ? $actorName : null);
|
||||
|
||||
if ($success) {
|
||||
$normalizedNew = strtolower(trim($newStatus));
|
||||
if ($oldStatus !== $normalizedNew) {
|
||||
try {
|
||||
$this->automation?->trigger('order.status_changed', $orderId, [
|
||||
'old_status' => $oldStatus,
|
||||
'new_status' => $normalizedNew,
|
||||
]);
|
||||
} catch (\Throwable) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($isAjax) {
|
||||
if (!$success) {
|
||||
return Response::json(['success' => false, 'error' => $this->translator->get('orders.details.status_change.failed')], 500);
|
||||
@@ -791,7 +810,7 @@ final class OrdersController
|
||||
return Response::json(['ok' => false, 'error' => 'Nieprawidłowe ID zamówienia.'], 400);
|
||||
}
|
||||
|
||||
if (!Csrf::verify((string) $request->input('_token', ''))) {
|
||||
if (!Csrf::validate((string) $request->input('_token', ''))) {
|
||||
return Response::json(['ok' => false, 'error' => 'Nieprawidłowy token CSRF.'], 403);
|
||||
}
|
||||
|
||||
@@ -807,12 +826,16 @@ final class OrdersController
|
||||
return Response::json(['ok' => false, 'error' => 'Wybierz typ płatności.'], 422);
|
||||
}
|
||||
|
||||
$result = $this->orders->addPayment($orderId, [
|
||||
'amount' => $amount,
|
||||
'payment_type_id' => $paymentTypeId,
|
||||
'payment_date' => $paymentDate !== '' ? $paymentDate . ' ' . date('H:i:s') : '',
|
||||
'comment' => $comment,
|
||||
]);
|
||||
try {
|
||||
$result = $this->orders->addPayment($orderId, [
|
||||
'amount' => $amount,
|
||||
'payment_type_id' => $paymentTypeId,
|
||||
'payment_date' => $paymentDate !== '' ? $paymentDate . ' ' . date('H:i:s') : '',
|
||||
'comment' => $comment,
|
||||
]);
|
||||
} catch (\Throwable $ex) {
|
||||
return Response::json(['ok' => false, 'error' => 'Błąd zapisu: ' . $ex->getMessage()], 500);
|
||||
}
|
||||
|
||||
if ($result === null) {
|
||||
return Response::json(['ok' => false, 'error' => 'Nie udało się zapisać płatności.'], 500);
|
||||
@@ -824,9 +847,18 @@ final class OrdersController
|
||||
'Dodano płatność: ' . number_format($amount, 2, '.', ' ') . ' PLN (' . $paymentTypeId . ')',
|
||||
['payment_id' => $result['id'], 'amount' => $amount, 'type' => $paymentTypeId],
|
||||
'user',
|
||||
$this->auth->user()['name'] ?? null
|
||||
($this->auth->user() ?? [])['name'] ?? null
|
||||
);
|
||||
|
||||
try {
|
||||
$this->automation?->trigger('payment.status_changed', $orderId, [
|
||||
'new_payment_status' => (string) $result['payment_status'],
|
||||
'total_paid' => $result['total_paid'],
|
||||
'payment_type_id' => $paymentTypeId,
|
||||
]);
|
||||
} catch (\Throwable) {
|
||||
}
|
||||
|
||||
$this->pushPaymentToShoppro($orderId, $result['payment_status']);
|
||||
|
||||
return Response::json([
|
||||
|
||||
Reference in New Issue
Block a user