From 0d5014465325bc1e98e63e6a8259342bddc63875 Mon Sep 17 00:00:00 2001 From: Tobias Graml Date: Mon, 6 Nov 2023 11:16:53 +0100 Subject: [PATCH 1/2] Fix requests without session params --- src/Search/Request/SearchRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Search/Request/SearchRequest.php b/src/Search/Request/SearchRequest.php index 680dccc9..ba9eef1a 100644 --- a/src/Search/Request/SearchRequest.php +++ b/src/Search/Request/SearchRequest.php @@ -33,7 +33,7 @@ public function __construct( private array $filters = []; - private array $sessionParams = []; + private ?array $sessionParams = null; public function setQuery(string $query): void { From ca3ee43c5e00833f6ba1d925f954aa9b14021d5b Mon Sep 17 00:00:00 2001 From: Tobias Graml Date: Mon, 6 Nov 2023 17:28:07 +0100 Subject: [PATCH 2/2] Add more order handlers --- .../CustomFieldSortingHandler.php | 21 +++++++++++++++++++ .../ProductNumberSortingHandler.php | 21 +++++++++++++++++++ .../SortHandlers/RatingSortingHandler.php | 21 +++++++++++++++++++ .../SortHandlers/StockSortingHandler.php | 21 +++++++++++++++++++ .../Request/Handler/SortingHandlerService.php | 10 ++++++++- 5 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 src/Search/Request/Handler/SortHandlers/CustomFieldSortingHandler.php create mode 100644 src/Search/Request/Handler/SortHandlers/ProductNumberSortingHandler.php create mode 100644 src/Search/Request/Handler/SortHandlers/RatingSortingHandler.php create mode 100644 src/Search/Request/Handler/SortHandlers/StockSortingHandler.php diff --git a/src/Search/Request/Handler/SortHandlers/CustomFieldSortingHandler.php b/src/Search/Request/Handler/SortHandlers/CustomFieldSortingHandler.php new file mode 100644 index 00000000..eb05eee3 --- /dev/null +++ b/src/Search/Request/Handler/SortHandlers/CustomFieldSortingHandler.php @@ -0,0 +1,21 @@ +getField(), 'customFields'); + } + + public function generateSorting(FieldSorting $fieldSorting, SearchRequest $searchNavigationRequest): void + { + $searchNavigationRequest->setSort($fieldSorting->getField(), $fieldSorting->getDirection()); + } +} diff --git a/src/Search/Request/Handler/SortHandlers/ProductNumberSortingHandler.php b/src/Search/Request/Handler/SortHandlers/ProductNumberSortingHandler.php new file mode 100644 index 00000000..140f3a48 --- /dev/null +++ b/src/Search/Request/Handler/SortHandlers/ProductNumberSortingHandler.php @@ -0,0 +1,21 @@ +getField() === 'product.productNumber'; + } + + public function generateSorting(FieldSorting $fieldSorting, SearchRequest $searchNavigationRequest): void + { + $searchNavigationRequest->setSort('customFields.productNumber', $fieldSorting->getDirection()); + } +} diff --git a/src/Search/Request/Handler/SortHandlers/RatingSortingHandler.php b/src/Search/Request/Handler/SortHandlers/RatingSortingHandler.php new file mode 100644 index 00000000..321f6fbf --- /dev/null +++ b/src/Search/Request/Handler/SortHandlers/RatingSortingHandler.php @@ -0,0 +1,21 @@ +getField() === 'product.ratingAverage'; + } + + public function generateSorting(FieldSorting $fieldSorting, SearchRequest $searchNavigationRequest): void + { + $searchNavigationRequest->setSort('ratingValue', $fieldSorting->getDirection()); + } +} diff --git a/src/Search/Request/Handler/SortHandlers/StockSortingHandler.php b/src/Search/Request/Handler/SortHandlers/StockSortingHandler.php new file mode 100644 index 00000000..cedbb352 --- /dev/null +++ b/src/Search/Request/Handler/SortHandlers/StockSortingHandler.php @@ -0,0 +1,21 @@ +getField() === 'product.stock'; + } + + public function generateSorting(FieldSorting $fieldSorting, SearchRequest $searchNavigationRequest): void + { + $searchNavigationRequest->setSort('inventoryLevel', $fieldSorting->getDirection()); + } +} diff --git a/src/Search/Request/Handler/SortingHandlerService.php b/src/Search/Request/Handler/SortingHandlerService.php index 3004a6b6..624b02c9 100644 --- a/src/Search/Request/Handler/SortingHandlerService.php +++ b/src/Search/Request/Handler/SortingHandlerService.php @@ -4,11 +4,15 @@ namespace Nosto\NostoIntegration\Search\Request\Handler; +use Nosto\NostoIntegration\Search\Request\Handler\SortHandlers\CustomFieldSortingHandler; use Nosto\NostoIntegration\Search\Request\Handler\SortHandlers\PriceSortingHandler; use Nosto\NostoIntegration\Search\Request\Handler\SortHandlers\ProductNameSortingHandler; +use Nosto\NostoIntegration\Search\Request\Handler\SortHandlers\ProductNumberSortingHandler; +use Nosto\NostoIntegration\Search\Request\Handler\SortHandlers\RatingSortingHandler; use Nosto\NostoIntegration\Search\Request\Handler\SortHandlers\ReleaseDateSortingHandler; use Nosto\NostoIntegration\Search\Request\Handler\SortHandlers\ScoreSortingHandler; use Nosto\NostoIntegration\Search\Request\Handler\SortHandlers\SortingHandlerInterface; +use Nosto\NostoIntegration\Search\Request\Handler\SortHandlers\StockSortingHandler; use Nosto\NostoIntegration\Search\Request\Handler\SortHandlers\TopSellerSortingHandler; use Nosto\NostoIntegration\Search\Request\SearchRequest; use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria; @@ -32,10 +36,14 @@ public function handle(SearchRequest $searchNavigationRequest, Criteria $criteri protected function getSortingHandlers(): array { return [ - new ScoreSortingHandler(), + new CustomFieldSortingHandler(), new PriceSortingHandler(), new ProductNameSortingHandler(), + new ProductNumberSortingHandler(), + new RatingSortingHandler(), new ReleaseDateSortingHandler(), + new ScoreSortingHandler(), + new StockSortingHandler(), new TopSellerSortingHandler(), ]; }