update
This commit is contained in:
@@ -16,7 +16,7 @@ use Throwable;
|
||||
final class AutomationController
|
||||
{
|
||||
private const HISTORY_PER_PAGE = 25;
|
||||
private const ALLOWED_EVENTS = ['receipt.created', 'shipment.created', 'shipment.status_changed', 'payment.status_changed', 'order.status_changed', 'order.status_aged'];
|
||||
private const ALLOWED_EVENTS = ['receipt.created', 'shipment.created', 'shipment.status_changed', 'payment.status_changed', 'order.status_changed', 'order.status_aged', 'order.imported'];
|
||||
private const ALLOWED_CONDITION_TYPES = ['integration', 'shipment_status', 'payment_status', 'order_status', 'days_in_status'];
|
||||
private const PAYMENT_STATUS_OPTIONS = [
|
||||
'0' => 'Nieopłacone',
|
||||
|
||||
@@ -23,6 +23,7 @@ use App\Modules\Settings\AllegroOAuthClient;
|
||||
use App\Modules\Settings\AllegroOrderImportService;
|
||||
use App\Modules\Settings\AllegroOrdersSyncService;
|
||||
use App\Modules\Settings\AllegroOrderSyncStateRepository;
|
||||
use App\Modules\Settings\AllegroPullStatusMappingRepository;
|
||||
use App\Modules\Settings\AllegroStatusMappingRepository;
|
||||
use App\Modules\Settings\AllegroStatusSyncService;
|
||||
use App\Modules\Settings\AllegroTokenManager;
|
||||
@@ -70,13 +71,18 @@ final class CronHandlerFactory
|
||||
$ordersRepository = new OrdersRepository($this->db);
|
||||
$allegroSyncStateRepository = new AllegroOrderSyncStateRepository($this->db);
|
||||
|
||||
$allegroPullStatusMappingRepo = new AllegroPullStatusMappingRepository($this->db);
|
||||
$automationService = $this->buildAutomationService($ordersRepository);
|
||||
|
||||
$orderImportService = new AllegroOrderImportService(
|
||||
$integrationRepository,
|
||||
$tokenManager,
|
||||
$apiClient,
|
||||
new OrderImportRepository($this->db),
|
||||
$statusMappingRepository,
|
||||
$ordersRepository
|
||||
$ordersRepository,
|
||||
$allegroPullStatusMappingRepo,
|
||||
$automationService
|
||||
);
|
||||
|
||||
$ordersSyncService = new AllegroOrdersSyncService(
|
||||
@@ -101,7 +107,8 @@ final class CronHandlerFactory
|
||||
$ordersRepository,
|
||||
new ShopproOrderMapper(),
|
||||
new ShopproProductImageResolver($shopproApiClient),
|
||||
$shopproPullStatusMappingRepo
|
||||
$shopproPullStatusMappingRepo,
|
||||
$automationService
|
||||
);
|
||||
$shopproStatusSyncService = new ShopproStatusSyncService(
|
||||
$shopproIntegrationsRepo,
|
||||
@@ -111,7 +118,6 @@ final class CronHandlerFactory
|
||||
$shopproStatusMappingRepo,
|
||||
$this->db
|
||||
);
|
||||
$automationService = $this->buildAutomationService($ordersRepository);
|
||||
|
||||
$shopproPaymentSyncService = new ShopproPaymentStatusSyncService(
|
||||
$shopproIntegrationsRepo,
|
||||
|
||||
@@ -47,6 +47,7 @@ final class OrdersController
|
||||
'search' => trim((string) $request->input('search', '')),
|
||||
'source' => trim((string) $request->input('source', '')),
|
||||
'status' => trim((string) $request->input('status', '')),
|
||||
'status_group' => trim((string) $request->input('status_group', '')),
|
||||
'payment_status' => trim((string) $request->input('payment_status', '')),
|
||||
'date_from' => trim((string) $request->input('date_from', '')),
|
||||
'date_to' => trim((string) $request->input('date_to', '')),
|
||||
@@ -66,7 +67,7 @@ final class OrdersController
|
||||
$statusLabelMap = $this->statusLabelMap($statusConfig);
|
||||
$statusColorMap = $this->statusColorMap($statusConfig);
|
||||
$statusOptions = $this->buildStatusFilterOptions($this->orders->statusOptions(), $statusLabelMap);
|
||||
$statusPanel = $this->buildStatusPanel($statusConfig, $statusCounts, $filters['status'], $filters);
|
||||
$statusPanel = $this->buildStatusPanel($statusConfig, $statusCounts, $filters['status'], $filters, $filters['status_group']);
|
||||
|
||||
$tableRows = array_map(fn (array $row): array => $this->toTableRow($row, $statusLabelMap, $statusColorMap), (array) ($result['items'] ?? []));
|
||||
|
||||
@@ -438,7 +439,7 @@ final class OrdersController
|
||||
* @param array<string, int> $counts
|
||||
* @return array<int, array<string, mixed>>
|
||||
*/
|
||||
private function buildStatusPanel(array $config, array $counts, string $currentStatusCode, array $query = []): array
|
||||
private function buildStatusPanel(array $config, array $counts, string $currentStatusCode, array $query = [], string $currentStatusGroup = ''): array
|
||||
{
|
||||
$allCount = 0;
|
||||
foreach ($counts as $count) {
|
||||
@@ -451,7 +452,7 @@ final class OrdersController
|
||||
'code' => '',
|
||||
'label' => 'Wszystkie',
|
||||
'count' => $allCount,
|
||||
'is_active' => trim($currentStatusCode) === '',
|
||||
'is_active' => trim($currentStatusCode) === '' && trim($currentStatusGroup) === '',
|
||||
'tone' => 'neutral',
|
||||
'color_hex' => '#64748b',
|
||||
'url' => $this->statusFilterUrl($query, ''),
|
||||
@@ -461,17 +462,22 @@ final class OrdersController
|
||||
foreach ($config as $group) {
|
||||
$items = [];
|
||||
$groupColor = StringHelper::normalizeColorHex((string) ($group['color_hex'] ?? '#64748b'));
|
||||
$groupId = (string) ((int) ($group['id'] ?? 0));
|
||||
$groupItems = is_array($group['items'] ?? null) ? $group['items'] : [];
|
||||
$isActiveGroup = $currentStatusGroup !== '' && $currentStatusGroup === $groupId;
|
||||
$groupCount = 0;
|
||||
foreach ($groupItems as $status) {
|
||||
$code = strtolower(trim((string) ($status['code'] ?? '')));
|
||||
if ($code === '') {
|
||||
continue;
|
||||
}
|
||||
$statusCount = (int) ($counts[$code] ?? 0);
|
||||
$groupCount += $statusCount;
|
||||
$items[] = [
|
||||
'code' => $code,
|
||||
'label' => (string) ($status['name'] ?? $code),
|
||||
'count' => (int) ($counts[$code] ?? 0),
|
||||
'is_active' => trim(strtolower($currentStatusCode)) === $code,
|
||||
'count' => $statusCount,
|
||||
'is_active' => !$isActiveGroup && trim(strtolower($currentStatusCode)) === $code,
|
||||
'tone' => $this->statusTone($code),
|
||||
'color_hex' => $groupColor,
|
||||
'url' => $this->statusFilterUrl($query, $code),
|
||||
@@ -483,6 +489,10 @@ final class OrdersController
|
||||
$result[] = [
|
||||
'name' => (string) ($group['name'] ?? ''),
|
||||
'color_hex' => $groupColor,
|
||||
'group_id' => $groupId,
|
||||
'group_url' => $this->groupFilterUrl($query, $groupId),
|
||||
'group_count' => $groupCount,
|
||||
'is_active_group' => $isActiveGroup,
|
||||
'items' => $items,
|
||||
];
|
||||
}
|
||||
@@ -531,6 +541,7 @@ final class OrdersController
|
||||
private function statusFilterUrl(array $query, string $statusCode): string
|
||||
{
|
||||
$params = $query;
|
||||
unset($params['status_group']);
|
||||
if ($statusCode === '') {
|
||||
unset($params['status']);
|
||||
} else {
|
||||
@@ -550,6 +561,29 @@ final class OrdersController
|
||||
return $qs === '' ? '/orders/list' : '/orders/list?' . $qs;
|
||||
}
|
||||
|
||||
private function groupFilterUrl(array $query, string $groupId): string
|
||||
{
|
||||
$params = $query;
|
||||
unset($params['status']);
|
||||
if ($groupId === '' || $groupId === '0') {
|
||||
unset($params['status_group']);
|
||||
} else {
|
||||
$params['status_group'] = $groupId;
|
||||
}
|
||||
$params['page'] = 1;
|
||||
|
||||
$clean = [];
|
||||
foreach ($params as $key => $value) {
|
||||
if ($value === '' || $value === null) {
|
||||
continue;
|
||||
}
|
||||
$clean[(string) $key] = (string) $value;
|
||||
}
|
||||
|
||||
$qs = http_build_query($clean);
|
||||
return $qs === '' ? '/orders/list' : '/orders/list?' . $qs;
|
||||
}
|
||||
|
||||
private function statusTone(string $statusCode): string
|
||||
{
|
||||
$code = strtolower(trim($statusCode));
|
||||
|
||||
@@ -111,8 +111,20 @@ final class OrdersRepository
|
||||
$params['source'] = $source;
|
||||
}
|
||||
|
||||
$statusGroup = trim((string) ($filters['status_group'] ?? ''));
|
||||
$status = trim((string) ($filters['status'] ?? ''));
|
||||
if ($status !== '') {
|
||||
if ($statusGroup !== '' && ctype_digit($statusGroup)) {
|
||||
$groupCodes = $this->statusCodesByGroupId((int) $statusGroup);
|
||||
if ($groupCodes !== []) {
|
||||
$placeholders = [];
|
||||
foreach ($groupCodes as $i => $code) {
|
||||
$key = 'sg' . $i;
|
||||
$placeholders[] = ':' . $key;
|
||||
$params[$key] = $code;
|
||||
}
|
||||
$where[] = $effectiveStatusSql . ' IN (' . implode(', ', $placeholders) . ')';
|
||||
}
|
||||
} elseif ($status !== '') {
|
||||
$where[] = $effectiveStatusSql . ' = :status';
|
||||
$params['status'] = $status;
|
||||
}
|
||||
@@ -398,6 +410,7 @@ final class OrdersRepository
|
||||
|
||||
if (!isset($groupMap[$groupId])) {
|
||||
$groupMap[$groupId] = [
|
||||
'id' => $groupId,
|
||||
'name' => trim((string) ($row['group_name'] ?? '')),
|
||||
'color_hex' => StringHelper::normalizeColorHex((string) ($row['group_color_hex'] ?? '#64748b')),
|
||||
'items' => [],
|
||||
@@ -418,6 +431,35 @@ final class OrdersRepository
|
||||
return array_values($groupMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<string>
|
||||
*/
|
||||
private function statusCodesByGroupId(int $groupId): array
|
||||
{
|
||||
try {
|
||||
$stmt = $this->pdo->prepare(
|
||||
'SELECT code FROM order_statuses WHERE group_id = :gid AND is_active = 1 ORDER BY sort_order ASC'
|
||||
);
|
||||
$stmt->execute(['gid' => $groupId]);
|
||||
$rows = $stmt->fetchAll(PDO::FETCH_COLUMN);
|
||||
} catch (Throwable) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (!is_array($rows)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$codes = [];
|
||||
foreach ($rows as $code) {
|
||||
$trimmed = strtolower(trim((string) $code));
|
||||
if ($trimmed !== '') {
|
||||
$codes[] = $trimmed;
|
||||
}
|
||||
}
|
||||
return $codes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>|null
|
||||
*/
|
||||
|
||||
@@ -49,6 +49,7 @@ final class AllegroIntegrationController
|
||||
private readonly AuthService $auth,
|
||||
private readonly AllegroIntegrationRepository $repository,
|
||||
private readonly AllegroStatusMappingRepository $statusMappings,
|
||||
private readonly AllegroPullStatusMappingRepository $pullStatusMappings,
|
||||
private readonly OrderStatusRepository $orderStatuses,
|
||||
private readonly CronRepository $cronRepository,
|
||||
private readonly AllegroOAuthClient $oauthClient,
|
||||
@@ -95,6 +96,7 @@ final class AllegroIntegrationController
|
||||
'statusSyncDirection' => $statusSyncDirection,
|
||||
'statusSyncIntervalMinutes' => $statusSyncIntervalMinutes,
|
||||
'statusMappings' => $this->statusMappings->listMappings(),
|
||||
'pullStatusMappings' => $this->pullStatusMappings->listAll(),
|
||||
'orderproStatuses' => $this->orderStatuses->listStatuses(),
|
||||
'allegroStatuses' => $this->statusMappings->listExternalStatuses(),
|
||||
'defaultRedirectUri' => $defaultRedirectUri,
|
||||
|
||||
@@ -8,6 +8,7 @@ use App\Modules\Orders\OrderImportRepository;
|
||||
use App\Modules\Orders\OrdersRepository;
|
||||
use App\Core\Constants\IntegrationSources;
|
||||
use App\Core\Exceptions\AllegroApiException;
|
||||
use App\Modules\Automation\AutomationService;
|
||||
use RuntimeException;
|
||||
use Throwable;
|
||||
|
||||
@@ -25,7 +26,9 @@ final class AllegroOrderImportService
|
||||
private readonly AllegroApiClient $apiClient,
|
||||
private readonly OrderImportRepository $orders,
|
||||
private readonly AllegroStatusMappingRepository $statusMappings,
|
||||
private readonly OrdersRepository $ordersRepository
|
||||
private readonly OrdersRepository $ordersRepository,
|
||||
private readonly ?AllegroPullStatusMappingRepository $pullStatusMappings = null,
|
||||
private readonly ?AutomationService $automationService = null
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -92,6 +95,14 @@ final class AllegroOrderImportService
|
||||
'Allegro'
|
||||
);
|
||||
}
|
||||
|
||||
if ($this->automationService !== null) {
|
||||
$this->automationService->trigger('order.imported', $savedOrderId, [
|
||||
'source' => IntegrationSources::ALLEGRO,
|
||||
'created' => $wasCreated,
|
||||
'integration_id' => (int) ($mapped['order']['integration_id'] ?? 0),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
@@ -135,7 +146,12 @@ final class AllegroOrderImportService
|
||||
$status = trim((string) ($payload['status'] ?? ''));
|
||||
$fulfillmentStatus = trim((string) ($payload['fulfillment']['status'] ?? ''));
|
||||
$rawAllegroStatus = strtolower($fulfillmentStatus !== '' ? $fulfillmentStatus : $status);
|
||||
$mappedOrderproStatus = $this->statusMappings->findMappedOrderproStatusCode($rawAllegroStatus);
|
||||
$mappedOrderproStatus = $this->pullStatusMappings !== null
|
||||
? $this->pullStatusMappings->findMappedStatusCode($rawAllegroStatus)
|
||||
: $this->statusMappings->findMappedOrderproStatusCode($rawAllegroStatus);
|
||||
if ($mappedOrderproStatus === null && $this->pullStatusMappings !== null) {
|
||||
$this->pullStatusMappings->upsertDiscoveredStatus($rawAllegroStatus);
|
||||
}
|
||||
$externalStatus = $mappedOrderproStatus !== null ? $mappedOrderproStatus : $rawAllegroStatus;
|
||||
$paymentStatusRaw = strtolower(trim((string) ($payload['payment']['status'] ?? '')));
|
||||
|
||||
|
||||
156
src/Modules/Settings/AllegroPullStatusMappingRepository.php
Normal file
156
src/Modules/Settings/AllegroPullStatusMappingRepository.php
Normal file
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Settings;
|
||||
|
||||
use App\Core\Support\StringHelper;
|
||||
use PDO;
|
||||
|
||||
final class AllegroPullStatusMappingRepository
|
||||
{
|
||||
public function __construct(private readonly PDO $pdo)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, array{allegro_status_code:string,allegro_status_name:string,orderpro_status_code:string}>
|
||||
*/
|
||||
public function listAll(): array
|
||||
{
|
||||
$statement = $this->pdo->query(
|
||||
'SELECT allegro_status_code, allegro_status_name, orderpro_status_code
|
||||
FROM allegro_order_status_pull_mappings
|
||||
ORDER BY allegro_status_code ASC'
|
||||
);
|
||||
$rows = $statement->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
if (!is_array($rows)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$result = [];
|
||||
foreach ($rows as $row) {
|
||||
if (!is_array($row)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$allegroCode = strtolower(trim((string) ($row['allegro_status_code'] ?? '')));
|
||||
if ($allegroCode === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$result[] = [
|
||||
'allegro_status_code' => $allegroCode,
|
||||
'allegro_status_name' => trim((string) ($row['allegro_status_name'] ?? '')),
|
||||
'orderpro_status_code' => strtolower(trim((string) ($row['orderpro_status_code'] ?? ''))),
|
||||
];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function findMappedStatusCode(string $allegroStatusCode): ?string
|
||||
{
|
||||
$code = strtolower(trim($allegroStatusCode));
|
||||
if ($code === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$statement = $this->pdo->prepare(
|
||||
'SELECT orderpro_status_code
|
||||
FROM allegro_order_status_pull_mappings
|
||||
WHERE allegro_status_code = :allegro_status_code
|
||||
AND orderpro_status_code IS NOT NULL
|
||||
AND orderpro_status_code <> ""
|
||||
LIMIT 1'
|
||||
);
|
||||
$statement->execute(['allegro_status_code' => $code]);
|
||||
$value = $statement->fetchColumn();
|
||||
if (!is_string($value)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$mapped = strtolower(trim($value));
|
||||
return $mapped !== '' ? $mapped : null;
|
||||
}
|
||||
|
||||
public function upsertDiscoveredStatus(string $allegroStatusCode, ?string $allegroStatusName = null): void
|
||||
{
|
||||
$code = strtolower(trim($allegroStatusCode));
|
||||
if ($code === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
$existing = $this->pdo->prepare(
|
||||
'SELECT id FROM allegro_order_status_pull_mappings
|
||||
WHERE allegro_status_code = :allegro_status_code
|
||||
LIMIT 1'
|
||||
);
|
||||
$existing->execute(['allegro_status_code' => $code]);
|
||||
|
||||
if ($existing->fetchColumn() !== false) {
|
||||
if ($allegroStatusName !== null && trim($allegroStatusName) !== '') {
|
||||
$update = $this->pdo->prepare(
|
||||
'UPDATE allegro_order_status_pull_mappings
|
||||
SET allegro_status_name = :allegro_status_name,
|
||||
updated_at = NOW()
|
||||
WHERE allegro_status_code = :allegro_status_code
|
||||
AND (allegro_status_name IS NULL OR allegro_status_name = "")'
|
||||
);
|
||||
$update->execute([
|
||||
'allegro_status_name' => trim($allegroStatusName),
|
||||
'allegro_status_code' => $code,
|
||||
]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
$insert = $this->pdo->prepare(
|
||||
'INSERT INTO allegro_order_status_pull_mappings (
|
||||
allegro_status_code, allegro_status_name, orderpro_status_code, created_at, updated_at
|
||||
) VALUES (
|
||||
:allegro_status_code, :allegro_status_name, NULL, NOW(), NOW()
|
||||
)'
|
||||
);
|
||||
$insert->execute([
|
||||
'allegro_status_code' => $code,
|
||||
'allegro_status_name' => StringHelper::nullableString((string) $allegroStatusName),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, array{allegro_status_code:string,allegro_status_name:string,orderpro_status_code:string}> $mappings
|
||||
*/
|
||||
public function replaceAll(array $mappings): void
|
||||
{
|
||||
$this->pdo->exec('DELETE FROM allegro_order_status_pull_mappings');
|
||||
|
||||
if ($mappings === []) {
|
||||
return;
|
||||
}
|
||||
|
||||
$insertStatement = $this->pdo->prepare(
|
||||
'INSERT INTO allegro_order_status_pull_mappings (
|
||||
allegro_status_code, allegro_status_name, orderpro_status_code, created_at, updated_at
|
||||
) VALUES (
|
||||
:allegro_status_code, :allegro_status_name, :orderpro_status_code, NOW(), NOW()
|
||||
)'
|
||||
);
|
||||
|
||||
foreach ($mappings as $mapping) {
|
||||
$allegroCode = strtolower(trim((string) ($mapping['allegro_status_code'] ?? '')));
|
||||
if ($allegroCode === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$orderpro = strtolower(trim((string) ($mapping['orderpro_status_code'] ?? '')));
|
||||
$allegroName = trim((string) ($mapping['allegro_status_name'] ?? ''));
|
||||
|
||||
$insertStatement->execute([
|
||||
'allegro_status_code' => $allegroCode,
|
||||
'allegro_status_name' => $allegroName !== '' ? $allegroName : null,
|
||||
'orderpro_status_code' => $orderpro !== '' ? $orderpro : null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,8 @@ final class AllegroStatusDiscoveryService
|
||||
public function __construct(
|
||||
private readonly AllegroTokenManager $tokenManager,
|
||||
private readonly AllegroApiClient $apiClient,
|
||||
private readonly AllegroStatusMappingRepository $statusMappings
|
||||
private readonly AllegroStatusMappingRepository $statusMappings,
|
||||
private readonly ?AllegroPullStatusMappingRepository $pullStatusMappings = null
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -64,6 +65,9 @@ final class AllegroStatusDiscoveryService
|
||||
|
||||
foreach ($unique as $code => $name) {
|
||||
$this->statusMappings->upsertDiscoveredStatus((string) $code, (string) $name);
|
||||
if ($this->pullStatusMappings !== null) {
|
||||
$this->pullStatusMappings->upsertDiscoveredStatus((string) $code, (string) $name);
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
|
||||
@@ -17,7 +17,8 @@ final class AllegroStatusMappingController
|
||||
private readonly Translator $translator,
|
||||
private readonly AllegroStatusMappingRepository $statusMappings,
|
||||
private readonly OrderStatusRepository $orderStatuses,
|
||||
private readonly AllegroStatusDiscoveryService $statusDiscoveryService
|
||||
private readonly AllegroStatusDiscoveryService $statusDiscoveryService,
|
||||
private readonly ?AllegroPullStatusMappingRepository $pullStatusMappings = null
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -97,6 +98,53 @@ final class AllegroStatusMappingController
|
||||
return Response::redirect(RedirectPaths::ALLEGRO_STATUSES_TAB);
|
||||
}
|
||||
|
||||
public function savePullStatusMappings(Request $request): Response
|
||||
{
|
||||
$csrfError = $this->validateCsrf((string) $request->input('_token', ''));
|
||||
if ($csrfError !== null) {
|
||||
return $csrfError;
|
||||
}
|
||||
|
||||
if ($this->pullStatusMappings === null) {
|
||||
Flash::set('settings_error', $this->translator->get('settings.allegro.statuses.flash.save_failed'));
|
||||
return Response::redirect(RedirectPaths::ALLEGRO_STATUSES_TAB);
|
||||
}
|
||||
|
||||
$allegroCodes = $request->input('allegro_status_code', []);
|
||||
$allegroNames = $request->input('allegro_status_name', []);
|
||||
$orderproCodes = $request->input('orderpro_status_code', []);
|
||||
if (!is_array($allegroCodes) || !is_array($allegroNames) || !is_array($orderproCodes)) {
|
||||
Flash::set('settings_error', $this->translator->get('settings.allegro.statuses.flash.save_failed'));
|
||||
return Response::redirect(RedirectPaths::ALLEGRO_STATUSES_TAB);
|
||||
}
|
||||
|
||||
$mappings = [];
|
||||
foreach ($allegroCodes as $index => $rawAllegroCode) {
|
||||
$allegroCode = strtolower(trim((string) $rawAllegroCode));
|
||||
if ($allegroCode === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$allegroName = trim((string) ($allegroNames[$index] ?? ''));
|
||||
$orderproCode = strtolower(trim((string) ($orderproCodes[$index] ?? '')));
|
||||
|
||||
$mappings[] = [
|
||||
'allegro_status_code' => $allegroCode,
|
||||
'allegro_status_name' => $allegroName,
|
||||
'orderpro_status_code' => $orderproCode,
|
||||
];
|
||||
}
|
||||
|
||||
try {
|
||||
$this->pullStatusMappings->replaceAll($mappings);
|
||||
Flash::set('settings_success', $this->translator->get('settings.allegro.statuses.flash.saved_pull'));
|
||||
} catch (Throwable $exception) {
|
||||
Flash::set('settings_error', $this->translator->get('settings.allegro.statuses.flash.save_failed') . ' ' . $exception->getMessage());
|
||||
}
|
||||
|
||||
return Response::redirect(RedirectPaths::ALLEGRO_STATUSES_TAB);
|
||||
}
|
||||
|
||||
public function syncStatusesFromAllegro(Request $request): Response
|
||||
{
|
||||
$csrfError = $this->validateCsrf((string) $request->input('_token', ''));
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
namespace App\Modules\Settings;
|
||||
|
||||
use App\Core\Support\StringHelper;
|
||||
use App\Modules\Automation\AutomationService;
|
||||
use App\Modules\Orders\OrderImportRepository;
|
||||
use App\Modules\Orders\OrdersRepository;
|
||||
use DateTimeImmutable;
|
||||
@@ -20,7 +21,8 @@ final class ShopproOrdersSyncService
|
||||
private readonly OrdersRepository $orders,
|
||||
private readonly ShopproOrderMapper $mapper,
|
||||
private readonly ShopproProductImageResolver $imageResolver,
|
||||
private readonly ?ShopproPullStatusMappingRepository $pullStatusMappings = null
|
||||
private readonly ?ShopproPullStatusMappingRepository $pullStatusMappings = null,
|
||||
private readonly ?AutomationService $automationService = null
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -267,6 +269,14 @@ final class ShopproOrdersSyncService
|
||||
'shopPRO'
|
||||
);
|
||||
}
|
||||
|
||||
if ($savedOrderId > 0 && !$wasPaymentTransition && $this->automationService !== null) {
|
||||
$this->automationService->trigger('order.imported', $savedOrderId, [
|
||||
'source' => 'shoppro',
|
||||
'created' => $wasCreated,
|
||||
'integration_id' => $integrationId,
|
||||
]);
|
||||
}
|
||||
} catch (Throwable $exception) {
|
||||
$result['failed'] = (int) $result['failed'] + 1;
|
||||
$errors = is_array($result['errors']) ? $result['errors'] : [];
|
||||
|
||||
Reference in New Issue
Block a user