Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d2277c6d9d | |||
| 908c997b91 | |||
| 9d3ae9a470 | |||
| 09d266204e | |||
| 8f43f5ab4d | |||
| b17463bcbc | |||
| 76de81bca4 | |||
| 842ed77f5b | |||
| 96ed86649a | |||
| fdc4cac593 | |||
| 8f67d9de0a |
@@ -48,7 +48,26 @@
|
||||
"Bash(python3:*)",
|
||||
"Bash(python:*)",
|
||||
"Bash(grep:*)",
|
||||
"Bash(grep ^<b>ver:*)"
|
||||
"Bash(grep ^<b>ver:*)",
|
||||
"Bash(claude mcp:*)",
|
||||
"mcp__serena__get_current_config",
|
||||
"Bash(cd \"C:\\\\visual studio code\\\\projekty\\\\shopPRO\" && npx sass admin/layout/style-scss/style.scss admin/layout/style-css/style.css --no-source-map 2>&1 || sass admin/layout/style-scss/style.scss admin/layout/style-css/style.css --no-source-map 2>&1)",
|
||||
"Bash(echo no 7z:*)",
|
||||
"Bash(cd \"C:/visual studio code/projekty/shopPRO\" && php -r \"\n\\\\$files = [\n 'admin/templates/integrations/logs.php',\n 'admin/templates/site/main-layout.php',\n 'autoload/Domain/Integrations/IntegrationsRepository.php',\n 'autoload/admin/Controllers/IntegrationsController.php',\n];\n\\\\$zipPath = 'updates/0.30/ver_0.310.zip';\nif \\(!is_dir\\('updates/0.30'\\)\\) mkdir\\('updates/0.30', 0777, true\\);\nif \\(file_exists\\(\\\\$zipPath\\)\\) unlink\\(\\\\$zipPath\\);\n\\\\$zip = new ZipArchive\\(\\);\nif \\(\\\\$zip->open\\(\\\\$zipPath, ZipArchive::CREATE\\) !== true\\) { echo 'Cannot create ZIP'; exit\\(1\\); }\nforeach \\(\\\\$files as \\\\$f\\) {\n if \\(file_exists\\(\\\\$f\\)\\) {\n \\\\$zip->addFile\\(\\\\$f, \\\\$f\\);\n echo \\\\\"Added: \\\\$f\\\\n\\\\\";\n } else {\n echo \\\\\"MISSING: \\\\$f\\\\n\\\\\";\n }\n}\n\\\\$zip->close\\(\\);\necho \\\\\"ZIP created: \\\\$zipPath \\(\\\\\".filesize\\(\\\\$zipPath\\).\\\\\" bytes\\)\\\\n\\\\\";\n\" 2>&1)",
|
||||
"Bash(where jar:*)",
|
||||
"Bash(echo php not found:*)",
|
||||
"Bash(/c/xampp/php/php:*)",
|
||||
"Bash(curl:*)",
|
||||
"Bash(cat:*)",
|
||||
"Bash(rm -rf \"/c/visual studio code/projekty/shopPRO/temp/temp_313\" && cd \"/c/visual studio code/projekty/shopPRO\" && powershell -File ./build-update.ps1 -FromTag v0.312 -ToTag v0.313 -ChangelogEntry \"FIX - sync płatności Apilo \\(int cast na apilo_order_id PPxxxxxx dawał 0\\) + logowanie decyzji sync do pp_log\" 2>&1)",
|
||||
"Bash(which php:*)",
|
||||
"mcp__serena__replace_symbol_body",
|
||||
"mcp__serena__insert_after_symbol",
|
||||
"Bash(php:*)",
|
||||
"Bash(rm -rf \"C:/visual studio code/projekty/shopPRO/temp/temp_314\" && cd \"C:/visual studio code/projekty/shopPRO\" && powershell -ExecutionPolicy Bypass -File build-update.ps1 -FromTag v0.313 -ToTag v0.314 -ChangelogEntry \"FIX - naprawa globalnej wyszukiwarki admin \\(Content-Type, Cache-Control, POST, try/catch\\), NEW - title strony z numerem zamówienia\" 2>&1)",
|
||||
"mcp__serena__initial_instructions",
|
||||
"mcp__serena__list_memories",
|
||||
"mcp__serena__find_referencing_symbols"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -27,6 +27,7 @@ project_name: "shopPRO"
|
||||
# Note that when using the JetBrains backend, language servers are not used and this list is correspondingly ignored.
|
||||
languages:
|
||||
- typescript
|
||||
- php
|
||||
|
||||
# the encoding used by text files in the project
|
||||
# For a list of possible encodings, see https://docs.python.org/3.11/library/codecs.html#standard-encodings
|
||||
|
||||
6
.vscode/ftp-kr.json
vendored
6
.vscode/ftp-kr.json
vendored
@@ -14,6 +14,10 @@
|
||||
".git",
|
||||
".svn",
|
||||
"/.vscode",
|
||||
"/temp/*"
|
||||
"/temp",
|
||||
"/.serena",
|
||||
"/.claude",
|
||||
"/docs",
|
||||
"/tests"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ $isCompactColumn = function(array $column): bool {
|
||||
|
||||
<div class="col-sm-12">
|
||||
<button type="submit" class="btn btn-primary btn-sm">Szukaj</button>
|
||||
<a href="<?= htmlspecialchars($list->basePath, ENT_QUOTES, 'UTF-8'); ?>" class="btn btn-default btn-sm">Wyczyść</a>
|
||||
<a href="<?= htmlspecialchars($list->basePath, ENT_QUOTES, 'UTF-8'); ?>" class="btn btn-default btn-sm js-table-filters-clear">Wyczyść</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
@@ -312,6 +312,40 @@ $isCompactColumn = function(array $column): bool {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
// Table state persistence — redirect ASAP to saved view
|
||||
(function() {
|
||||
var basePath = <?= json_encode($list->basePath); ?>;
|
||||
var stateKey = 'tableListQuery_' + basePath;
|
||||
var clearKey = 'tableListCleared_' + basePath;
|
||||
|
||||
var pathname = window.location.pathname.replace(/\/+$/, '/');
|
||||
var bp = basePath.replace(/\/+$/, '/');
|
||||
|
||||
var queryPart = '';
|
||||
if (pathname.length > bp.length && pathname.indexOf(bp) === 0) {
|
||||
queryPart = pathname.substring(bp.length);
|
||||
}
|
||||
if (!queryPart && window.location.search) {
|
||||
queryPart = window.location.search.substring(1);
|
||||
}
|
||||
|
||||
try {
|
||||
var justCleared = sessionStorage.getItem(clearKey) === '1';
|
||||
sessionStorage.removeItem(clearKey);
|
||||
|
||||
if (queryPart) {
|
||||
localStorage.setItem(stateKey, queryPart);
|
||||
} else if (!justCleared) {
|
||||
var saved = localStorage.getItem(stateKey);
|
||||
if (saved) {
|
||||
window.location.replace(basePath + saved);
|
||||
}
|
||||
}
|
||||
} catch (e) {}
|
||||
})();
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
(function($) {
|
||||
if (!$) {
|
||||
@@ -550,5 +584,17 @@ $isCompactColumn = function(array $column): bool {
|
||||
$(document).on('change.tablePerPage', '.js-per-page-select', function() {
|
||||
$(this).closest('form').trigger('submit');
|
||||
});
|
||||
|
||||
// --- Table state clear on "Wyczyść" ---
|
||||
var stateStorageKey = 'tableListQuery_' + <?= json_encode($list->basePath); ?>;
|
||||
var stateClearKey = 'tableListCleared_' + <?= json_encode($list->basePath); ?>;
|
||||
|
||||
$(document).off('click.tableClearState', '.js-table-filters-clear');
|
||||
$(document).on('click.tableClearState', '.js-table-filters-clear', function() {
|
||||
try {
|
||||
localStorage.removeItem(stateStorageKey);
|
||||
sessionStorage.setItem(stateClearKey, '1');
|
||||
} catch (e) {}
|
||||
});
|
||||
})(window.jQuery);
|
||||
</script>
|
||||
|
||||
@@ -3,6 +3,7 @@ $orderId = (int)($this -> order['id'] ?? 0);
|
||||
?>
|
||||
|
||||
<div class="site-title">Szczegóły zamówienia: <?= htmlspecialchars((string)($this -> order['number'] ?? ''), ENT_QUOTES, 'UTF-8');?></div>
|
||||
<script>document.title = 'Zamówienie <?= htmlspecialchars((string)($this -> order['number'] ?? ''), ENT_QUOTES, 'UTF-8');?> - shopPro';</script>
|
||||
|
||||
<div class="od-actions mb15">
|
||||
<a href="/admin/shop_order/list/" class="btn btn-dark btn-sm">
|
||||
@@ -89,6 +90,19 @@ $orderId = (int)($this -> order['id'] ?? 0);
|
||||
<div>
|
||||
<b><?= $this -> order[ 'payment_method' ];?> </b>
|
||||
</div>
|
||||
<? if ( !empty($this -> order['apilo_order_id']) ):?>
|
||||
<br/>
|
||||
<div>
|
||||
<i class="fa fa-cloud"></i> Apilo: <b style="color: #27ae60;">tak</b>
|
||||
— ID: <b id="order-apilo-id"><?= htmlspecialchars((string)$this -> order['apilo_order_id'], ENT_QUOTES, 'UTF-8');?></b>
|
||||
<i class="fa fa-copy" onclick="copyToClipboard( 'order-apilo-id' ); return false;"></i>
|
||||
</div>
|
||||
<? else:?>
|
||||
<br/>
|
||||
<div>
|
||||
<i class="fa fa-cloud"></i> Apilo: <b style="color: #c0392b;">nie</b>
|
||||
</div>
|
||||
<? endif;?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="paid-status panel">
|
||||
@@ -184,13 +198,14 @@ $orderId = (int)($this -> order['id'] ?? 0);
|
||||
<?= $product[ 'message' ] != '' ? '<strong>Wiadomość:</strong> ' . $product['message'] : '';?>
|
||||
</div>
|
||||
<div class="od-mobile-price-line">
|
||||
<?= (int)$product['quantity'];?> × <?= \Shared\Helpers\Helpers::decimal( $product['price_brutto_promo'] );?> = <?= \Shared\Helpers\Helpers::decimal( $product['price_brutto_promo'] * $product['quantity'] );?> zł
|
||||
<? $effective = ((float)$product['price_brutto_promo'] > 0 && (float)$product['price_brutto_promo'] < (float)$product['price_brutto']) ? (float)$product['price_brutto_promo'] : (float)$product['price_brutto'];?>
|
||||
<?= (int)$product['quantity'];?> × <?= \Shared\Helpers\Helpers::decimal( $effective );?> = <?= \Shared\Helpers\Helpers::decimal( $effective * $product['quantity'] );?> zł
|
||||
</div>
|
||||
</td>
|
||||
<td class="tab-center"><?= $product[ 'quantity' ];?></td>
|
||||
<td class="tab-right"><?= \Shared\Helpers\Helpers::decimal( $product[ 'price_brutto' ] );?> zł</td>
|
||||
<td class="tab-right"><?= \Shared\Helpers\Helpers::decimal( $product[ 'price_brutto_promo' ] );?> zł</td>
|
||||
<td class="tab-right"><?= \Shared\Helpers\Helpers::decimal( $product[ 'price_brutto_promo' ] * $product[ 'quantity' ] );?> zł</td>
|
||||
<td class="tab-right"><?= \Shared\Helpers\Helpers::decimal( $effective );?> zł</td>
|
||||
<td class="tab-right"><?= \Shared\Helpers\Helpers::decimal( $effective * $product[ 'quantity' ] );?> zł</td>
|
||||
</tr>
|
||||
<? endforeach; endif;?>
|
||||
</tbody>
|
||||
|
||||
@@ -322,7 +322,7 @@
|
||||
|
||||
$.ajax({
|
||||
url: '/admin/settings/globalSearchAjax/',
|
||||
type: 'GET',
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
data: { q: phrase },
|
||||
success: function(response) {
|
||||
@@ -333,8 +333,12 @@
|
||||
|
||||
renderResults(response.items || []);
|
||||
},
|
||||
error: function() {
|
||||
$results.html('<div class="admin-global-search-empty">Błąd połączenia</div>').addClass('open');
|
||||
error: function(xhr) {
|
||||
var msg = 'Błąd połączenia';
|
||||
if (xhr.status === 200) {
|
||||
msg = 'Błąd parsowania odpowiedzi';
|
||||
}
|
||||
$results.html('<div class="admin-global-search-empty">' + msg + '</div>').addClass('open');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ class AttributeRepository
|
||||
FROM pp_shop_attributes AS sa
|
||||
WHERE {$whereSql}
|
||||
";
|
||||
$stmtCount = $this->db->query($sqlCount, $params);
|
||||
$stmtCount = $this->db->query($sqlCount, $whereData['params']);
|
||||
$countRows = $stmtCount ? $stmtCount->fetchAll() : [];
|
||||
$total = isset($countRows[0][0]) ? (int)$countRows[0][0] : 0;
|
||||
|
||||
|
||||
@@ -393,17 +393,38 @@ class OrderAdminService
|
||||
global $mdb;
|
||||
|
||||
if ($orderId <= 0) {
|
||||
\Domain\Integrations\ApiloLogger::log(
|
||||
$mdb,
|
||||
'resend_order',
|
||||
$orderId,
|
||||
'Nieprawidlowe ID zamowienia (orderId <= 0)',
|
||||
['order_id' => $orderId]
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
$order = $this->orders->findForAdmin($orderId);
|
||||
if (empty($order) || empty($order['apilo_order_id'])) {
|
||||
\Domain\Integrations\ApiloLogger::log(
|
||||
$mdb,
|
||||
'resend_order',
|
||||
$orderId,
|
||||
'Brak zamowienia lub brak apilo_order_id',
|
||||
['order_found' => !empty($order), 'apilo_order_id' => $order['apilo_order_id'] ?? null]
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
$integrationsRepository = new \Domain\Integrations\IntegrationsRepository( $mdb );
|
||||
$accessToken = $integrationsRepository -> apiloGetAccessToken();
|
||||
if (!$accessToken) {
|
||||
\Domain\Integrations\ApiloLogger::log(
|
||||
$mdb,
|
||||
'resend_order',
|
||||
$orderId,
|
||||
'Nie udalo sie uzyskac tokenu Apilo (access token)',
|
||||
['apilo_order_id' => $order['apilo_order_id']]
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -533,9 +554,26 @@ class OrderAdminService
|
||||
|
||||
$error = '';
|
||||
$sync_failed = false;
|
||||
$max_attempts = 50; // ~8h przy cronie co 10 min
|
||||
|
||||
// Zamówienie jeszcze nie wysłane do Apilo — czekaj na crona
|
||||
if (!(int)$order['apilo_order_id']) {
|
||||
$attempts = (int)($task['attempts'] ?? 0) + 1;
|
||||
if ($attempts >= $max_attempts) {
|
||||
// Przekroczono limit prób — porzuć task
|
||||
unset($queue[$key]);
|
||||
} else {
|
||||
$task['attempts'] = $attempts;
|
||||
$task['last_error'] = 'awaiting_apilo_order';
|
||||
$task['updated_at'] = date('Y-m-d H:i:s');
|
||||
$queue[$key] = $task;
|
||||
}
|
||||
$processed++;
|
||||
continue;
|
||||
}
|
||||
|
||||
$payment_pending = !empty($task['payment']) && (int)$order['paid'] === 1;
|
||||
if ($payment_pending && (int)$order['apilo_order_id']) {
|
||||
if ($payment_pending) {
|
||||
if (!$this->syncApiloPayment($order)) {
|
||||
$sync_failed = true;
|
||||
$error = 'payment_sync_failed';
|
||||
@@ -543,7 +581,7 @@ class OrderAdminService
|
||||
}
|
||||
|
||||
$status_pending = isset($task['status']) && $task['status'] !== null && $task['status'] !== '';
|
||||
if (!$sync_failed && $status_pending && (int)$order['apilo_order_id']) {
|
||||
if (!$sync_failed && $status_pending) {
|
||||
if (!$this->syncApiloStatus($order, (int)$task['status'])) {
|
||||
$sync_failed = true;
|
||||
$error = 'status_sync_failed';
|
||||
@@ -624,6 +662,17 @@ class OrderAdminService
|
||||
$apilo_settings = $integrationsRepository->getSettings('apilo');
|
||||
|
||||
if (!$apilo_settings['enabled'] || !$apilo_settings['access-token'] || !$apilo_settings['sync_orders']) {
|
||||
\Domain\Integrations\ApiloLogger::log(
|
||||
$db,
|
||||
'payment_sync',
|
||||
(int)$order['id'],
|
||||
'Pominięto sync płatności — Apilo wyłączone lub brak tokenu/sync_orders',
|
||||
[
|
||||
'enabled' => $apilo_settings['enabled'] ?? false,
|
||||
'has_token' => !empty($apilo_settings['access-token']),
|
||||
'sync_orders' => $apilo_settings['sync_orders'] ?? false,
|
||||
]
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -631,7 +680,24 @@ class OrderAdminService
|
||||
self::appendApiloLog("SET AS PAID\n" . print_r($order, true));
|
||||
}
|
||||
|
||||
if ($order['apilo_order_id'] && !$this->syncApiloPayment($order)) {
|
||||
if (!$order['apilo_order_id']) {
|
||||
// Zamówienie jeszcze nie wysłane do Apilo — kolejkuj sync płatności na później
|
||||
\Domain\Integrations\ApiloLogger::log(
|
||||
$db,
|
||||
'payment_sync',
|
||||
(int)$order['id'],
|
||||
'Brak apilo_order_id — płatność zakolejkowana do sync',
|
||||
['apilo_order_id' => $order['apilo_order_id'] ?? null]
|
||||
);
|
||||
self::queueApiloSync((int)$order['id'], true, null, 'awaiting_apilo_order');
|
||||
} elseif (!$this->syncApiloPayment($order)) {
|
||||
\Domain\Integrations\ApiloLogger::log(
|
||||
$db,
|
||||
'payment_sync',
|
||||
(int)$order['id'],
|
||||
'Sync płatności nieudany — zakolejkowano ponowną próbę',
|
||||
['apilo_order_id' => $order['apilo_order_id']]
|
||||
);
|
||||
self::queueApiloSync((int)$order['id'], true, null, 'payment_sync_failed');
|
||||
}
|
||||
}
|
||||
@@ -645,6 +711,18 @@ class OrderAdminService
|
||||
$apilo_settings = $integrationsRepository->getSettings('apilo');
|
||||
|
||||
if (!$apilo_settings['enabled'] || !$apilo_settings['access-token'] || !$apilo_settings['sync_orders']) {
|
||||
\Domain\Integrations\ApiloLogger::log(
|
||||
$db,
|
||||
'status_sync',
|
||||
(int)$order['id'],
|
||||
'Pominięto sync statusu — Apilo wyłączone lub brak tokenu/sync_orders',
|
||||
[
|
||||
'target_status' => $status,
|
||||
'enabled' => $apilo_settings['enabled'] ?? false,
|
||||
'has_token' => !empty($apilo_settings['access-token']),
|
||||
'sync_orders' => $apilo_settings['sync_orders'] ?? false,
|
||||
]
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -652,7 +730,24 @@ class OrderAdminService
|
||||
self::appendApiloLog("UPDATE STATUS\n" . print_r($order, true));
|
||||
}
|
||||
|
||||
if ($order['apilo_order_id'] && !$this->syncApiloStatus($order, $status)) {
|
||||
if (!$order['apilo_order_id']) {
|
||||
// Zamówienie jeszcze nie wysłane do Apilo — kolejkuj sync statusu na później
|
||||
\Domain\Integrations\ApiloLogger::log(
|
||||
$db,
|
||||
'status_sync',
|
||||
(int)$order['id'],
|
||||
'Brak apilo_order_id — status zakolejkowany do sync',
|
||||
['apilo_order_id' => $order['apilo_order_id'] ?? null, 'target_status' => $status]
|
||||
);
|
||||
self::queueApiloSync((int)$order['id'], false, $status, 'awaiting_apilo_order');
|
||||
} elseif (!$this->syncApiloStatus($order, $status)) {
|
||||
\Domain\Integrations\ApiloLogger::log(
|
||||
$db,
|
||||
'status_sync',
|
||||
(int)$order['id'],
|
||||
'Sync statusu nieudany — zakolejkowano ponowną próbę',
|
||||
['apilo_order_id' => $order['apilo_order_id'], 'target_status' => $status]
|
||||
);
|
||||
self::queueApiloSync((int)$order['id'], false, $status, 'status_sync_failed');
|
||||
}
|
||||
}
|
||||
@@ -664,7 +759,7 @@ class OrderAdminService
|
||||
$db = $this->orders->getDb();
|
||||
$integrationsRepository = new \Domain\Integrations\IntegrationsRepository($db);
|
||||
|
||||
if (!(int)$order['apilo_order_id']) {
|
||||
if (empty($order['apilo_order_id'])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -731,7 +826,7 @@ class OrderAdminService
|
||||
$db = $this->orders->getDb();
|
||||
$integrationsRepository = new \Domain\Integrations\IntegrationsRepository($db);
|
||||
|
||||
if (!(int)$order['apilo_order_id']) {
|
||||
if (empty($order['apilo_order_id'])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -73,26 +73,45 @@ class SettingsController
|
||||
*/
|
||||
public function globalSearchAjax(): void
|
||||
{
|
||||
global $mdb;
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
header('Cache-Control: no-store');
|
||||
|
||||
$phrase = trim((string)\Shared\Helpers\Helpers::get('q'));
|
||||
if ($phrase === '' || mb_strlen($phrase) < 2) {
|
||||
try {
|
||||
$this->executeGlobalSearch();
|
||||
} catch (\Throwable $e) {
|
||||
echo json_encode([
|
||||
'status' => 'ok',
|
||||
'status' => 'error',
|
||||
'items' => [],
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
private function executeGlobalSearch(): void
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$phrase = isset($_REQUEST['q']) ? trim((string)$_REQUEST['q']) : '';
|
||||
if ($phrase === '' || mb_strlen($phrase) < 2) {
|
||||
echo json_encode(['status' => 'ok', 'items' => []]);
|
||||
return;
|
||||
}
|
||||
|
||||
$phrase = mb_substr($phrase, 0, 120);
|
||||
$phraseNormalized = preg_replace('/\s+/', ' ', $phrase);
|
||||
$phraseNormalized = trim((string)$phraseNormalized);
|
||||
$phraseNormalized = trim((string)preg_replace('/\s+/', ' ', $phrase));
|
||||
$like = '%' . $phrase . '%';
|
||||
$likeNormalized = '%' . $phraseNormalized . '%';
|
||||
|
||||
$items = [];
|
||||
$defaultLang = (string)$this->languagesRepository->defaultLanguage();
|
||||
|
||||
$defaultLang = '1';
|
||||
try {
|
||||
$defaultLang = (string)$this->languagesRepository->defaultLanguage();
|
||||
} catch (\Throwable $e) {
|
||||
// fallback to '1'
|
||||
}
|
||||
|
||||
// --- Produkty ---
|
||||
try {
|
||||
$productStmt = $mdb->query(
|
||||
'SELECT '
|
||||
@@ -115,7 +134,10 @@ class SettingsController
|
||||
$productStmt = false;
|
||||
}
|
||||
|
||||
$productRows = $productStmt ? $productStmt->fetchAll() : [];
|
||||
$productRows = ($productStmt && method_exists($productStmt, 'fetchAll'))
|
||||
? $productStmt->fetchAll(\PDO::FETCH_ASSOC)
|
||||
: [];
|
||||
|
||||
if (is_array($productRows)) {
|
||||
foreach ($productRows as $row) {
|
||||
$productId = (int)($row['id'] ?? 0);
|
||||
@@ -147,6 +169,7 @@ class SettingsController
|
||||
}
|
||||
}
|
||||
|
||||
// --- Zamowienia ---
|
||||
try {
|
||||
$orderStmt = $mdb->query(
|
||||
'SELECT '
|
||||
@@ -178,7 +201,10 @@ class SettingsController
|
||||
$orderStmt = false;
|
||||
}
|
||||
|
||||
$orderRows = $orderStmt ? $orderStmt->fetchAll() : [];
|
||||
$orderRows = ($orderStmt && method_exists($orderStmt, 'fetchAll'))
|
||||
? $orderStmt->fetchAll(\PDO::FETCH_ASSOC)
|
||||
: [];
|
||||
|
||||
if (is_array($orderRows)) {
|
||||
foreach ($orderRows as $row) {
|
||||
$orderId = (int)($row['id'] ?? 0);
|
||||
@@ -214,11 +240,12 @@ class SettingsController
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
'status' => 'ok',
|
||||
'items' => array_slice($items, 0, 20),
|
||||
]);
|
||||
exit;
|
||||
$json = json_encode(['status' => 'ok', 'items' => array_slice($items, 0, 20)]);
|
||||
if ($json === false) {
|
||||
echo json_encode(['status' => 'ok', 'items' => []], JSON_UNESCAPED_UNICODE);
|
||||
return;
|
||||
}
|
||||
echo $json;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
$database['host'] = 'localhost';
|
||||
$database['remote_host'] = 'host700513.hostido.net.pl';
|
||||
$database['remote_host'] = 'host117523.hostido.net.pl';
|
||||
$database['user'] = 'host117523_shoppro';
|
||||
$database['password'] = 'mhA9WCEXEnRfTtbN33hL';
|
||||
$database['name'] = 'host117523_shoppro';
|
||||
@@ -13,7 +13,7 @@ $config['redis']['host'] = '127.0.0.1';
|
||||
$config['redis']['port'] = 20470;
|
||||
$config['redis']['password'] = 'Gi7FzWtkry19hZ1BqT1LKEWfwokQpigh';
|
||||
|
||||
$config['debug']['apilo'] = false;
|
||||
$config['debug']['apilo'] = true;
|
||||
|
||||
$config['trustmate']['enabled'] = true;
|
||||
$config['trustmate']['uid'] = '34eb36ba-c715-4cdc-8707-22376c9f14c7';
|
||||
|
||||
43
cron.php
43
cron.php
@@ -201,6 +201,7 @@ if ( $apilo_settings['enabled'] and $apilo_settings['sync_orders'] and $apilo_se
|
||||
{
|
||||
$products = $mdb -> select( 'pp_shop_order_products', '*', [ 'order_id' => $order['id'] ] );
|
||||
$products_array = [];
|
||||
$order_message = '';
|
||||
foreach ( $products as $product )
|
||||
{
|
||||
$productRepo = new \Domain\Product\ProductRepository( $mdb );
|
||||
@@ -211,8 +212,8 @@ if ( $apilo_settings['enabled'] and $apilo_settings['sync_orders'] and $apilo_se
|
||||
'ean' => $productRepo->getEanWithFallback( (int)$product['product_id'], true ),
|
||||
'sku' => $sku ? $sku : md5( $product['product_id'] ),
|
||||
'originalName' => $product['name'],
|
||||
'originalPriceWithTax' => $product['price_brutto_promo'] ? str_replace( ',', '.', $product['price_brutto_promo'] ) : str_replace( ',', '.', $product['price_brutto'] ),
|
||||
'originalPriceWithoutTax' => $product['price_brutto_promo'] ? str_replace( ',', '.', round( $product['price_brutto_promo'] / ( 1 + $product['vat']/100 ), 2 ) ) : str_replace( ',', '.', round( $product['price_brutto'] / ( 1 + $product['vat']/100 ), 2 ) ),
|
||||
'originalPriceWithTax' => (float)$product['price_brutto_promo'] > 0 ? str_replace( ',', '.', $product['price_brutto_promo'] ) : str_replace( ',', '.', $product['price_brutto'] ),
|
||||
'originalPriceWithoutTax' => (float)$product['price_brutto_promo'] > 0 ? str_replace( ',', '.', round( $product['price_brutto_promo'] / ( 1 + $product['vat']/100 ), 2 ) ) : str_replace( ',', '.', round( $product['price_brutto'] / ( 1 + $product['vat']/100 ), 2 ) ),
|
||||
'quantity' => $product['quantity'],
|
||||
'tax' => number_format( $product['vat'], 2, '.', '' ),
|
||||
'status' => 1,
|
||||
@@ -255,6 +256,25 @@ if ( $apilo_settings['enabled'] and $apilo_settings['sync_orders'] and $apilo_se
|
||||
'media' => null
|
||||
];
|
||||
|
||||
// Walidacja: sprawdź czy zamówienie ma produkty z cenami > 0
|
||||
$has_priced_products = false;
|
||||
foreach ( $products_array as $pa )
|
||||
{
|
||||
if ( $pa['type'] == 1 && (float)$pa['originalPriceWithTax'] > 0 )
|
||||
{
|
||||
$has_priced_products = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( !$has_priced_products )
|
||||
{
|
||||
\Domain\Integrations\ApiloLogger::log( $mdb, 'send_order', (int)$order['id'], 'Pominięto zamówienie - wszystkie produkty mają cenę 0.00', [ 'products' => $products_array ] );
|
||||
\Shared\Helpers\Helpers::send_email( 'biuro@project-pro.pl', 'Apilo: zamówienie #' . $order['id'] . ' ma zerowe ceny produktów', 'Zamówienie #' . $order['id'] . ' nie zostało wysłane do Apilo, ponieważ wszystkie produkty mają cenę 0.00 PLN. Sprawdź zamówienie w panelu sklepu.' );
|
||||
$mdb -> update( 'pp_shop_orders', [ 'apilo_order_id' => -2 ], [ 'id' => $order['id'] ] );
|
||||
echo '<p>Pominięto zamówienie #' . $order['id'] . ' - zerowe ceny produktów</p>';
|
||||
continue;
|
||||
}
|
||||
|
||||
$access_token = $integrationsRepository -> apiloGetAccessToken();
|
||||
|
||||
$order_date = new DateTime( $order['date_order'] );
|
||||
@@ -410,9 +430,9 @@ if ( $apilo_settings['enabled'] and $apilo_settings['sync_orders'] and $apilo_se
|
||||
\Domain\Integrations\ApiloLogger::log( $mdb, 'send_order', (int)$order['id'], 'Błąd cURL przy wysyłaniu zamówienia: ' . $curl_error_send, [ 'curl_error' => $curl_error_send ] );
|
||||
echo 'Błąd cURL: ' . $curl_error_send;
|
||||
}
|
||||
$http_code_send = (int)curl_getinfo( $ch, CURLINFO_HTTP_CODE );
|
||||
curl_close( $ch );
|
||||
|
||||
$http_code_send = (int)curl_getinfo( $ch, CURLINFO_HTTP_CODE );
|
||||
$response = json_decode( $response, true );
|
||||
|
||||
if ( $config['debug']['apilo'] )
|
||||
@@ -497,6 +517,20 @@ if ( $apilo_settings['enabled'] and $apilo_settings['sync_orders'] and $apilo_se
|
||||
\Shared\Helpers\Helpers::send_email( 'biuro@project-pro.pl', 'Błąd wysyłania zamówienia do apilo.com', $email_data );
|
||||
}
|
||||
}
|
||||
elseif ( $http_code_send >= 400 || !isset( $response['id'] ) )
|
||||
{
|
||||
// Błąd serwera lub brak ID w odpowiedzi — logujemy i pomijamy, NIE ustawiamy apilo_order_id
|
||||
// żeby zamówienie nie wpadło w nieskończoną pętlę, ustawiamy apilo_order_id na -1 (błąd)
|
||||
$mdb -> update( 'pp_shop_orders', [ 'apilo_order_id' => -1 ], [ 'id' => $order['id'] ] );
|
||||
\Domain\Integrations\ApiloLogger::log( $mdb, 'send_order', (int)$order['id'], 'Błąd wysyłania zamówienia do Apilo (HTTP ' . $http_code_send . ')', [ 'http_code' => $http_code_send, 'response' => $response ] );
|
||||
|
||||
$email_data = 'HTTP Code: ' . $http_code_send . "\n\n";
|
||||
$email_data .= print_r( $response, true );
|
||||
$email_data .= print_r( $postData, true );
|
||||
\Shared\Helpers\Helpers::send_email( 'biuro@project-pro.pl', 'Błąd wysyłania zamówienia #' . $order['id'] . ' do apilo.com (HTTP ' . $http_code_send . ')', $email_data );
|
||||
|
||||
echo '<p>Błąd wysyłania zamówienia do apilo.com: ID: ' . $order['id'] . ' (HTTP ' . $http_code_send . ')</p>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$mdb -> update( 'pp_shop_orders', [ 'apilo_order_id' => $response['id'] ], [ 'id' => $order['id'] ] );
|
||||
@@ -504,6 +538,9 @@ if ( $apilo_settings['enabled'] and $apilo_settings['sync_orders'] and $apilo_se
|
||||
echo '<p>Wysłałem zamówienie do apilo.com: ID: ' . $order['id'] . ' - ' . $response['id'] . '</p>';
|
||||
}
|
||||
}
|
||||
|
||||
// Po wysłaniu zamówień: przetwórz kolejkę sync (płatności/statusy oczekujące na apilo_order_id)
|
||||
$orderAdminService->processApiloSyncQueue( 10 );
|
||||
}
|
||||
|
||||
// sprawdzanie statusów zamówień w apilo.com jeżeli zamówienie nie jest zrealizowane, anulowane lub nieodebrane
|
||||
|
||||
@@ -4,6 +4,46 @@ Logi zmian z migracji na Domain-Driven Architecture. Najnowsze na gorze.
|
||||
|
||||
---
|
||||
|
||||
## ver. 0.315 (2026-02-23) - Fix listowania atrybutów w admin
|
||||
|
||||
- **FIX**: `AttributeRepository::listForAdmin()` — zapytanie COUNT dostawało parametr `:default_lang_id` którego nie miało w SQL, powodując `PDOException: SQLSTATE[HY093]: Invalid parameter number`. Parametr potrzebny tylko w głównym SELECT, nie w COUNT
|
||||
|
||||
---
|
||||
|
||||
## ver. 0.314 (2026-02-23) - Fix wyszukiwarki admin + title zamówienia
|
||||
|
||||
- **FIX**: Globalna wyszukiwarka w panelu admina przestała zwracać wyniki — dodano `Content-Type: application/json` i `Cache-Control: no-store` (zapobiega cache'owaniu przez proxy/CDN), zmiana AJAX z GET na POST, `fetchAll(PDO::FETCH_ASSOC)`, top-level try/catch z gwarantowaną odpowiedzią JSON
|
||||
- **NEW**: `document.title` w widoku szczegółów zamówienia pokazuje numer zamówienia (np. "Zamówienie ZAM/123 - shopPro")
|
||||
|
||||
---
|
||||
|
||||
## ver. 0.313 (2026-02-23) - Fix sync płatności Apilo + logowanie
|
||||
|
||||
- **FIX**: `syncApiloPayment()` i `syncApiloStatus()` — `(int)` cast na `apilo_order_id` (format `"PPxxxxxx"`) dawał `0`, przez co metody pomijały sync z API Apilo. Zmiana na `empty()`
|
||||
- **NEW**: Logowanie w `syncApiloPaymentIfNeeded()` i `syncApiloStatusIfNeeded()` — każda ścieżka decyzyjna (Apilo wyłączone, brak tokenu, brak `apilo_order_id`, sync nieudany) zapisuje wpis do `pp_log` z kontekstem
|
||||
|
||||
---
|
||||
|
||||
## ver. 0.312 (2026-02-23) - Fix krytycznych bugów integracji Apilo
|
||||
|
||||
- **FIX**: `curl_getinfo()` wywoływane po `curl_close()` — HTTP code zawsze wynosił 0, uniemożliwiając prawidłową obsługę odpowiedzi Apilo
|
||||
- **FIX**: Nieskończona pętla wysyłania zamówienia — gdy Apilo zwracało błąd serwera, zamówienie nie dostawało `apilo_order_id` i było ponownie wybierane w każdym cyklu crona. Teraz błędne zamówienia oznaczane `apilo_order_id = -1` z powiadomieniem email
|
||||
- **FIX**: Ceny produktów 0.00 PLN w Apilo — string `"0.00"` z MySQL jest truthy w PHP, więc ternary wybierał `price_brutto_promo` (0.00) zamiast `price_brutto`. Zmiana na `(float)... > 0`
|
||||
- **FIX**: Walidacja cen przed wysyłką — zamówienia z zerowymi cenami produktów nie są wysyłane do Apilo (`apilo_order_id = -2`) z powiadomieniem email
|
||||
- **FIX**: Niezainicjalizowana zmienna `$order_message` powodująca PHP warning
|
||||
|
||||
---
|
||||
|
||||
## ver. 0.311 (2026-02-23) - Fix race condition Apilo + persistence filtrów + poprawki cen
|
||||
|
||||
- **FIX**: Race condition — callback płatności przed wysłaniem zamówienia do Apilo nie synchronizował płatności (task trafiał w pustkę). Teraz `syncApiloPaymentIfNeeded` i `syncApiloStatusIfNeeded` kolejkują sync do retry gdy `apilo_order_id` jeszcze nie istnieje
|
||||
- **FIX**: `processApiloSyncQueue` — zamówienia bez `apilo_order_id` były usuwane z kolejki bez synchronizacji. Teraz czekają (max 50 prób ~8h) aż cron wyśle zamówienie do Apilo
|
||||
- **FIX**: Drugie wywołanie `processApiloSyncQueue` w cronie po wysyłce zamówień — sync płatności/statusów w tym samym cyklu
|
||||
- **FIX**: Ceny w szczegółach zamówienia (admin + frontend) — gdy `price_brutto_promo` = 0 lub >= ceny regularnej, wyświetla cenę regularną zamiast 0 zł
|
||||
- **NEW**: Persistence filtrów tabel w panelu admin — localStorage zapamiętuje ostatni widok (filtry, sortowanie, paginacja) i przywraca go przy powrocie do listy. Przycisk "Wyczyść" resetuje zapisany stan
|
||||
|
||||
---
|
||||
|
||||
## ver. 0.310 (2026-02-23) - Logi integracji w panelu admin
|
||||
|
||||
- **NEW**: Zakładka "Logi" w sekcji Integracje — podgląd tabeli `pp_log` z paginacją, sortowaniem, filtrami (akcja, wiadomość, ID zamówienia) i rozwijalnym kontekstem JSON
|
||||
|
||||
156
docs/CRON_QUEUE_PLAN.md
Normal file
156
docs/CRON_QUEUE_PLAN.md
Normal file
@@ -0,0 +1,156 @@
|
||||
# Plan: System kolejki zadań cron oparty o bazę danych
|
||||
|
||||
## Kontekst
|
||||
|
||||
Obecny system cron ma dwa problemy:
|
||||
1. **Kolejka plikowa (JSON)** — sync płatności/statusów Apilo trzymany w `/temp/apilo-sync-queue.json` — kruchy, brak transakcji, ryzyko utraty danych
|
||||
2. **Monolityczny cron.php** (~550 linii) — brak priorytetów, brak retry z backoff, brak centralnego zarządzania
|
||||
|
||||
Cel: Zastąpienie całego systemu cron tabelą `pp_cron_jobs` z priorytetami, retry/backoff i harmonogramem `pp_cron_schedules`.
|
||||
|
||||
## Nowe pliki
|
||||
|
||||
| Plik | Opis |
|
||||
|------|------|
|
||||
| `autoload/Domain/CronJob/CronJobType.php` | Stałe typów zadań i priorytetów |
|
||||
| `autoload/Domain/CronJob/CronJobRepository.php` | CRUD na `pp_cron_jobs` + `pp_cron_schedules` |
|
||||
| `autoload/Domain/CronJob/CronJobProcessor.php` | Orkiestracja: pobierz zadanie → wywołaj handler → obsłuż wynik |
|
||||
| `tests/Unit/Domain/CronJob/CronJobTypeTest.php` | Testy stałych |
|
||||
| `tests/Unit/Domain/CronJob/CronJobRepositoryTest.php` | Testy repozytorium |
|
||||
| `tests/Unit/Domain/CronJob/CronJobProcessorTest.php` | Testy procesora |
|
||||
| `migrations/0.315.sql` | CREATE TABLE + INSERT harmonogramów |
|
||||
|
||||
## Modyfikowane pliki
|
||||
|
||||
| Plik | Zmiana |
|
||||
|------|--------|
|
||||
| `cron.php` | Zastąpienie ~550 linii orchestratorem (~100 linii) z rejestracją handlerów |
|
||||
| `cron/cron-xml.php` | Usunięcie — logika przeniesiona do handlera `google_xml_feed` |
|
||||
| `cron-turstmate.php` | Usunięcie — logika przeniesiona do handlera `trustmate_invitation` |
|
||||
| `autoload/Domain/Order/OrderAdminService.php` | `queueApiloSync()` → enqueue do DB; usunięcie metod plikowych; `syncApiloPayment()`/`syncApiloStatus()` → public |
|
||||
| `tests/Unit/Domain/Order/OrderAdminServiceTest.php` | Refaktor testów kolejki: mock `CronJobRepository` zamiast pliku JSON |
|
||||
| `docs/DATABASE_STRUCTURE.md` | Dodanie tabel `pp_cron_jobs`, `pp_cron_schedules` |
|
||||
| `docs/CHANGELOG.md` | Wpis o nowym systemie |
|
||||
|
||||
## Schemat DB (`migrations/0.315.sql`)
|
||||
|
||||
### `pp_cron_jobs`
|
||||
```sql
|
||||
CREATE TABLE pp_cron_jobs (
|
||||
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
||||
job_type VARCHAR(50) NOT NULL,
|
||||
status ENUM('pending','processing','completed','failed','cancelled') NOT NULL DEFAULT 'pending',
|
||||
priority TINYINT UNSIGNED NOT NULL DEFAULT 100, -- niższy = ważniejszy
|
||||
payload TEXT NULL, -- JSON z danymi zadania
|
||||
result TEXT NULL, -- JSON z wynikiem
|
||||
attempts SMALLINT UNSIGNED NOT NULL DEFAULT 0,
|
||||
max_attempts SMALLINT UNSIGNED NOT NULL DEFAULT 10,
|
||||
last_error VARCHAR(500) NULL,
|
||||
scheduled_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
started_at DATETIME NULL,
|
||||
completed_at DATETIME NULL,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
INDEX idx_status_priority_scheduled (status, priority, scheduled_at),
|
||||
INDEX idx_job_type (job_type),
|
||||
INDEX idx_status (status)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
```
|
||||
|
||||
### `pp_cron_schedules`
|
||||
```sql
|
||||
CREATE TABLE pp_cron_schedules (
|
||||
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
||||
job_type VARCHAR(50) NOT NULL UNIQUE,
|
||||
interval_seconds INT UNSIGNED NOT NULL,
|
||||
priority TINYINT UNSIGNED NOT NULL DEFAULT 100,
|
||||
max_attempts SMALLINT UNSIGNED NOT NULL DEFAULT 3,
|
||||
payload TEXT NULL,
|
||||
enabled TINYINT(1) NOT NULL DEFAULT 1,
|
||||
last_run_at DATETIME NULL,
|
||||
next_run_at DATETIME NULL,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
INDEX idx_enabled_next_run (enabled, next_run_at)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
```
|
||||
|
||||
## Typy zadań i priorytety
|
||||
|
||||
| Typ | Priorytet | Harmonogram |
|
||||
|-----|-----------|-------------|
|
||||
| `apilo_token_keepalive` | 10 (krytyczny) | co 4 min |
|
||||
| `apilo_send_order` | 50 (wysoki) | co 1 min |
|
||||
| `apilo_sync_payment` | 50 (wysoki) | event-driven (enqueue przy zmianie) |
|
||||
| `apilo_sync_status` | 50 (wysoki) | event-driven |
|
||||
| `apilo_product_sync` | 100 (normalny) | co 10 min |
|
||||
| `apilo_pricelist_sync` | 100 (normalny) | co 1h |
|
||||
| `apilo_status_poll` | 100 (normalny) | co 10 min |
|
||||
| `price_history` | 100 (normalny) | co 24h |
|
||||
| `order_analysis` | 100 (normalny) | co 10 min |
|
||||
| `trustmate_invitation` | 200 (niski) | co 10 min |
|
||||
| `google_xml_feed` | 200 (niski) | co 1h |
|
||||
|
||||
## Architektura klas
|
||||
|
||||
### CronJobRepository — metody kluczowe
|
||||
- `enqueue($jobType, $payload, $priority, $maxAttempts, $scheduledAt)` — dodaj do kolejki
|
||||
- `fetchNext($limit)` — atomowe pobranie pending jobs (UPDATE WHERE status='pending')
|
||||
- `markCompleted($jobId, $result)` / `markFailed($jobId, $error, $backoffSeconds)`
|
||||
- `hasPendingJob($jobType, $payloadMatch)` — zapobiega duplikatom
|
||||
- `cleanup($olderThanDays)` — GC starych wpisów
|
||||
- `recoverStuck($olderThanMinutes)` — reset stuck "processing" jobs
|
||||
- `getDueSchedules()` / `touchSchedule($id)` — harmonogram
|
||||
|
||||
### CronJobProcessor — orkiestracja
|
||||
- `registerHandler($jobType, callable)` — rejestracja handlera
|
||||
- `createScheduledJobs()` — tworzy jobs z harmonogramów których `next_run_at <= NOW`
|
||||
- `processQueue($limit)` — pobierz + wywołaj handler + markCompleted/markFailed
|
||||
- `run($limit)` — główna metoda: schedules + process
|
||||
|
||||
### Exponential backoff
|
||||
```
|
||||
Próba 1: 60s, Próba 2: 120s, Próba 3: 240s, ... max 3600s (1h)
|
||||
```
|
||||
|
||||
### Zależność "order not yet in Apilo"
|
||||
Handler `apilo_sync_payment`/`apilo_sync_status` sprawdza `apilo_order_id`. Jeśli brak → zwraca false → `markFailed()` z backoffem → zadanie wraca do kolejki. Max 50 prób.
|
||||
|
||||
## Nowy cron.php (schemat)
|
||||
|
||||
```php
|
||||
$cronRepo = new \Domain\CronJob\CronJobRepository($mdb);
|
||||
$processor = new \Domain\CronJob\CronJobProcessor($mdb, $cronRepo);
|
||||
|
||||
// Rejestracja handlerów (każdy to callable)
|
||||
$processor->registerHandler('apilo_token_keepalive', function($payload) use ($integrationsRepo) { ... });
|
||||
$processor->registerHandler('apilo_send_order', function($payload) use ($orderService, ...) { ... });
|
||||
// ... inne handlery
|
||||
|
||||
$result = $processor->run(20);
|
||||
```
|
||||
|
||||
## Zmiany w OrderAdminService
|
||||
|
||||
1. `queueApiloSync()` → `CronJobRepository::enqueue()` zamiast zapisu do pliku JSON
|
||||
2. Usunięcie: `loadApiloSyncQueue()`, `saveApiloSyncQueue()`, `apiloSyncQueuePath()`, stała `APILO_SYNC_QUEUE_FILE`
|
||||
3. `syncApiloPayment()`, `syncApiloStatus()` → zmiana z `private` na `public`
|
||||
4. Jednorazowa migracja: odczyt JSON → insert do DB → usunięcie pliku
|
||||
|
||||
## Kolejność implementacji
|
||||
|
||||
1. Migracja SQL
|
||||
2. `CronJobType.php`
|
||||
3. `CronJobRepository.php` + testy
|
||||
4. `CronJobProcessor.php` + testy
|
||||
5. Modyfikacja `OrderAdminService` (queue → DB, public methods)
|
||||
6. Jednorazowa migracja pliku JSON → DB
|
||||
7. Nowy `cron.php` z handlerami (ekstrakcja logiki z bloków proceduralnych)
|
||||
8. Aktualizacja testów OrderAdminService
|
||||
9. Dokumentacja (DATABASE_STRUCTURE.md, CHANGELOG.md)
|
||||
|
||||
## Weryfikacja
|
||||
|
||||
1. Uruchomienie pełnego zestawu testów: `./test.ps1`
|
||||
2. Sprawdzenie czy nowe testy CronJob* przechodzą
|
||||
3. Sprawdzenie czy istniejące testy OrderAdminService przechodzą po refaktorze
|
||||
4. Weryfikacja migracji SQL na pustej bazie
|
||||
@@ -179,7 +179,7 @@
|
||||
'id': <?= (int)$product['product_id'];?>,
|
||||
'name': '<?= $product['name'];?>',
|
||||
'quantity': <?= $product['quantity'];?>,
|
||||
'price': <?= $product['price_brutto_promo'];?>
|
||||
'price': <?= ((float)$product['price_brutto_promo'] > 0 && (float)$product['price_brutto_promo'] < (float)$product['price_brutto']) ? (float)$product['price_brutto_promo'] : (float)$product['price_brutto'];?>
|
||||
}<? if ( $product != end( $this -> order['products'] ) ) echo ',';?>
|
||||
<? endforeach;?>
|
||||
]
|
||||
|
||||
@@ -227,4 +227,110 @@ class OrderAdminServiceTest extends TestCase
|
||||
$service = $this->createService(null, null, $settingsRepo);
|
||||
$this->assertSame(150.0, $service->getFreeDeliveryThreshold());
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// processApiloSyncQueue — awaiting apilo_order_id
|
||||
// =========================================================================
|
||||
|
||||
private function getQueuePath(): string
|
||||
{
|
||||
// Musi odpowiadać ścieżce w OrderAdminService::apiloSyncQueuePath()
|
||||
// dirname(autoload/Domain/Order/, 2) = autoload/
|
||||
return dirname(__DIR__, 4) . '/autoload/temp/apilo-sync-queue.json';
|
||||
}
|
||||
|
||||
private function writeQueue(array $queue): void
|
||||
{
|
||||
$path = $this->getQueuePath();
|
||||
$dir = dirname($path);
|
||||
if (!is_dir($dir)) {
|
||||
mkdir($dir, 0777, true);
|
||||
}
|
||||
file_put_contents($path, json_encode($queue, JSON_PRETTY_PRINT));
|
||||
}
|
||||
|
||||
private function readQueue(): array
|
||||
{
|
||||
$path = $this->getQueuePath();
|
||||
if (!file_exists($path)) return [];
|
||||
$content = file_get_contents($path);
|
||||
return $content ? json_decode($content, true) : [];
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$path = $this->getQueuePath();
|
||||
if (file_exists($path)) {
|
||||
unlink($path);
|
||||
}
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function testProcessApiloSyncQueueKeepsTaskWhenApiloOrderIdIsNull(): void
|
||||
{
|
||||
// Zamówienie bez apilo_order_id — task powinien zostać w kolejce
|
||||
$this->writeQueue([
|
||||
'42' => [
|
||||
'order_id' => 42,
|
||||
'payment' => 1,
|
||||
'status' => null,
|
||||
'attempts' => 0,
|
||||
'last_error' => 'awaiting_apilo_order',
|
||||
'updated_at' => '2026-01-01 00:00:00',
|
||||
],
|
||||
]);
|
||||
|
||||
$orderRepo = $this->createMock(OrderRepository::class);
|
||||
$orderRepo->method('findRawById')
|
||||
->with(42)
|
||||
->willReturn([
|
||||
'id' => 42,
|
||||
'apilo_order_id' => null,
|
||||
'paid' => 1,
|
||||
'summary' => '100.00',
|
||||
]);
|
||||
|
||||
$service = new OrderAdminService($orderRepo);
|
||||
$processed = $service->processApiloSyncQueue(10);
|
||||
|
||||
$this->assertSame(1, $processed);
|
||||
|
||||
$queue = $this->readQueue();
|
||||
$this->assertArrayHasKey('42', $queue);
|
||||
$this->assertSame('awaiting_apilo_order', $queue['42']['last_error']);
|
||||
$this->assertSame(1, $queue['42']['attempts']);
|
||||
}
|
||||
|
||||
public function testProcessApiloSyncQueueRemovesTaskAfterMaxAttempts(): void
|
||||
{
|
||||
// Task z 49 próbami — limit to 50, więc powinien zostać usunięty
|
||||
$this->writeQueue([
|
||||
'42' => [
|
||||
'order_id' => 42,
|
||||
'payment' => 1,
|
||||
'status' => null,
|
||||
'attempts' => 49,
|
||||
'last_error' => 'awaiting_apilo_order',
|
||||
'updated_at' => '2026-01-01 00:00:00',
|
||||
],
|
||||
]);
|
||||
|
||||
$orderRepo = $this->createMock(OrderRepository::class);
|
||||
$orderRepo->method('findRawById')
|
||||
->with(42)
|
||||
->willReturn([
|
||||
'id' => 42,
|
||||
'apilo_order_id' => null,
|
||||
'paid' => 1,
|
||||
'summary' => '100.00',
|
||||
]);
|
||||
|
||||
$service = new OrderAdminService($orderRepo);
|
||||
$processed = $service->processApiloSyncQueue(10);
|
||||
|
||||
$this->assertSame(1, $processed);
|
||||
|
||||
$queue = $this->readQueue();
|
||||
$this->assertArrayNotHasKey('42', $queue);
|
||||
}
|
||||
}
|
||||
|
||||
BIN
updates/0.30/ver_0.310.zip
Normal file
BIN
updates/0.30/ver_0.310.zip
Normal file
Binary file not shown.
25
updates/0.30/ver_0.310_manifest.json
Normal file
25
updates/0.30/ver_0.310_manifest.json
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"changelog": "NEW - Zakladka Logi w sekcji Integracje (podglad pp_log z paginacja, sortowaniem, filtrami)",
|
||||
"version": "0.310",
|
||||
"files": {
|
||||
"added": [
|
||||
"admin/templates/integrations/logs.php"
|
||||
],
|
||||
"deleted": [
|
||||
|
||||
],
|
||||
"modified": [
|
||||
"admin/templates/site/main-layout.php",
|
||||
"autoload/Domain/Integrations/IntegrationsRepository.php",
|
||||
"autoload/admin/Controllers/IntegrationsController.php"
|
||||
]
|
||||
},
|
||||
"checksum_zip": "sha256:e3b14e239230548aba203a83f01c91b00651e5114e92e162f6da7389c6a92975",
|
||||
"sql": [
|
||||
|
||||
],
|
||||
"date": "2026-02-23",
|
||||
"directories_deleted": [
|
||||
|
||||
]
|
||||
}
|
||||
BIN
updates/0.30/ver_0.311.zip
Normal file
BIN
updates/0.30/ver_0.311.zip
Normal file
Binary file not shown.
27
updates/0.30/ver_0.311_manifest.json
Normal file
27
updates/0.30/ver_0.311_manifest.json
Normal file
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"changelog": "FIX - race condition callback płatności Apilo, persistence filtrów tabel admin, poprawki cen zamówień",
|
||||
"version": "0.311",
|
||||
"files": {
|
||||
"added": [
|
||||
|
||||
],
|
||||
"deleted": [
|
||||
|
||||
],
|
||||
"modified": [
|
||||
"admin/templates/components/table-list.php",
|
||||
"admin/templates/shop-order/order-details.php",
|
||||
"autoload/Domain/Order/OrderAdminService.php",
|
||||
"cron.php",
|
||||
"templates/shop-order/order-details.php"
|
||||
]
|
||||
},
|
||||
"checksum_zip": "sha256:542f599e844d48bba1378fbe91c06ef00d5487aca56af118ad9c9ea27343ebdb",
|
||||
"sql": [
|
||||
|
||||
],
|
||||
"date": "2026-02-23",
|
||||
"directories_deleted": [
|
||||
|
||||
]
|
||||
}
|
||||
BIN
updates/0.30/ver_0.312.zip
Normal file
BIN
updates/0.30/ver_0.312.zip
Normal file
Binary file not shown.
23
updates/0.30/ver_0.312_manifest.json
Normal file
23
updates/0.30/ver_0.312_manifest.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"changelog": "FIX - krytyczne bugi integracji Apilo: curl_getinfo po curl_close, nieskończona pętla wysyłki, ceny 0.00 PLN, walidacja cen",
|
||||
"version": "0.312",
|
||||
"files": {
|
||||
"added": [
|
||||
|
||||
],
|
||||
"deleted": [
|
||||
|
||||
],
|
||||
"modified": [
|
||||
"cron.php"
|
||||
]
|
||||
},
|
||||
"checksum_zip": "sha256:07f9efd02a6a83327ab8dd9403e0c072a5f38b680d6e3f6c67a96d2af8b8fc85",
|
||||
"sql": [
|
||||
|
||||
],
|
||||
"date": "2026-02-23",
|
||||
"directories_deleted": [
|
||||
|
||||
]
|
||||
}
|
||||
BIN
updates/0.30/ver_0.313.zip
Normal file
BIN
updates/0.30/ver_0.313.zip
Normal file
Binary file not shown.
24
updates/0.30/ver_0.313_manifest.json
Normal file
24
updates/0.30/ver_0.313_manifest.json
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"changelog": "FIX - sync płatności Apilo (int cast na apilo_order_id PPxxxxxx dawał 0) + logowanie decyzji sync do pp_log",
|
||||
"version": "0.313",
|
||||
"files": {
|
||||
"added": [
|
||||
|
||||
],
|
||||
"deleted": [
|
||||
|
||||
],
|
||||
"modified": [
|
||||
"admin/templates/shop-order/order-details.php",
|
||||
"autoload/Domain/Order/OrderAdminService.php"
|
||||
]
|
||||
},
|
||||
"checksum_zip": "sha256:f344da1f3270abfc63653f8912ec1abbc006154db784cfee5a565fc0daaa75f8",
|
||||
"sql": [
|
||||
|
||||
],
|
||||
"date": "2026-02-23",
|
||||
"directories_deleted": [
|
||||
|
||||
]
|
||||
}
|
||||
BIN
updates/0.30/ver_0.314.zip
Normal file
BIN
updates/0.30/ver_0.314.zip
Normal file
Binary file not shown.
25
updates/0.30/ver_0.314_manifest.json
Normal file
25
updates/0.30/ver_0.314_manifest.json
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"changelog": "FIX - naprawa globalnej wyszukiwarki admin (Content-Type, Cache-Control, POST, try/catch), NEW - title strony z numerem zamówienia",
|
||||
"version": "0.314",
|
||||
"files": {
|
||||
"added": [
|
||||
|
||||
],
|
||||
"deleted": [
|
||||
|
||||
],
|
||||
"modified": [
|
||||
"admin/templates/shop-order/order-details.php",
|
||||
"admin/templates/site/main-layout.php",
|
||||
"autoload/admin/Controllers/SettingsController.php"
|
||||
]
|
||||
},
|
||||
"checksum_zip": "sha256:5ef21d158850db4036e3ee3ed4e9d2938d0451cd9b8602d26fd53163085a391f",
|
||||
"sql": [
|
||||
|
||||
],
|
||||
"date": "2026-02-23",
|
||||
"directories_deleted": [
|
||||
|
||||
]
|
||||
}
|
||||
@@ -1,3 +1,18 @@
|
||||
<b>ver. 0.314 - 23.02.2026</b><br />
|
||||
FIX - naprawa globalnej wyszukiwarki admin (Content-Type, Cache-Control, POST, try/catch), NEW - title strony z numerem zamówienia
|
||||
<hr>
|
||||
<b>ver. 0.313 - 23.02.2026</b><br />
|
||||
FIX - sync płatności Apilo (int cast na apilo_order_id PPxxxxxx dawał 0) + logowanie decyzji sync do pp_log
|
||||
<hr>
|
||||
<b>ver. 0.312 - 23.02.2026</b><br />
|
||||
FIX - krytyczne bugi integracji Apilo: curl_getinfo po curl_close, nieskończona pętla wysyłki, ceny 0.00 PLN, walidacja cen
|
||||
<hr>
|
||||
<b>ver. 0.311 - 23.02.2026</b><br />
|
||||
FIX - race condition callback płatności Apilo, persistence filtrów tabel admin, poprawki cen zamówień
|
||||
<hr>
|
||||
<b>ver. 0.310 - 23.02.2026</b><br />
|
||||
NEW - Zakladka Logi w sekcji Integracje (podglad pp_log z paginacja, sortowaniem, filtrami)
|
||||
<hr>
|
||||
<b>ver. 0.309 - 23.02.2026</b><br />
|
||||
NEW - ApiloLogger (logowanie operacji Apilo do pp_log), cache-busting CSS/JS w admin panelu, poprawki UI listy produktow, clipboard API
|
||||
<hr>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?
|
||||
$current_ver = 310;
|
||||
$current_ver = 315;
|
||||
|
||||
for ($i = 1; $i <= $current_ver; $i++)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user