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(), ]; }