Skip to content

Commit

Permalink
Added suggestions search results page
Browse files Browse the repository at this point in the history
  • Loading branch information
jansentjeu committed Jan 17, 2025
1 parent a533687 commit e781989
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 1 deletion.
28 changes: 28 additions & 0 deletions src/Controller/Results/Index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Tweakwise\TweakwiseJs\Controller\Results;

use Magento\Framework\App\Action\HttpGetActionInterface;
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\Controller\ResultInterface;

class Index implements HttpGetActionInterface
{
/**
* @param ResultFactory $resultFactory
*/
public function __construct(
private readonly ResultFactory $resultFactory
) {
}

/**
* @return ResultInterface
*/
public function execute()
{
return $this->resultFactory->create(ResultFactory::TYPE_PAGE);
}
}
2 changes: 1 addition & 1 deletion src/ViewModel/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@ public function getStoreRootCategory(): int
*/
public function getSearchUrl(): string
{
return trim($this->urlBuilder->getUrl('twsearch#twn|'), '/');
return trim($this->urlBuilder->getUrl('catalogsearch/results#twn|'), '/');
}
}
9 changes: 9 additions & 0 deletions src/etc/frontend/routes.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="standard">
<route id="catalogsearch" frontName="catalogsearch">
<module name="Tweakwise_TweakwiseJs"/>
</route>
</router>
</config>
7 changes: 7 additions & 0 deletions src/view/frontend/layout/catalogsearch_results_index.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="columns" remove="true"/>
</body>
</page>
10 changes: 10 additions & 0 deletions src/view/frontend/templates/js/search.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ $viewModel = $block->getViewModel();
}
});
});

window.addEventListener('DOMContentLoaded', () => {
const inputId = input[0].replace('#', '');
const $input = document.getElementById(inputId);
const $form = $input.closest('form');
$form.onsubmit = e => {
e.preventDefault();
location.href = '<?= $viewModel->getSearchUrl();?>?tn_q=' + $input.value;
};
});
</script>
<?php elseif ($viewModel->getSearchType() === SearchType::INSTANT_SEARCH->value): ?>
<script>
Expand Down

0 comments on commit e781989

Please sign in to comment.