ver. 0.294: Code review complete — 96/96 classes, 27 fixes across all layers
Full codebase review of autoload/ directory (96 classes, ~1144 methods). Fixes: null safety (query/find guards), redundant DI bypass, undefined variables, missing globals, and Imagick WebP mime type bug in Helpers. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1154,6 +1154,11 @@ class ProductRepository
|
||||
*/
|
||||
public function updateCustomLabel(int $productId, string $label, $value): bool
|
||||
{
|
||||
$allowed = ['0', '1', '2', '3', '4'];
|
||||
if (!in_array($label, $allowed, true)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->db->update( 'pp_shop_products', [
|
||||
'custom_label_' . $label => $value ? $value : null,
|
||||
], [ 'id' => $productId ] );
|
||||
@@ -1478,6 +1483,11 @@ class ProductRepository
|
||||
*/
|
||||
public function customLabelSuggestions(string $customLabel, string $labelType): array
|
||||
{
|
||||
$allowed = ['custom_label_0', 'custom_label_1', 'custom_label_2', 'custom_label_3', 'custom_label_4'];
|
||||
if (!in_array($labelType, $allowed, true)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$output = [];
|
||||
$results = $this->db->query(
|
||||
'SELECT DISTINCT ' . $labelType . ' AS label FROM pp_shop_products WHERE ' . $labelType . ' LIKE :custom_label LIMIT 10',
|
||||
@@ -1496,6 +1506,11 @@ class ProductRepository
|
||||
*/
|
||||
public function saveCustomLabel(int $productId, string $customLabel, string $labelType): bool
|
||||
{
|
||||
$allowed = ['custom_label_0', 'custom_label_1', 'custom_label_2', 'custom_label_3', 'custom_label_4'];
|
||||
if (!in_array($labelType, $allowed, true)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (bool) $this->db->update( 'pp_shop_products', [ $labelType => $customLabel ], [ 'id' => $productId ] );
|
||||
}
|
||||
|
||||
@@ -1525,6 +1540,7 @@ class ProductRepository
|
||||
global $lang_id;
|
||||
|
||||
$settings = ( new \Domain\Settings\SettingsRepository( $this->db ) )->allSettings( true );
|
||||
$this->transportRepoForXml = new \Domain\Transport\TransportRepository( $this->db );
|
||||
|
||||
$domainPrefix = 'https';
|
||||
$url = preg_replace( '#^(http(s)?://)?w{3}\.#', '$1', $_SERVER['SERVER_NAME'] );
|
||||
@@ -1715,7 +1731,7 @@ class ProductRepository
|
||||
$shippingNode->appendChild( $doc->createElement( 'g:country', 'PL' ) );
|
||||
$shippingNode->appendChild( $doc->createElement( 'g:service', '1 dzień roboczy' ) );
|
||||
$shippingNode->appendChild( $doc->createElement( 'g:price',
|
||||
( new \Domain\Transport\TransportRepository( $this->db ) )->lowestTransportPrice( (int) $product['wp'] ) . ' PLN'
|
||||
$this->transportRepoForXml->lowestTransportPrice( (int) $product['wp'] ) . ' PLN'
|
||||
) );
|
||||
}
|
||||
|
||||
@@ -2197,8 +2213,8 @@ class ProductRepository
|
||||
$product['categories'] = $this->db->select('pp_shop_products_categories', 'category_id', ['product_id' => $productId]);
|
||||
$product['products_related'] = $this->db->select('pp_shop_products_related', 'product_related_id', ['product_id' => $productId]);
|
||||
|
||||
$setId = $this->db->select('pp_shop_product_sets_products', 'set_id', ['product_id' => $productId]);
|
||||
$productsSets = $this->db->select('pp_shop_product_sets_products', 'product_id', ['set_id' => (int)$setId]);
|
||||
$setId = (int)($product['set_id'] ?? 0);
|
||||
$productsSets = $this->db->select('pp_shop_product_sets_products', 'product_id', ['set_id' => $setId]);
|
||||
$product['products_sets'] = is_array($productsSets) ? array_unique($productsSets) : [];
|
||||
|
||||
$attributes = $this->db->select('pp_shop_products_attributes', ['attribute_id', 'value_id'], ['product_id' => $productId]);
|
||||
@@ -2491,7 +2507,7 @@ class ProductRepository
|
||||
|
||||
public function searchProductsByNameCount(string $query, string $langId): int
|
||||
{
|
||||
$results = $this->db->query('SELECT COUNT(0) AS c FROM ( '
|
||||
$stmt = $this->db->query('SELECT COUNT(0) AS c FROM ( '
|
||||
. 'SELECT psp.id, '
|
||||
. '( CASE '
|
||||
. 'WHEN copy_from IS NULL THEN name '
|
||||
@@ -2505,14 +2521,15 @@ class ProductRepository
|
||||
. ') AS q1', [
|
||||
':query' => '%' . $query . '%',
|
||||
':lang_id' => $langId,
|
||||
])->fetchAll(\PDO::FETCH_ASSOC);
|
||||
]);
|
||||
$results = $stmt ? $stmt->fetchAll(\PDO::FETCH_ASSOC) : [];
|
||||
|
||||
return (int) ($results[0]['c'] ?? 0);
|
||||
}
|
||||
|
||||
public function getProductsIdByName(string $query, string $langId, int $limit, int $from): array
|
||||
{
|
||||
$results = $this->db->query('SELECT psp.id, '
|
||||
$stmt = $this->db->query('SELECT psp.id, '
|
||||
. '( CASE '
|
||||
. 'WHEN copy_from IS NULL THEN name '
|
||||
. 'WHEN copy_from IS NOT NULL THEN ( '
|
||||
@@ -2526,7 +2543,8 @@ class ProductRepository
|
||||
. 'LIMIT ' . (int) $from . ',' . (int) $limit, [
|
||||
':query' => '%' . $query . '%',
|
||||
':lang_id' => $langId,
|
||||
])->fetchAll(\PDO::FETCH_ASSOC);
|
||||
]);
|
||||
$results = $stmt ? $stmt->fetchAll(\PDO::FETCH_ASSOC) : [];
|
||||
|
||||
$output = [];
|
||||
if (is_array($results)) {
|
||||
@@ -2562,13 +2580,14 @@ class ProductRepository
|
||||
|
||||
public function searchProductByNameAjax(string $query, string $langId): array
|
||||
{
|
||||
$results = $this->db->query(
|
||||
$stmt = $this->db->query(
|
||||
'SELECT product_id FROM pp_shop_products_langs AS pspl '
|
||||
. 'INNER JOIN pp_shop_products AS psp ON psp.id = pspl.product_id '
|
||||
. 'WHERE status = 1 AND lang_id = :lang_id AND LOWER(name) LIKE :query '
|
||||
. 'ORDER BY visits DESC LIMIT 12',
|
||||
[':query' => '%' . $query . '%', ':lang_id' => $langId]
|
||||
)->fetchAll(\PDO::FETCH_ASSOC);
|
||||
);
|
||||
$results = $stmt ? $stmt->fetchAll(\PDO::FETCH_ASSOC) : [];
|
||||
|
||||
return is_array($results) ? $results : [];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user