feat: UI changes
This commit is contained in:
@@ -266,6 +266,7 @@ TEXT,
|
||||
'module_tgshop_customer_notification_template' => <<<TEXT
|
||||
Спасибо за Ваш заказ в магазине *{store_name}*
|
||||
|
||||
*Номер заказа* \#{order_id}
|
||||
*Сумма заказа:* {total}
|
||||
*Дата оформления:* {created_at}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ class Email implements ValidationRuleInterface
|
||||
{
|
||||
$email = $input[$field] ?? '';
|
||||
|
||||
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
if ($email && !filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
$fail('Email is not valid');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,12 +20,14 @@ class OrderHandler
|
||||
public function store(Request $request): JsonResponse
|
||||
{
|
||||
try {
|
||||
$this->orderCreateService->create($request->json(), [
|
||||
$order = $this->orderCreateService->create($request->json(), [
|
||||
'ip' => $request->getClientIp(),
|
||||
'user_agent' => $request->getUserAgent(),
|
||||
]);
|
||||
|
||||
return new JsonResponse([], Response::HTTP_CREATED);
|
||||
return new JsonResponse([
|
||||
'data' => $order,
|
||||
], Response::HTTP_CREATED);
|
||||
} catch (OrderValidationFailedException $exception) {
|
||||
return new JsonResponse([
|
||||
'data' => $exception->getErrorBag()->firstOfAll(),
|
||||
|
||||
@@ -6,6 +6,8 @@ namespace App\Services;
|
||||
|
||||
use App\Decorators\OcRegistryDecorator;
|
||||
use App\Exceptions\OrderValidationFailedException;
|
||||
use Cassandra\Date;
|
||||
use DateTime;
|
||||
use Exception;
|
||||
use Openguru\OpenCartFramework\Config\Settings;
|
||||
use Openguru\OpenCartFramework\Logger\LoggerInterface;
|
||||
@@ -44,7 +46,7 @@ class OrderCreateService
|
||||
$this->validator = $validator;
|
||||
}
|
||||
|
||||
public function create(array $data, array $meta = []): void
|
||||
public function create(array $data, array $meta = []): array
|
||||
{
|
||||
try {
|
||||
$this->validate($data);
|
||||
@@ -178,6 +180,19 @@ class OrderCreateService
|
||||
$orderData['total'] = $cart['total_text'] ?? '';
|
||||
|
||||
$this->sendNotifications($orderData, $data['tgData']);
|
||||
|
||||
$dateTimeFormatted = '';
|
||||
try {
|
||||
$dateTimeFormatted = (new DateTime($orderData['date_added']))->format('d.m.Y H:i');
|
||||
} catch (Exception $exception) {
|
||||
$this->logger->logException($exception);
|
||||
}
|
||||
|
||||
return [
|
||||
'id' => $orderData['order_id'],
|
||||
'created_at' => $dateTimeFormatted,
|
||||
'total' => $orderData['total'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -220,7 +235,7 @@ class OrderCreateService
|
||||
if ($chatId && $template) {
|
||||
$message = $this->telegramService->prepareMessage($template, $variables);
|
||||
try {
|
||||
$this->telegramService->sendMessage($chatId, $message);
|
||||
$this->telegramService->sendMessage((int) $chatId, $message);
|
||||
} catch (Exception $exception) {
|
||||
$this->logger->error("Telegram sendMessage to owner error. ChatID: $chatId, Message: $message");
|
||||
$this->logger->logException($exception);
|
||||
@@ -247,10 +262,8 @@ class OrderCreateService
|
||||
return [
|
||||
'firstName' => 'required',
|
||||
'lastName' => 'required',
|
||||
'email' => 'required|email',
|
||||
'phone' => 'required',
|
||||
'address' => 'required',
|
||||
'comment' => 'required',
|
||||
'email' => 'email',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user