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

Feature search manual sort #708

Merged
merged 13 commits into from
Jan 24, 2018
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
use Smile\ElasticsuiteCatalogOptimizer\Api\Data\OptimizerInterfaceFactory;
use Smile\ElasticsuiteCatalogOptimizer\Model\Optimizer\PreviewFactory;
use Smile\ElasticsuiteCore\Api\Search\Request\ContainerConfigurationInterface;
use Smile\ElasticsuiteCore\Search\Request\ContainerConfiguration;
use Smile\ElasticsuiteCore\Search\Request\ContainerConfigurationFactory;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php
/**
* DISCLAIMER
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future.
*
* @category Smile
* @package Smile\ElasticsuiteCatalog
* @author Aurelien FOUCRET <aurelien.foucret@smile.fr>
* @copyright 2018 Smile
* @license Open Software License ("OSL") v. 3.0
*/

namespace Smile\ElasticsuiteCatalog\Block\Adminhtml\Search\Term\Edit;

use Magento\Framework\View\Element\AbstractBlock;

/**
* Add the merchandiser button in the search term form.
*
* @category Smile
* @package Smile\ElasticsuiteCatalog
* @author Aurelien FOUCRET <aurelien.foucret@smile.fr>
*/
class Preview extends \Magento\Framework\View\Element\AbstractBlock
{
/**
* @var \Magento\Backend\Block\Widget\Button\ButtonList
*/
private $buttonList;

/**
* @var \Magento\Backend\Model\UrlInterface
*/
private $urlBuilder;

/**
* Constructor.
*
* @param \Magento\Backend\Block\Widget\Context $context Block context.
* @param \Magento\Backend\Model\UrlInterface $urlBuilder URL Builder.
* @param array $data Block data.
*/
public function __construct(
\Magento\Backend\Block\Widget\Context $context,
\Magento\Backend\Model\UrlInterface $urlBuilder,
array $data = []
) {
$this->buttonList = $context->getButtonList();
$this->urlBuilder = $urlBuilder;
parent::__construct($context, $data);
}

/**
* @SuppressWarnings(PHPMD.CamelCaseMethodName)
*
* {@inheritDoc}
*/
protected function _construct()
{
parent::_construct();

$this->buttonList->add(
'merchandiser-button',
[
'label' => __('Merchandiser'),
'class' => 'delete',
'onclick' => "setLocation('" . $this->getMerchandiserUrl() . "')",
]
);
}

/**
* Retrieve merchandiser button URL.
*
* @return string
*/
private function getMerchandiserUrl()
{
$queryId = $this->getRequest()->getParam('id');

return $this->urlBuilder->getUrl('search/term_merchandiser/edit', ['id' => $queryId]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
/**
* DISCLAIMER
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future.
*
* @category Smile
* @package Smile\ElasticsuiteCatalog
* @author Aurelien FOUCRET <aurelien.foucret@smile.fr>
* @copyright 2018 Smile
* @license Open Software License ("OSL") v. 3.0
*/
namespace Smile\ElasticsuiteCatalog\Block\Adminhtml\Search\Term\Merchandiser\Edit;

use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;

/**
* Form back button.
*
* @category Smile
* @package Smile\ElasticsuiteCatalog
* @author Aurelien FOUCRET <aurelien.foucret@smile.fr>
*/
class BackButton extends GenericButton implements ButtonProviderInterface
{
/**
* {@inheritDoc}
*/
public function getButtonData()
{
$data = [];
if ($this->canRender('reset')) {
$data = [
'label' => __('Back'),
'class' => 'back',
'on_click' => "setLocation('" . $this->getQueryUrl() . "');",
'sort_order' => 10,
];
}

return $data;
}

/**
* Get back URL.
*
* @return string
*/
public function getQueryUrl()
{
return $this->getUrl('search/term/edit', ['id' => $this->getQueryId()]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php
/**
* DISCLAIMER
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future.
*
* @category Smile
* @package Smile\ElasticsuiteCatalog
* @author Aurelien FOUCRET <aurelien.foucret@smile.fr>
* @copyright 2018 Smile
* @license Open Software License ("OSL") v. 3.0
*/
namespace Smile\ElasticsuiteCatalog\Block\Adminhtml\Search\Term\Merchandiser\Edit;

/**
* Generic form button.
*
* @category Smile
* @package Smile\ElasticsuiteCatalog
* @author Aurelien FOUCRET <aurelien.foucret@smile.fr>
*/
class GenericButton
{
/**
* Url Builder
*
* @var \Magento\Framework\UrlInterface
*/
private $urlBuilder;

/**
* Registry
*
* @var \Magento\Framework\Registry
*/
private $registry;

/**
* Constructor
*
* @param \Magento\Backend\Block\Widget\Context $context Block context.
* @param \Magento\Framework\Registry $registry Registry.
*/
public function __construct(
\Magento\Backend\Block\Widget\Context $context,
\Magento\Framework\Registry $registry
) {
$this->urlBuilder = $context->getUrlBuilder();
$this->registry = $registry;
}

/**
* Return the current query id.
*
* @return int|null
*/
public function getQueryId()
{
$query = $this->registry->registry('current_query');

return $query ? $query->getId() : null;
}

/**
* Generate url by route and parameters
*
* @param string $route Route.
* @param array $params Route params.
*
* @return string
*/
public function getUrl($route = '', $params = [])
{
return $this->urlBuilder->getUrl($route, $params);
}

/**
* Check where button can be rendered
*
* @param string $name Button name.
*
* @return string
*/
public function canRender($name)
{
return $name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* DISCLAIMER
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future.
*
* @category Smile
* @package Smile\ElasticsuiteCatalog
* @author Aurelien FOUCRET <aurelien.foucret@smile.fr>
* @copyright 2018 Smile
* @license Open Software License ("OSL") v. 3.0
*/
namespace Smile\ElasticsuiteCatalog\Block\Adminhtml\Search\Term\Merchandiser\Edit;

use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;

/**
* Reset button.
*
* @category Smile
* @package Smile\ElasticsuiteCatalog
* @author Aurelien FOUCRET <aurelien.foucret@smile.fr>
*/
class ResetButton extends GenericButton implements ButtonProviderInterface
{
/**
* {@inheritDoc}
*/
public function getButtonData()
{
$data = [];
if ($this->canRender('reset')) {
$data = [
'label' => __('Reset'),
'class' => 'reset',
'on_click' => 'location.reload()',
'sort_order' => 30,
];
}

return $data;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* DISCLAIMER
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future.
*
* @category Smile
* @package Smile\ElasticsuiteCatalog
* @author Aurelien FOUCRET <aurelien.foucret@smile.fr>
* @copyright 2018 Smile
* @license Open Software License ("OSL") v. 3.0
*/
namespace Smile\ElasticsuiteCatalog\Block\Adminhtml\Search\Term\Merchandiser\Edit;

use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;

/**
* Save and continue button.
*
* @category Smile
* @package Smile\ElasticsuiteCatalog
* @author Aurelien FOUCRET <aurelien.foucret@smile.fr>
*/
class SaveAndContinueButton extends GenericButton implements ButtonProviderInterface
{
/**
* {@inheritDoc}
*/
public function getButtonData()
{
$data = [];
if ($this->canRender('save_and_continue_edit')) {
$data = [
'label' => __('Save and Continue Edit'),
'class' => 'save',
'on_click' => '',
'sort_order' => 90,
];
}

return $data;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* DISCLAIMER
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future.
*
* @category Smile
* @package Smile\ElasticsuiteCatalog
* @author Aurelien FOUCRET <aurelien.foucret@smile.fr>
* @copyright 2018 Smile
* @license Open Software License ("OSL") v. 3.0
*/
namespace Smile\ElasticsuiteCatalog\Block\Adminhtml\Search\Term\Merchandiser\Edit;

use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;

/**
* Save button.
*
* @category Smile
* @package Smile\ElasticsuiteCatalog
* @author Aurelien FOUCRET <aurelien.foucret@smile.fr>
*/
class SaveButton extends GenericButton implements ButtonProviderInterface
{
/**
* @return array
* @codeCoverageIgnore
*/
public function getButtonData()
{
$data = [];
if ($this->canRender('save')) {
$data = [
'label' => __('Save'),
'class' => 'save primary',
'on_click' => '',
];
}

return $data;
}
}
Loading