Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,13 @@ private function buildProductListQuery(
}
}

foreach ($relationSpecs as $spec) {
$paramKey = 'filter_' . $spec->fieldName;
if (isset($params[$paramKey]) && $params[$paramKey] !== '') {
$c->where([$spec->sortExpression() . ':LIKE' => "%{$params[$paramKey]}%"]);
}
}

if (!isset($params['deleted']) || $params['deleted'] === '') {
$c->where(['msProduct.deleted' => 0]);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/**
* #582: relation column filters use filter_{field} (PHP + Vue grid contract).
*
* Run: php tests/CategoryProductsRelationFilterTest.php
*/

declare(strict_types=1);

$fail = static function (string $message): never {
fwrite(STDERR, "FAIL: {$message}\n");
exit(1);
};

$listSrc = file_get_contents(__DIR__ . '/../src/Services/Category/CategoryProductsListService.php');
$vueSrc = file_get_contents(__DIR__ . '/../../../../vueManager/src/components/CategoryProductsGrid.vue');

if ($listSrc === false) {
$fail('unable to read CategoryProductsListService.php');
}
if ($vueSrc === false) {
$fail('unable to read CategoryProductsGrid.vue');
}

if (!str_contains($listSrc, 'foreach ($optionSpecs as $spec)')) {
$fail('optionSpecs filter loop missing (regression)');
}

if (!preg_match(
'/foreach\s*\(\s*\$relationSpecs\s+as\s+\$spec\s*\)\s*\{[^}]*filter_[^}]*sortExpression\(\)[^}]*:LIKE/s',
$listSrc
)) {
$fail('relationSpecs foreach must apply filter_{field} via sortExpression() LIKE');
}

// Manager grid must prefix both option and relation filters for the backend contract.
if (!preg_match(
"/col\.type\s*===\s*'option'\s*\|\|\s*col\.type\s*===\s*'relation'/",
$vueSrc
) || !str_contains($vueSrc, 'filter_${key}')) {
$fail('CategoryProductsGrid must send filter_{key} for option and relation columns');
}

fwrite(STDOUT, "OK CategoryProductsRelationFilterTest\n");
exit(0);
5 changes: 5 additions & 0 deletions core/components/minishop3/tests/RelationColumnSpecTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@
$spec->selectExpression(),
'vendor select expression'
);
$assertSame(
'`rel_msVendor_vendor_id`.address',
$spec->sortExpression(),
'vendor sort/filter expression'
);

$assertNull(
RelationColumnSpec::fromGroupField($group, [
Expand Down
4 changes: 2 additions & 2 deletions vueManager/src/components/CategoryProductsGrid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ async function loadProducts() {
nested: nested.value ? 1 : 0,
}

// Apply filter values. Option-type columns are JOIN-ed at runtime — backend
// Apply filter values. Option/relation columns are JOIN-ed at runtime — backend
// reads their filters as `filter_{fieldName}` (see CategoryProductsListService).
// Builtin product/data filters keep the original direct-param contract.
Object.keys(filterValues.value).forEach(key => {
Expand All @@ -152,7 +152,7 @@ async function loadProducts() {
return
}
const col = columns.value.find(c => c.name === key)
if (col && col.type === 'option') {
if (col && (col.type === 'option' || col.type === 'relation')) {
params[`filter_${key}`] = value
} else {
params[key] = value
Expand Down