forked from Smile-SA/elasticsuite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Analytics][Tracker] Feature Smile-SA#3340, add company_id and custom…
…er_group_id in tracking data
- Loading branch information
Showing
12 changed files
with
495 additions
and
6 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
src/module-elasticsuite-analytics/Block/Adminhtml/Report/CustomerGroupSelector.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?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\ElasticsuiteAnalytics | ||
* @author Vadym Honcharuk <[email protected]> | ||
* @copyright 2024 Smile | ||
* @license Open Software License ("OSL") v. 3.0 | ||
*/ | ||
namespace Smile\ElasticsuiteAnalytics\Block\Adminhtml\Report; | ||
|
||
use Magento\Framework\View\Element\Template; | ||
use Magento\Customer\Model\ResourceModel\Group\CollectionFactory; | ||
|
||
/** | ||
* Block used to display customer group selector in reports. | ||
* | ||
* @SuppressWarnings(PHPMD.CamelCasePropertyName) | ||
* | ||
* @category Smile | ||
* @package Smile\ElasticsuiteAnalytics | ||
* @author Vadym Honcharuk <[email protected]> | ||
*/ | ||
class CustomerGroupSelector extends Template | ||
{ | ||
/** | ||
* @var CollectionFactory | ||
*/ | ||
protected $customerGroupCollectionFactory; | ||
|
||
/** | ||
* CustomerGroupSelector constructor. | ||
* | ||
* @param Template\Context $context The context of the template. | ||
* @param CollectionFactory $customerGroupCollectionFactory Factory for creating customer group collection. | ||
* @param array $data Additional block data. | ||
*/ | ||
public function __construct( | ||
Template\Context $context, | ||
CollectionFactory $customerGroupCollectionFactory, | ||
array $data = [] | ||
) { | ||
$this->customerGroupCollectionFactory = $customerGroupCollectionFactory; | ||
parent::__construct($context, $data); | ||
} | ||
|
||
/** | ||
* Get customer groups in an option array format. | ||
* | ||
* @return array | ||
*/ | ||
public function getCustomerGroups() | ||
{ | ||
return $this->customerGroupCollectionFactory->create()->toOptionArray(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/module-elasticsuite-analytics/Model/Report/Event/CustomerGroupIdFilterQueryProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?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\ElasticsuiteAnalytics | ||
* @author Vadym Honcharuk <[email protected]> | ||
* @copyright 2024 Smile | ||
* @license Open Software License ("OSL") v. 3.0 | ||
*/ | ||
namespace Smile\ElasticsuiteAnalytics\Model\Report\Event; | ||
|
||
use Smile\ElasticsuiteAnalytics\Model\Report\QueryProviderInterface; | ||
use Smile\ElasticsuiteCore\Search\Request\QueryInterface; | ||
use Smile\ElasticsuiteCore\Search\Request\Query\QueryFactory; | ||
use Smile\ElasticsuiteAnalytics\Model\Report\Context; | ||
|
||
/** | ||
* Customer group id filter query provider. | ||
* | ||
* @category Smile | ||
* @package Smile\ElasticsuiteAnalytics | ||
*/ | ||
class CustomerGroupIdFilterQueryProvider implements QueryProviderInterface | ||
{ | ||
/** | ||
* @var QueryFactory | ||
*/ | ||
private $queryFactory; | ||
|
||
/** | ||
* @var Context | ||
*/ | ||
private $context; | ||
|
||
/** | ||
* DateFilterQueryProvider constructor. | ||
* | ||
* @param QueryFactory $queryFactory Query factory. | ||
* @param Context $context Report context. | ||
*/ | ||
public function __construct(QueryFactory $queryFactory, Context $context) | ||
{ | ||
$this->queryFactory = $queryFactory; | ||
$this->context = $context; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function getQuery() | ||
{ | ||
// Get customer group ID from the context. | ||
$customerGroupId = $this->context->getCustomerGroupId(); | ||
|
||
// Check if customer group ID is set and not 'all'. | ||
if ($customerGroupId !== 'all' && $customerGroupId !== null) { | ||
// Return a TERM query for the customer group ID. | ||
return $this->queryFactory->create( | ||
QueryInterface::TYPE_TERM, | ||
[ | ||
'field' => 'customer.group_id', | ||
'value' => (int) $customerGroupId, | ||
] | ||
); | ||
} | ||
|
||
// If 'all' is selected or no customer group ID is set, return null (no filtering). | ||
return null; | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
...module-elasticsuite-analytics/Model/Report/Session/CustomerGroupIdFilterQueryProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?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\ElasticsuiteAnalytics | ||
* @author Vadym Honcharuk <[email protected]> | ||
* @copyright 2024 Smile | ||
* @license Open Software License ("OSL") v. 3.0 | ||
*/ | ||
namespace Smile\ElasticsuiteAnalytics\Model\Report\Session; | ||
|
||
use Smile\ElasticsuiteAnalytics\Model\Report\QueryProviderInterface; | ||
use Smile\ElasticsuiteCore\Search\Request\QueryInterface; | ||
use Smile\ElasticsuiteCore\Search\Request\Query\QueryFactory; | ||
use Smile\ElasticsuiteAnalytics\Model\Report\Context; | ||
|
||
/** | ||
* Customer group id filter query provider. | ||
* | ||
* @category Smile | ||
* @package Smile\ElasticsuiteAnalytics | ||
*/ | ||
class CustomerGroupIdFilterQueryProvider implements QueryProviderInterface | ||
{ | ||
/** | ||
* @var QueryFactory | ||
*/ | ||
private $queryFactory; | ||
|
||
/** | ||
* @var Context | ||
*/ | ||
private $context; | ||
|
||
/** | ||
* CustomerGroupIdFilterQueryProvider constructor. | ||
* | ||
* @param QueryFactory $queryFactory Query factory. | ||
* @param Context $context Report context. | ||
*/ | ||
public function __construct(QueryFactory $queryFactory, Context $context) | ||
{ | ||
$this->queryFactory = $queryFactory; | ||
$this->context = $context; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function getQuery() | ||
{ | ||
// Get customer group ID from the context. | ||
$customerGroupId = $this->context->getCustomerGroupId(); | ||
|
||
// Check if customer group ID is set and not 'all'. | ||
if ($customerGroupId !== 'all' && $customerGroupId !== null) { | ||
// Return a TERM query for the customer group ID. | ||
return $this->queryFactory->create( | ||
QueryInterface::TYPE_BOOL, | ||
[ | ||
'must' => [ | ||
$this->queryFactory->create( | ||
QueryInterface::TYPE_TERM, | ||
[ | ||
'field' => 'customer_group_id', | ||
'value' => (int) $customerGroupId, | ||
] | ||
), | ||
], | ||
] | ||
); | ||
} | ||
|
||
// If 'all' is selected or no customer group ID is set, return null (no filtering). | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...dule-elasticsuite-analytics/view/adminhtml/templates/report/customer_group_selector.phtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?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\ElasticsuiteAnalytics | ||
* @author Vadym Honcharuk <[email protected]> | ||
* @copyright 2024 Smile | ||
* @license Open Software License ("OSL") v. 3.0 | ||
*/ | ||
?> | ||
|
||
<?php | ||
/** | ||
* @var Smile\ElasticsuiteAnalytics\Block\Adminhtml\Report\CustomerGroupSelector $block | ||
*/ | ||
$customerGroups = $block->getCustomerGroups(); | ||
?> | ||
<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="<?php echo $group['value']; ?>"><?php echo $group['label']; ?></option> | ||
<?php endforeach; ?> | ||
</select> | ||
</div> | ||
|
||
<script type="text/x-magento-init"> | ||
{ | ||
"*": { | ||
"Smile_ElasticsuiteAnalytics/js/report/customer-group-selector": {} | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.