Skip to content

Commit

Permalink
Merge branch '2.10.x' into 2.11.x
Browse files Browse the repository at this point in the history
  • Loading branch information
rbayet committed Feb 21, 2025
2 parents 37d987b + 8bcbde6 commit 6f58dd7
Show file tree
Hide file tree
Showing 16 changed files with 259 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Magento\Framework\Module\Manager as ModuleManager;
use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;
use Magento\Store\Model\ScopeInterface;
use Smile\ElasticsuiteAnalytics\Model\Report\Context as ReportContext;

/**
Expand All @@ -38,6 +39,13 @@ class CustomerCompanySelector extends Template
*/
const CONFIG_IS_B2B_COMPANY_ACTIVE_XPATH = 'btob/website_configuration/company_active';

/**
* Configuration path for enabling or disabling the Company filter.
*
* @var string
*/
const CONFIG_IS_COMPANY_FILTER_ACTIVE_XPATH = 'smile_elasticsuite_analytics/filters_configuration/company_enabled';

/**
* @var ScopeConfigInterface
*/
Expand Down Expand Up @@ -110,6 +118,19 @@ public function isCompanyEnabled()
);
}

/**
* Check if the Company filter should be displayed.
*
* @return bool
*/
public function isCompanyFilterEnabled(): bool
{
return $this->scopeConfig->isSetFlag(
self::CONFIG_IS_COMPANY_FILTER_ACTIVE_XPATH,
ScopeInterface::SCOPE_STORE
);
}

/**
* Get the list of companies if the Company feature is enabled.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
*/
namespace Smile\ElasticsuiteAnalytics\Block\Adminhtml\Report;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\View\Element\Template;
use Magento\Customer\Model\ResourceModel\Group\CollectionFactory;
use Magento\Store\Model\ScopeInterface;
use Smile\ElasticsuiteAnalytics\Model\Report\Context as ReportContext;

/**
Expand All @@ -28,6 +30,18 @@
*/
class CustomerGroupSelector extends Template
{
/**
* Configuration path for enabling or disabling the Customer group filter.
*
* @var string
*/
const CONFIG_IS_CUSTOMER_GROUP_FILTER_ACTIVE_XPATH = 'smile_elasticsuite_analytics/filters_configuration/customer_group_enabled';

/**
* @var ScopeConfigInterface
*/
protected ScopeConfigInterface $scopeConfig;

/**
* @var CollectionFactory
*/
Expand All @@ -41,22 +55,38 @@ class CustomerGroupSelector extends Template
/**
* CustomerGroupSelector constructor.
*
* @param Template\Context $context The context of the template.
* @param CollectionFactory $customerGroupCollectionFactory Factory for creating customer group collection.
* @param ReportContext $reportContext Report context.
* @param array $data Additional block data.
* @param Template\Context $context The context of the template.
* @param ScopeConfigInterface $scopeConfig Scope configuration.
* @param CollectionFactory $customerGroupCollectionFactory Factory for creating customer group collection.
* @param ReportContext $reportContext Report context.
* @param array $data Additional block data.
*/
public function __construct(
Template\Context $context,
ScopeConfigInterface $scopeConfig,
CollectionFactory $customerGroupCollectionFactory,
ReportContext $reportContext,
array $data = []
) {
$this->scopeConfig = $scopeConfig;
$this->customerGroupCollectionFactory = $customerGroupCollectionFactory;
$this->reportContext = $reportContext;
parent::__construct($context, $data);
}

/**
* Check if the Customer group filter should be displayed.
*
* @return bool
*/
public function isCustomerGroupFilterEnabled(): bool
{
return $this->scopeConfig->isSetFlag(
self::CONFIG_IS_CUSTOMER_GROUP_FILTER_ACTIVE_XPATH,
ScopeInterface::SCOPE_STORE
);
}

/**
* Get customer groups in an option array format.
*
Expand Down
12 changes: 12 additions & 0 deletions src/module-elasticsuite-analytics/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@
<comment><![CDATA[A warning will be displayed on the search usage dashboard if there are pending events older than this number of hours still in the events queue table.]]></comment>
</field>
</group>

<group id="filters_configuration" translate="label" type="text" sortOrder="30" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Filters configuration</label>
<field id="customer_group_enabled" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<label>Show customer group filter</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="company_enabled" translate="label" type="select" sortOrder="20" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<label>Show company filter</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
</group>
</section>
</system>
</config>
4 changes: 4 additions & 0 deletions src/module-elasticsuite-analytics/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
<pending_events>
<warn_after_hours>6</warn_after_hours>
</pending_events>
<filters_configuration>
<customer_group_enabled>1</customer_group_enabled>
<company_enabled>1</company_enabled>
</filters_configuration>
</smile_elasticsuite_analytics>
</default>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
$baseUrl = $block->getUrl('*/*/*', ['_current' => true, 'company_id' => '__company_id__']);
$companyId = $block->getCustomerCompanyId();
?>
<?php if ($block->isCompanyEnabled()): ?>
<?php if ($block->isCompanyEnabled() && $block->isCompanyFilterEnabled()): ?>
<?php $companies = $block->getCompaniesList(); ?>
<div class="customer-company-selector">
<label for="company_id"><?= __('Company:') ?></label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,24 @@ $customerGroups = $block->getCustomerGroups();
$customerGroupId = $block->getCurrentCustomerGroupId();
$baseUrl = $block->getUrl('*/*/*', ['_current' => true, 'customer_group' => '__customer_group__']);
?>
<div class="customer-group-selector">
<label for="customer_group"><?= __('Customer Group:');?></label>
<select id="customer_group" name="customer_group" class="admin__control-select">
<option value="all"><?= __('All Customer Groups');?></option>
<?php foreach ($customerGroups as $group): ?>
<option value="<?= $block->escapeHtmlAttr($group['value']); ?>" <?php if ($customerGroupId == $group['value']): ?> selected="selected"<?php endif; ?>><?= $block->escapeHtml($group['label']); ?></option>
<?php endforeach; ?>
</select>
</div>
<?php if ($block->isCustomerGroupFilterEnabled()): ?>
<div class="customer-group-selector">
<label for="customer_group"><?= __('Customer Group:');?></label>
<select id="customer_group" name="customer_group" class="admin__control-select">
<option value="all"><?= __('All Customer Groups');?></option>
<?php foreach ($customerGroups as $group): ?>
<option value="<?= $block->escapeHtmlAttr($group['value']); ?>" <?php if ($customerGroupId == $group['value']): ?> selected="selected"<?php endif; ?>><?= $block->escapeHtml($group['label']); ?></option>
<?php endforeach; ?>
</select>
</div>

<script type="text/x-magento-init">
{
"*": {
"customerGroupSelector": {
"baseUrl": "<?= $block->escapeJs($block->escapeUrl($baseUrl)) ?>"
}
<script type="text/x-magento-init">
{
"*": {
"customerGroupSelector": {
"baseUrl": "<?= $block->escapeJs($block->escapeUrl($baseUrl)) ?>"
}
}
}
}
</script>
</script>
<?php endif; ?>
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,16 @@
display: block;
}

.tooltip {
margin-right: 4rem;
}

.customer-group-selector {
color: #41362f;
float: left;
font-size: 1.3rem;
margin-top: .59rem;
margin-left: 4rem;
margin-right: 2rem;
}

.customer-group-selector label {
Expand All @@ -92,7 +96,6 @@
float: left;
font-size: 1.3rem;
margin-top: .59rem;
margin-left: 2rem;
}

.customer-company-selector label {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ interface CheckInterface
/**
* Status indicating that the health check has passed successfully.
*/
const STATUS_PASSED = 'success';
const STATUS_PASSED = 'passed';

/**
* Status indicating that the health check has detected a potential issue.
*/
const STATUS_FAILED = 'warning';
const STATUS_FAILED = 'failed';

/**
* Retrieve the unique identifier for the health check.
Expand All @@ -45,7 +45,7 @@ public function getDescription(): string;

/**
* Retrieve the status of the health check.
* Expected values: 'success', 'warning'.
* Expected values: 'passed', 'failed'.
*
* @return string
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
<?php
/**
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Smile ElasticSuite to newer
* versions in the future.
*
* @category Smile
* @package Smile\ElasticsuiteCore
* @author Vadym Honcharuk <vahonc@smile.fr>
* @copyright 2025 Smile
* @license Open Software License ("OSL") v. 3.0
*/

namespace Smile\ElasticsuiteCore\Model\Healthcheck;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\UrlInterface;
use Smile\ElasticsuiteCore\Api\Healthcheck\CheckInterface;

/**
* Checks that, verify if Magento is correctly configured to use Elasticsuite as the default search engine.
*
* @category Smile
* @package Smile\ElasticsuiteCore
*/
class SearchEngineConfigCheck extends AbstractCheck
{
/**
* Configuration path for the search engine setting.
*/
private const CONFIG_PATH_SEARCH_ENGINE = 'catalog/search/engine';

/**
* Expected value for Elasticsuite.
*/
private const ELASTICSUITE_ENGINE = 'elasticsuite';

/**
* Route to Stores -> Configuration section.
*/
private const ROUTE_SYSTEM_CONFIG = 'adminhtml/system_config/edit';

/**
* Anchor for Stores -> Configuration -> Catalog -> Catalog Search.
*/
private const ANCHOR_CATALOG_SEARCH_CONFIG = 'catalog_search-link';

/**
* @var ScopeConfigInterface
*/
private ScopeConfigInterface $scopeConfig;

/**
* Constructor.
*
* @param ScopeConfigInterface $scopeConfig Scope configuration.
* @param UrlInterface $urlBuilder URL builder.
* @param int $sortOrder Sort order (default: 50).
*/
public function __construct(
ScopeConfigInterface $scopeConfig,
UrlInterface $urlBuilder,
int $sortOrder = 50
) {
parent::__construct($urlBuilder, $sortOrder);
$this->scopeConfig = $scopeConfig;
}

/**
* {@inheritDoc}
*/
public function getIdentifier(): string
{
return 'search_engine_config_check';
}

/**
* {@inheritDoc}
*/
public function getDescription(): string
{
$description = __('Magento is correctly configured to use Elasticsuite as its search engine.');

if ($this->getStatus() === CheckInterface::STATUS_FAILED) {
// @codingStandardsIgnoreStart
$description = implode(
'<br />',
[
__(
'Magento is not configured to use Elasticsuite as its search engine.'
),
__(
'Please click <a href="%1"><strong>here</strong></a> to head to the <strong>Catalog Search Configuration</strong> and select ElasticSuite in the <strong>Search Engine</strong> field.',
$this->getCatalogSearchConfigUrl()
),
]
);
// @codingStandardsIgnoreEnd
}

return $description;
}

/**
* {@inheritDoc}
*/
public function getStatus(): string
{
$configuredEngine = $this->scopeConfig->getValue(self::CONFIG_PATH_SEARCH_ENGINE);

return ($configuredEngine === self::ELASTICSUITE_ENGINE) ? CheckInterface::STATUS_PASSED : CheckInterface::STATUS_FAILED;
}

/**
* Get URL to the Catalog Search Configuration page.
*
* @return string
*/
private function getCatalogSearchConfigUrl(): string
{
return $this->urlBuilder->getUrl(
self::ROUTE_SYSTEM_CONFIG,
['section' => 'catalog', '_fragment' => self::ANCHOR_CATALOG_SEARCH_CONFIG]
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function getText()

// @codingStandardsIgnoreStart
return __(
'You have <strong>%1 health checks</strong> in <strong>Warning</strong> state. '
'You have <strong>%1 health checks</strong> in <strong>Failed</strong> state. '
. 'We invite you to head to the <a href="%2"><strong>Elasticsuite Healthcheck</strong></a> page to get more details and to see how to fix them.',
$issuesCount,
$this->getElasticsuiteHealthcheckUrl()
Expand Down
1 change: 1 addition & 0 deletions src/module-elasticsuite-core/etc/adminhtml/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<item name="replicas_config_check" xsi:type="object">Smile\ElasticsuiteCore\Model\Healthcheck\ReplicasConfigCheck</item>
<item name="packages_version_check" xsi:type="object">Smile\ElasticsuiteCore\Model\Healthcheck\PackageVersionsMismatchCheck</item>
<item name="hyva_compatibility_check" xsi:type="object">Smile\ElasticsuiteCore\Model\Healthcheck\HyvaCompatibilityCheck</item>
<item name="search_engine_config_check" xsi:type="object">Smile\ElasticsuiteCore\Model\Healthcheck\SearchEngineConfigCheck</item>
</argument>
</arguments>
</type>
Expand Down
Loading

0 comments on commit 6f58dd7

Please sign in to comment.