From 2855c70cf400c830257c4305ae6e25df680e2815 Mon Sep 17 00:00:00 2001 From: Henning <leutz@pcsg.de> Date: Sat, 22 Mar 2025 06:45:45 +0100 Subject: [PATCH 1/2] fix: update php version and optimize string operations Updated the PHP version requirement from 8.0 to 8.1 in composer.json. Refactored the string operations functions in category.php and productList.php. Replaced the 'strpos' function with 'str_contains' for better readability and performance. Also replaced the usage of 'strpos' to check for string start with 'str_starts_with' for better readability. Fixed some strings formatting. --- composer.json | 2 +- types/category.php | 10 +++++----- types/productList.php | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index f1530150..b8047731 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "url": "https://www.pcsg.de" }, "require": { - "php": "^8.0", + "php": "^8.1", "quiqqer/core": "^2", "quiqqer/erp": "^3.2", "quiqqer/areas": "^2", diff --git a/types/category.php b/types/category.php index b7ba0a1d..02b57c21 100644 --- a/types/category.php +++ b/types/category.php @@ -29,7 +29,7 @@ // fallback url for a product, with NO category // this should never happen and is a configuration error -if (strpos(QUI::getRequest()->getPathInfo(), '_p/') !== false) { +if (str_contains(QUI::getRequest()->getPathInfo(), '_p/')) { $_REQUEST['_url'] = QUI::getRequest()->getPathInfo(); if (strlen(URL_DIR) == 1) { @@ -133,7 +133,7 @@ } // if product url is with lang flag /en/ - if (strpos($productUrl, '/', 1) === 3 && strpos($productUrl, '/_p/') === false) { + if (strpos($productUrl, '/', 1) === 3 && !str_contains($productUrl, '/_p/')) { $productUrl = mb_substr($productUrl, 3); } @@ -304,7 +304,7 @@ $fields = Products\Utils\Sortables::getSortableFieldsForSite($Site); foreach ($fields as $fieldId) { - if (strpos($fieldId, 'S') === 0) { + if (str_starts_with($fieldId, 'S')) { $title = QUI::getLocale()->get('quiqqer/products', 'sortable.' . mb_substr($fieldId, 1)); $ProductList->addSort( @@ -320,7 +320,7 @@ continue; } - if (strpos($fieldId, 'F') === 0) { + if (str_starts_with($fieldId, 'F')) { try { $fieldId = str_replace('F', '', $fieldId); @@ -361,7 +361,7 @@ } if ($hasFilter && !$ProductList->count()) { - // keine produkte -> weiterleitung zu main + // keine produkte → weiterleitung zu main $Redirect = new RedirectResponse($Site->getUrlRewritten()); $Redirect->setStatusCode(Response::HTTP_SEE_OTHER); diff --git a/types/productList.php b/types/productList.php index 558de754..b6699687 100644 --- a/types/productList.php +++ b/types/productList.php @@ -12,7 +12,7 @@ use QUI\ERP\Products\Handler\Products; $productIds = $Site->getAttribute('quiqqer.products.settings.productIds'); -$productIds = \explode(',', $productIds); +$productIds = explode(',', $productIds); $products = []; -- GitLab From b2d08affe99bd5a33e8b17b80d7a5a49a7b0da60 Mon Sep 17 00:00:00 2001 From: Henning <leutz@pcsg.de> Date: Sat, 22 Mar 2025 06:52:14 +0100 Subject: [PATCH 2/2] fix: improve error logging for product frontend view This commit expands on the error handling mechanism in our product model to be more specific during logging. If a product is activated in the system but not found in the frontend (HTTP 404 response), an error message is now logged using a 'products_not_found' tag. This will make it easier to identify and address issues with deactivated products that should be active. This commonly occurs when an outdated link through a search engine directs a user to a non-existing product page. --- src/QUI/ERP/Products/Product/Model.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/QUI/ERP/Products/Product/Model.php b/src/QUI/ERP/Products/Product/Model.php index 3febbad5..856aafc5 100644 --- a/src/QUI/ERP/Products/Product/Model.php +++ b/src/QUI/ERP/Products/Product/Model.php @@ -351,9 +351,21 @@ public function getViewFrontend(): ViewFrontend try { return new ViewFrontend($this); } catch (\Exception $Exception) { - QUI\System\Log::addError($Exception->getMessage(), [ - 'extra-message' => 'product frontend view error' - ]); + if ($Exception->getCode() === 404) { + // log products not found + // these are often products that are called up but are deactivated and still exist + // e.g. when search engines still direct users to it + QUI\System\Log::addError( + $Exception->getMessage(), + ['extra-message' => 'product frontend view error'], + 'products_not_found' + ); + } else { + QUI\System\Log::addError( + $Exception->getMessage(), + ['extra-message' => 'product frontend view error'] + ); + } throw $Exception; } -- GitLab