тут очень много с карточкой товара и импортом.

This commit is contained in:
Alisa
2026-06-05 18:50:38 +03:00
parent be883c5843
commit c08519263c
8 changed files with 379 additions and 69 deletions
+2 -2
View File
@@ -84,8 +84,8 @@ final class CatalogController
['title' => 'Каталог', 'url' => '/catalog'],
];
if (!empty($product['category_id'])) {
$breadcrumbs = $categoryRepository->breadcrumbs((int) $product['category_id']);
if (!empty($product['display_category_id'] ?? $product['category_id'] ?? null)) {
$breadcrumbs = $categoryRepository->breadcrumbs((int) ($product['display_category_id'] ?? $product['category_id']));
}
$breadcrumbs[] = ['title' => (string) $product['name']];
+25 -3
View File
@@ -50,13 +50,21 @@ final class ProductRepository extends BaseRepository
$placeholders = implode(',', array_fill(0, count($categoryIds), '?'));
$sql = $this->previewSelectSql(
'AND (
p.category_id IN (' . $placeholders . ')
OR EXISTS (
EXISTS (
SELECT 1
FROM product_category_links pcl
WHERE pcl.product_id = p.id
AND pcl.category_id IN (' . $placeholders . ')
)
OR (
p.category_id IN (' . $placeholders . ')
AND (p.legacy_path IS NULL OR p.legacy_path NOT LIKE \'/katalog/product/view/1/%\')
AND NOT EXISTS (
SELECT 1
FROM product_category_links pcl_any
WHERE pcl_any.product_id = p.id
)
)
)
ORDER BY p.sort_order, p.name',
$limit
@@ -74,9 +82,23 @@ final class ProductRepository extends BaseRepository
public function findBySlug(string $slug): ?array
{
$statement = $this->pdo()->prepare(
'SELECT p.*, c.name AS category_name, c.slug AS category_slug
'SELECT
p.*,
COALESCE(linked_c.id, c.id) AS display_category_id,
COALESCE(linked_c.name, c.name) AS category_name,
COALESCE(linked_c.slug, c.slug) AS category_slug
FROM products p
LEFT JOIN categories c ON c.id = p.category_id
LEFT JOIN categories linked_c
ON linked_c.id = (
SELECT pcl.category_id
FROM product_category_links pcl
INNER JOIN categories lc ON lc.id = pcl.category_id
WHERE pcl.product_id = p.id
AND lc.is_active = 1
ORDER BY lc.parent_id IS NULL, pcl.sort_order, pcl.category_id
LIMIT 1
)
WHERE p.slug = :slug
AND p.is_published = 1
AND p.is_available = 1