-
Notifications
You must be signed in to change notification settings - Fork 1
MAGE-1319 search client #4
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
Merged
+775
−46
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
82c2430
MAGE-1319 Refactor AlgoliaException throw
cammonro 99eeb5c
MAGE-1319 Implement crude adapter client for admin connection testing
cammonro 348cadb
MAGE-1319 Remove unnecessary controller (params passasble to core con…
cammonro 2d534bd
MAGE-1319 Switch to timeout in seconds
cammonro 623be69
MAGE-1319 Display current application ID for multi app across scopes
cammonro 80005d3
MAGE-1319 Add multi app ID instruction
cammonro a3cd630
MAGE-1319 Add backend connector with distinct timeout configuration
cammonro 13144a8
MAGE-1319 Add unit tests for DocumentMapper and fix variable scope bug
cammonro 3f1abbf
MAGE-1319 Bug fix for selectable field on Firefox
cammonro 5613d3e
Update Helper/ConfigHelper.php
cammonro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,36 @@ | ||
| <?php | ||
|
|
||
| namespace Algolia\SearchAdapter\Block\Adminhtml\System\Config; | ||
|
|
||
| use Algolia\SearchAdapter\Helper\ConfigHelper; | ||
| use Magento\Backend\Block\Template\Context; | ||
| use Magento\Framework\Data\Form\Element\AbstractElement; | ||
| use Magento\Framework\View\Helper\SecureHtmlRenderer; | ||
|
|
||
| class ApplicationId extends \Magento\Config\Block\System\Config\Form\Field | ||
| { | ||
| public function __construct( | ||
| protected ConfigHelper $configHelper, | ||
| Context $context, | ||
| array $data = [], | ||
| ?SecureHtmlRenderer $secureRenderer = null | ||
| ) { | ||
| parent::__construct($context, $data, $secureRenderer); | ||
| } | ||
|
|
||
| protected function _getElementHtml(AbstractElement $element): string | ||
| { | ||
| $element->setReadonly(true); | ||
|
|
||
| $request = $this->getRequest(); | ||
| $websiteId = $request->getParam('website') ?? null; | ||
| $storeId = $request->getParam('store') ?? null; | ||
|
|
||
| return '<strong>' . $this->configHelper->getApplicationId($websiteId, $storeId) . '</strong>'; | ||
| } | ||
|
|
||
| protected function _isInheritCheckboxRequired(AbstractElement $element): bool | ||
| { | ||
| return false; | ||
| } | ||
| } |
This file contains hidden or 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,45 @@ | ||
| <?php | ||
|
|
||
| namespace Algolia\SearchAdapter\Block\Adminhtml\System\Config; | ||
|
|
||
| use Algolia\SearchAdapter\Helper\ConfigHelper; | ||
| use Magento\Backend\Block\Template\Context; | ||
| use Magento\Framework\Data\Form\Element\AbstractElement; | ||
| use Magento\Framework\View\Helper\SecureHtmlRenderer; | ||
|
|
||
| class Engine extends \Magento\Config\Block\System\Config\Form\Field | ||
| { | ||
| public function __construct( | ||
| protected ConfigHelper $configHelper, | ||
| Context $context, | ||
| array $data = [], | ||
| ?SecureHtmlRenderer $secureRenderer = null | ||
| ) { | ||
| parent::__construct($context, $data, $secureRenderer); | ||
| } | ||
|
|
||
| /** Hide any engine other than Algolia if not in default scope */ | ||
| protected function _decorateRowHtml(AbstractElement $element, $html): string | ||
| { | ||
| $hiddenStyleAttr = ''; | ||
| if (!$this->configHelper->isEngineSelectVisible($this->getRequest())) { | ||
| $hiddenStyleAttr = ' style="display:none;"'; | ||
| } | ||
| return '<tr id="row_' . $element->getHtmlId() . '"'. $hiddenStyleAttr . '>' . $html . '</tr>'; | ||
| } | ||
|
|
||
| /** Disable engine selection for anything other than default scope */ | ||
| protected function _getElementHtml(AbstractElement $element): string | ||
| { | ||
| if (!$this->configHelper->isEngineSelectEnabled($this->getRequest())) { | ||
| $element->setReadonly(true); | ||
| } | ||
| return parent::_getElementHtml($element); | ||
| } | ||
|
|
||
| /** Preserve engine scope limitation despite overriding scope restrictions */ | ||
| protected function _isInheritCheckboxRequired(AbstractElement $element): bool | ||
| { | ||
| return false; | ||
| } | ||
| } | ||
This file contains hidden or 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,47 @@ | ||
| <?php | ||
|
|
||
| namespace Algolia\SearchAdapter\Block\Adminhtml\System\Config; | ||
|
|
||
| class TestConnection extends \Magento\AdvancedSearch\Block\Adminhtml\System\Config\TestConnection | ||
| { | ||
| protected function _getFieldMapping(): array | ||
| { | ||
| $fields = [ | ||
| 'connectTimeout' => 'catalog_search_algolia_connect_timeout', | ||
| 'readTimeout' => 'catalog_search_algolia_read_timeout', | ||
| ]; | ||
|
|
||
| return array_merge(parent::_getFieldMapping(), $fields); | ||
| } | ||
|
|
||
| /** Augment AJAX requests to include website and store scope */ | ||
| protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element): string | ||
| { | ||
| $request = $this->getRequest(); | ||
| $params = []; | ||
| if ($website = $request->getParam('website')) { | ||
| $params['website'] = $website; | ||
| } | ||
| elseif ($store = $request->getParam('store')) { | ||
| $params['store'] = $store; | ||
| } | ||
|
|
||
| $originalData = $element->getOriginalData(); | ||
| $this->addData( | ||
damcou marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| [ | ||
| 'button_label' => __($originalData['button_label']), | ||
| 'html_id' => $element->getHtmlId(), | ||
| 'ajax_url' => $this->_urlBuilder->getUrl('catalog/search_system_config/testconnection', $params), | ||
| 'field_mapping' => str_replace('"', '\\"', json_encode($this->_getFieldMapping())) | ||
| ] | ||
| ); | ||
|
|
||
| return $this->_toHtml(); | ||
| } | ||
|
|
||
|
|
||
| public function getButtonLabel(): string | ||
| { | ||
| return 'Test Algolia Connection'; | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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,42 @@ | ||
| <?php | ||
|
|
||
| namespace Algolia\SearchAdapter\Model; | ||
|
|
||
| use Algolia\SearchAdapter\Helper\ConfigHelper; | ||
| use Magento\AdvancedSearch\Model\Client\ClientOptionsInterface; | ||
|
|
||
| class Config implements ClientOptionsInterface | ||
| { | ||
| const DEFAULT_TIMEOUT_CONNECT = 2; | ||
| const DEFAULT_TIMEOUT_READ = 5; | ||
|
|
||
| public function __construct( | ||
| protected ConfigHelper $configHelper | ||
| ) {} | ||
|
|
||
| /** | ||
| * @inheritdoc | ||
| */ | ||
| public function prepareClientOptions($options = []): array | ||
| { | ||
| $storeId = $options['store'] ?? null; | ||
| $websiteId = $options['website'] ?? null; | ||
|
|
||
| $defaultOptions = [ | ||
| 'applicationId' => $this->configHelper->getApplicationId($websiteId, $storeId), | ||
| 'apiKey' => $this->configHelper->getApiKey($websiteId, $storeId), | ||
| 'connectTimeout' => self::DEFAULT_TIMEOUT_CONNECT, | ||
| 'readTimeout' => self::DEFAULT_TIMEOUT_READ | ||
| ]; | ||
| $options = array_merge($defaultOptions, $options); | ||
| $allowedOptions = array_merge(array_keys($defaultOptions), ['engine']); | ||
|
|
||
| return array_filter( | ||
| $options, | ||
| function (string $key) use ($allowedOptions) { | ||
| return in_array($key, $allowedOptions); | ||
| }, | ||
| ARRAY_FILTER_USE_KEY | ||
| ); | ||
| } | ||
| } |
This file contains hidden or 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,27 @@ | ||
| <?php | ||
|
|
||
| namespace Algolia\SearchAdapter\Model\Config\Comment; | ||
|
|
||
| use \Algolia\AlgoliaSearch\Model\Config\AbstractConfigComment; | ||
|
|
||
| class ApplicationIdComment extends AbstractConfigComment | ||
| { | ||
| public function getCommentText($elementValue): string | ||
| { | ||
| $link = $this->getConfigLink( | ||
| 'algoliasearch_credentials', | ||
| 'algoliasearch_credentials_credentials-link', | ||
| true | ||
| ); | ||
|
|
||
| return <<<COMMENT | ||
| Algolia's backend search supports multiple application IDs on a single Magento instance. | ||
|
|
||
| <br/><br/> | ||
|
|
||
| To configure credentials for your application id within a given scope, go to | ||
| <a href="$link">Algolia Search > Credentials and Basic Setup</a> | ||
|
|
||
| COMMENT; | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.