Skip to content

Commit

Permalink
GAS-2317 (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
hellward authored Nov 25, 2024
1 parent 24ffcdd commit 0ce29d2
Show file tree
Hide file tree
Showing 194 changed files with 62,190 additions and 47 deletions.
38 changes: 38 additions & 0 deletions Block/Adminhtml/SearchIndex/Assign/SaveButton.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Synerise\Integration\Block\Adminhtml\SearchIndex\Assign;

use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
use Synerise\Integration\Block\Adminhtml\SearchIndex\GenericButton;

class SaveButton extends GenericButton implements ButtonProviderInterface
{
/**
* Get button data
*
* @return array
*/
public function getButtonData()
{
return [
'label' => __('Save'),
'class' => 'save primary',
'data_attribute' => [
'mage-init' => [
'buttonAdapter' => [
'actions' => [
[
'targetName' => 'synerise_searchindex_assign_form.synerise_searchindex_assign_form',
'actionName' => 'save',
'params' => [
true,
['store_id' => $this->context->getRequest()->getParam('store')]
]
],
],
],
],
]
];
}
}
33 changes: 33 additions & 0 deletions Block/Adminhtml/SearchIndex/BackButton.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Synerise\Integration\Block\Adminhtml\SearchIndex;

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

class BackButton extends GenericButton implements ButtonProviderInterface
{
/**
* Get button data
*
* @return array
*/
public function getButtonData()
{
return [
'label' => __('Back'),
'on_click' => sprintf("location.href = '%s';", $this->getBackUrl()),
'class' => 'back',
'sort_order' => 10,
];
}

/**
* Get URL for back (reset) button
*
* @return string
*/
public function getBackUrl()
{
return $this->getUrl('*/*/');
}
}
34 changes: 34 additions & 0 deletions Block/Adminhtml/SearchIndex/GenericButton.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Synerise\Integration\Block\Adminhtml\SearchIndex;

use Magento\Backend\Block\Widget\Context;

class GenericButton
{
/**
* @var Context
*/
protected $context;

/**
* @param Context $context
*/
public function __construct(
Context $context
) {
$this->context = $context;
}

/**
* Generate url by route and parameters
*
* @param string $route
* @param array $params
* @return string
*/
public function getUrl($route = '', $params = []): string
{
return $this->context->getUrlBuilder()->getUrl($route, $params);
}
}
35 changes: 35 additions & 0 deletions Block/Adminhtml/SearchIndex/Setup/SaveButton.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Synerise\Integration\Block\Adminhtml\SearchIndex\Setup;

use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
use Synerise\Integration\Block\Adminhtml\SearchIndex\GenericButton;

class SaveButton extends GenericButton implements ButtonProviderInterface
{
/**
* Get button data
*
* @return array
*/
public function getButtonData()
{
return [
'label' => __('Save'),
'class' => 'save primary',
'data_attribute' => [
'mage-init' => [
'buttonAdapter' => [
'actions' => [
[
'targetName' => 'synerise_searchindex_setup_form.synerise_searchindex_setup_form',
'actionName' => 'save',
'params' => [false]
],
],
],
],
]
];
}
}
35 changes: 35 additions & 0 deletions Block/Adminhtml/SearchIndex/Store/ApplyButton.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Synerise\Integration\Block\Adminhtml\SearchIndex\Store;

use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
use Synerise\Integration\Block\Adminhtml\SearchIndex\GenericButton;

class ApplyButton extends GenericButton implements ButtonProviderInterface
{
/**
* Get button data
*
* @return array
*/
public function getButtonData()
{
return [
'label' => __('Apply'),
'class' => 'save primary',
'data_attribute' => [
'mage-init' => [
'buttonAdapter' => [
'actions' => [
[
'targetName' => 'synerise_searchindex_store_form.synerise_searchindex_store_form',
'actionName' => 'save',
'params' => [true]
],
],
],
],
]
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace Synerise\Integration\Block\ElasticsuiteSwatches\Navigation\Renderer\Swatches;

use Magento\Catalog\Model\Layer\Resolver;
use Magento\Catalog\Model\ResourceModel\Layer\Filter\AttributeFactory;
use Magento\Eav\Model\Entity\Attribute;
use Magento\Eav\Model\Entity\Attribute\Option;
use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;
use Magento\Swatches\Helper\Data;
use Magento\Swatches\Helper\Media;
use Magento\Theme\Block\Html\Pager;

if (!class_exists('Smile\ElasticsuiteSwatches\Block\Navigation\Renderer\Swatches\RenderLayered')) {
class RenderLayered extends Template {}
} else {
class RenderLayered extends \Smile\ElasticsuiteSwatches\Block\Navigation\Renderer\Swatches\RenderLayered
{
public const COLLECTION_CLASS = 'Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\Fulltext\Collection';

public function __construct(
Context $context,
Attribute $eavAttribute,
AttributeFactory $layerAttribute,
Data $swatchHelper,
Media $mediaHelper,
Resolver $layerResolver,
array $data = [],
?Pager $htmlPagerBlock = null
) {
$layer = $layerResolver->get();
$this->canExecute = $layer && is_a($layer->getProductCollection(), self::COLLECTION_CLASS);

parent::__construct($context, $eavAttribute, $layerAttribute, $swatchHelper, $mediaHelper, $data, $htmlPagerBlock);
}

/**
* {@inheritDoc}
*/
protected function getFilterOption(array $filterItems, Option $swatchOption)
{
if ($this->canExecute) {
return parent::getFilterOption($filterItems, $swatchOption);
}

$filterItem = $this->getFilterItemById($filterItems, $swatchOption->getValue());
if ($filterItem && $this->isOptionVisible($filterItem)) {
return $this->getOptionViewData($filterItem, $swatchOption);
}

return false;
}
}
}
51 changes: 51 additions & 0 deletions Block/ElasticsuiteTracker/Variables/Page/Search.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace Synerise\Integration\Block\ElasticsuiteTracker\Variables\Page;

use Magento\Framework\View\Element\Template;

if (!class_exists('Smile\ElasticsuiteTracker\Block\Variables\Page\Search')) {
class Search extends Template
{ }
} else {
class Search extends \Smile\ElasticsuiteTracker\Block\Variables\Page\Search
{
public const COLLECTION_CLASS = 'Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\Fulltext\Collection';

public function __construct(
Template\Context $context,
\Magento\Framework\Json\Helper\Data $jsonHelper,
\Smile\ElasticsuiteTracker\Helper\Data $trackerHelper,
\Magento\Framework\Registry $registry,
\Magento\Catalog\Model\Layer\Resolver $layerResolver,
\Magento\CatalogSearch\Helper\Data $catalogSearchData,
\Smile\ElasticsuiteCore\Api\Search\ContextInterface $searchContext,
array $data = []
) {
$layer = $layerResolver->get();
$this->canExecute = $layer && is_a($layer->getProductCollection(), self::COLLECTION_CLASS);

parent::__construct(
$context,
$jsonHelper,
$trackerHelper,
$registry,
$layerResolver,
$catalogSearchData,
$searchContext,
$data
);
}

/**
* @inheritDoc
*/
public function getVariables()
{
if ($this->canExecute) {
return parent::getVariables();
}
return [];
}
}
}
99 changes: 99 additions & 0 deletions Controller/Adminhtml/SearchIndex/Assign.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php

namespace Synerise\Integration\Controller\Adminhtml\SearchIndex;

use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\View\Result\PageFactory;
use Synerise\Integration\Helper\Logger;
use Synerise\Integration\Model\SearchIndex\ErrorMessage;
use Synerise\Integration\Search\Container\Indices;
use Synerise\ItemsSearchConfigApiClient\ApiException;

class Assign extends Action
{
/**
* Authorization level
*/
public const ADMIN_RESOURCE = 'Synerise_Integration::search_index_setup';

/**
* @var PageFactory
*/
protected $resultPageFactory;

/**
* @var ErrorMessage
*/
protected $errorMessage;

/**
* @var Indices
*/
protected $indices;

/**
* @var Logger
*/
protected $logger;

/**
* @param Context $context
* @param PageFactory $resultPageFactory
* @param ErrorMessage $errorMessage
* @param Indices $indices
* @param Logger $logger
*/
public function __construct(
Action\Context $context,
PageFactory $resultPageFactory,
ErrorMessage $errorMessage,
Indices $indices,
Logger $logger
) {
$this->resultPageFactory = $resultPageFactory;
$this->errorMessage = $errorMessage;
$this->indices = $indices;
$this->logger = $logger;

parent::__construct($context);
}

/**
* Edit Search Index
*
* @return \Magento\Framework\Controller\ResultInterface
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function execute()
{
if ($storeId = $this->getRequest()->getParam('store')) {
try {
$this->indices->getIndices($storeId);

$resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
$resultPage->getConfig()->getTitle()->prepend(__('Assign Search Index (Store: %1)', $storeId));
return $resultPage;
} catch (ApiException $exception) {
$config = $this->errorMessage->getMessageFromConfigApiException($exception);
if (isset($config['url'])) {
$this->messageManager->addComplexErrorMessage(
'messageWithUrl',
[
'message' => $config['base_message'] . ' ' . $config['url_message'],
'url' => $config['url'],
]
);
} else {
$this->messageManager->addErrorMessage($this->errorMessage->getDefaultMessage());
}
} catch (\Exception $exception) {
$this->logger->error($exception);
$this->messageManager->addErrorMessage($this->errorMessage->getDefaultMessage());
}
}

return $this->resultRedirectFactory->create()->setPath('*/*');
}
}
Loading

0 comments on commit 0ce29d2

Please sign in to comment.