-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1d506ca
commit 5d80331
Showing
6 changed files
with
113 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
/** | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade Gally to newer versions in the future. | ||
* | ||
* @package Gally | ||
* @author Gally Team <[email protected]> | ||
* @copyright 2024-present Smile | ||
* @license Open Software License v. 3.0 (OSL-3.0) | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Gally\OroPlugin\Search\Autocomplete; | ||
|
||
use Gally\OroPlugin\Config\ConfigManager as GallyConfigManager; | ||
use Gally\OroPlugin\Service\ContextProvider; | ||
use Oro\Bundle\ProductBundle\Event\ProcessAutocompleteDataEvent; | ||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | ||
|
||
/** | ||
* Adds category aggregation to product autocomplete. | ||
*/ | ||
class Attribute | ||
{ | ||
public function __construct( | ||
private ContextProvider $contextProvider, | ||
private GallyConfigManager $gallyConfigManager, | ||
private UrlGeneratorInterface $urlGenerator, | ||
) { | ||
} | ||
|
||
public function onProcessAutocompleteData(ProcessAutocompleteDataEvent $event): void | ||
{ | ||
$websiteId = $this->contextProvider->getCurrentWebsite()->getId(); | ||
if (!$this->gallyConfigManager->isGallyEnabled($websiteId)) { | ||
return; | ||
} | ||
|
||
$searchQuery = $this->contextProvider->getRequest()->getSearchQuery(); | ||
$attributeData = []; | ||
foreach ($this->contextProvider->getResponse()->getAggregations() as $aggregationData) { | ||
foreach ($aggregationData['options'] as $option) { | ||
$params = [ | ||
'f' => [$aggregationData['field'] => ['value' => [$option['value']]]], | ||
'g' => ['search' => $searchQuery], | ||
]; | ||
$url = $this->urlGenerator->generate( | ||
'oro_product_frontend_product_search', | ||
[ | ||
'search' => $searchQuery, | ||
'grid' => ['frontend-product-search-grid' => http_build_query($params)], | ||
] | ||
); | ||
$attributeData[] = [ | ||
'field' => $aggregationData['label'], | ||
'label' => $option['label'], | ||
'url' => $url, | ||
]; | ||
} | ||
} | ||
|
||
$data = $event->getData(); | ||
$data['attributes'] = $attributeData; | ||
$event->setData($data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters