Skip to content
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

[WIP] Migrate "Search" page #29128

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
80 changes: 80 additions & 0 deletions src/Core/Search/Row/HookableSearchPanel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/

declare(strict_types=1);

namespace PrestaShop\PrestaShop\Core\Search\Row;

use PrestaShop\PrestaShop\Core\Hook\HookDispatcherInterface;
use PrestaShop\PrestaShop\Core\Search\SearchPanel;
use PrestaShop\PrestaShop\Core\Search\SearchPanelInterface;
use Symfony\Component\Translation\TranslatorInterface;

final class HookableSearchPanel {
/**
* @var HookDispatcherInterface
*/
private $hookDispatcher;
/**
* @var TranslatorInterface
*/
private $translator;

public function __construct(HookDispatcherInterface $hookDispatcher, TranslatorInterface $translator)
{
$this->hookDispatcher = $hookDispatcher;
$this->translator = $translator;
}

public function build(string $searchExpression): array
{
$searchPanels = [];
$searchPanels[] = new SearchPanel(
$this->translator->trans('Search docs.prestashop-project.org', [], 'Admin.Navigation.Search'),
$this->translator->trans('Go to the documentation', [], 'Admin.Navigation.Search'),
'https://docs.prestashop-project.org/welcome/',
[
'q' => $searchExpression,
]
);

// Get additional search panels from hooks
$alternativeSearchPanelsFromModules = $this->hookDispatcher->dispatchRenderingWithParameters('actionGetAlternativeSearchPanels', [
'previous_search_panels' => $searchPanels,
'bo_query' => $searchExpression,
])->getContent();

foreach ($alternativeSearchPanelsFromModules as $alternativeSearchPanelsFromModule) {
foreach ($alternativeSearchPanelsFromModule as $alternativeSearchPanel) {
if ($alternativeSearchPanel instanceof SearchPanelInterface) {
$searchPanels[] = $alternativeSearchPanel;
}
}
}

return $searchPanels;
}
}
20 changes: 20 additions & 0 deletions src/PrestaShopBundle/Controller/Admin/CommonController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
use PrestaShop\PrestaShop\Core\Grid\Definition\Factory\FilterableGridDefinitionFactoryInterface;
use PrestaShop\PrestaShop\Core\Grid\Definition\Factory\GridDefinitionFactoryInterface;
use PrestaShop\PrestaShop\Core\Kpi\Row\KpiRowInterface;
use PrestaShop\PrestaShop\Core\Search\Row\SearchPanelRow;
use PrestaShop\PrestaShop\Core\Search\SearchPanel;
use PrestaShop\PrestaShop\Core\Search\SearchPanelInterface;
use PrestaShopBundle\Security\Annotation\AdminSecurity;
use PrestaShopBundle\Service\Grid\ControllerResponseBuilder;
use PrestaShopBundle\Service\Grid\ResponseBuilder;
Expand Down Expand Up @@ -353,4 +356,21 @@ public function searchGridAction(
$redirectQueryParamsToKeep
);
}

/**
* Back Office Search action
*
* @return Response
*/
public function backOfficeSearchAction(Request $request)
{
$searchExpression = $request->request->get('bo_search') ?? '';
$searchType = (int) $request->request->get('bo_type');

$searchPanels = $this->get('prestashop.core.search.panel');
return $this->render('@PrestaShop/Admin/Common/back_office_search.html.twig', [
'help_link' => $this->generateSidebarLink($request->attributes->get('_legacy_controller')),
'searchPanelCollections' => $searchPanels->build($searchExpression),
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,11 @@ admin_common_reset_search_by_filter_id:
_controller: 'PrestaShopBundle\Controller\Admin\CommonController::resetSearchAction'
controller: ''
action: ''

admin_common_back_office_search:
path: /back_office_search
methods: [ GET, POST ]
defaults:
_controller: 'PrestaShopBundle\Controller\Admin\CommonController::backOfficeSearchAction'
_legacy_controller: AdminSearch
_legacy_link: AdminSearch
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,9 @@ services:
prestashop.core.search.builder.typed_builder.product_combination_filters_builder:
class: 'PrestaShop\PrestaShop\Core\Search\Builder\TypedBuilder\ProductCombinationFiltersBuilder'
tags: [ 'core.typed_filters_builder' ]

prestashop.core.search.panel:
class: 'PrestaShop\PrestaShop\Core\Search\Row\HookableSearchPanel'
arguments:
[ '@prestashop.core.hook.dispatcher', '@translator' ]

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{#**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*#}

{% set enableSidebar = true %}
{% set layoutTitle = 'Search results'|trans({}, 'Admin.Global') %}

{% extends '@PrestaShop/Admin/layout.html.twig' %}

{% block content %}
{% if app.request.query.get('bo_query') %}
<h2>
1 result matches your query "joh".
</h2>
{% endif %}

{% block search_pannels %}
{{ include('@PrestaShop/Admin/Common/search_panel_row.html.twig', {'searchPanels': searchPanelCollections}) }}
{% endblock %}


{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{#**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*#}

<div class="row">
{% for searchPannel in searchPanels %}
<div class="col-lg-{% if searchPanels|length <= 2 %}6{% else %}4{% endif %}">
<div class="card">
<h3 class="card-header">
{{ searchPannel.title }}
</h3>


<div class="card-body">
<div class="form-group row">
<div class="col-sm input-container">
<a class="btn btn-default pointer" href="{{ searchPannel.link }}">
{{ searchPannel.buttonLabel }}
</a>
</div>
</div>
</div>

</div>
</div>
{% endfor %}
</div>