Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SW-778 Allow filter values with pipe character (SW 6.5) #358

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
8 changes: 7 additions & 1 deletion src/Findologic/Request/Handler/FilterHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
class FilterHandler
{
public const FILTER_DELIMITER = '|';
public const FILTER_DELIMITER_ENCODED = '%7C';
protected const MIN_PREFIX = 'min-';
protected const MAX_PREFIX = 'max-';
protected const IGNORE_LIST = ['pushAttrib'];
Expand Down Expand Up @@ -188,7 +189,12 @@ protected function fetchAvailableFilterNames(ShopwareEvent|ProductListingCriteri
*/
protected function getFilterValues(string $filterValues): array
{
return explode(self::FILTER_DELIMITER, $filterValues);
$filterValues = explode(self::FILTER_DELIMITER, $filterValues);

return array_map(
static fn (string $value) => str_replace(self::FILTER_DELIMITER_ENCODED, self::FILTER_DELIMITER, $value),
$filterValues
);
}

private function isMinRangeSlider(string $name): bool
Expand Down
11 changes: 8 additions & 3 deletions src/Findologic/Response/Xml21/Filter/Values/FilterValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace FINDOLOGIC\FinSearch\Findologic\Response\Xml21\Filter\Values;

use FINDOLOGIC\FinSearch\Findologic\Request\Handler\FilterHandler;
use FINDOLOGIC\FinSearch\Findologic\Response\Xml21\Filter\Filter;
use FINDOLOGIC\FinSearch\Findologic\Response\Xml21\Filter\TranslatedName;
use Shopware\Core\Framework\Struct\Struct;

Expand All @@ -22,13 +24,16 @@ class FilterValue extends Struct
* The uuid is generated only for the values in which we need a unique ID for selection in storefront
*/
public function __construct(
private readonly string $id,
private readonly string $name,
private string $id,
private string $name,
?string $filterName = null
) {
$this->id = str_replace(FilterHandler::FILTER_DELIMITER, FilterHandler::FILTER_DELIMITER_ENCODED, $id);
$this->name = str_replace(FilterHandler::FILTER_DELIMITER, FilterHandler::FILTER_DELIMITER_ENCODED, $name);

$this->translated = new TranslatedName($name);
if ($filterName !== null) {
$this->uuid = sprintf('%s%s%s', $filterName, self::DELIMITER, $id);
$this->uuid = sprintf('%s%s%s', $filterName, self::DELIMITER, $this->id);
}
}

Expand Down
9 changes: 8 additions & 1 deletion src/Struct/QueryInfoMessage/CategoryInfoMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@

namespace FINDOLOGIC\FinSearch\Struct\QueryInfoMessage;

use FINDOLOGIC\FinSearch\Findologic\Request\Handler\FilterHandler;

class CategoryInfoMessage extends QueryInfoMessage
{
public function __construct(
protected readonly string $filterName,
protected readonly string $filterValue
protected string $filterValue
) {
$this->filterValue = str_replace(
FilterHandler::FILTER_DELIMITER_ENCODED,
FilterHandler::FILTER_DELIMITER,
$filterValue
);
}

public function getFilterName(): string
Expand Down
9 changes: 8 additions & 1 deletion src/Struct/QueryInfoMessage/VendorInfoMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@

namespace FINDOLOGIC\FinSearch\Struct\QueryInfoMessage;

use FINDOLOGIC\FinSearch\Findologic\Request\Handler\FilterHandler;

class VendorInfoMessage extends QueryInfoMessage
{
public function __construct(
protected readonly string $filterName,
protected readonly string $filterValue
protected string $filterValue
) {
$this->filterValue = str_replace(
FilterHandler::FILTER_DELIMITER_ENCODED,
FilterHandler::FILTER_DELIMITER,
$filterValue
);
}

public function getFilterName(): string
Expand Down