Skip to content

Commit 9b8b6f4

Browse files
authored
Merge pull request #1459 from algolia/update/MAGE-804
MAGE-804 Added configuration for analytics region
2 parents 8a747d2 + aaf7269 commit 9b8b6f4

File tree

5 files changed

+42
-6
lines changed

5 files changed

+42
-6
lines changed

Helper/AnalyticsHelper.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ class AnalyticsHelper
5151
private $analyticsConfig;
5252

5353
/**
54-
* Can be changed through DI
54+
* Region can be modified via the Magento configuration
5555
*
5656
* @var string
5757
*/
58-
private $region;
58+
protected $region;
5959

6060
/**
6161
* @param AlgoliaHelper $algoliaHelper
@@ -77,7 +77,7 @@ public function __construct(
7777
$this->entityHelper = $entityHelper;
7878

7979
$this->logger = $logger;
80-
$this->region = $region;
80+
$this->region = $this->configHelper->getAnalyticsRegion();
8181
}
8282

8383
private function setupAnalyticsClient()
@@ -86,6 +86,7 @@ private function setupAnalyticsClient()
8686
return;
8787
}
8888

89+
8990
$this->analyticsClient = AnalyticsClient::create(
9091
$this->configHelper->getApplicationID(),
9192
$this->configHelper->getAPIKey(),

Helper/ConfigHelper.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ class ConfigHelper
100100
'algoliasearch_advanced/advanced/backend_rendering_allowed_user_agents';
101101
public const NON_CASTABLE_ATTRIBUTES = 'algoliasearch_advanced/advanced/non_castable_attributes';
102102
public const MAX_RECORD_SIZE_LIMIT = 'algoliasearch_advanced/advanced/max_record_size_limit';
103+
public const ANALYTICS_REGION = 'algoliasearch_advanced/advanced/analytics_region';
103104
public const CONNECTION_TIMEOUT = 'algoliasearch_advanced/advanced/connection_timeout';
104105
public const READ_TIMEOUT = 'algoliasearch_advanced/advanced/read_timeout';
105106
public const WRITE_TIMEOUT = 'algoliasearch_advanced/advanced/write_timeout';
@@ -1715,6 +1716,19 @@ public function getMaxRecordSizeLimit($storeId = null)
17151716
);
17161717
}
17171718

1719+
/**
1720+
* @param $storeId
1721+
* @return string
1722+
*/
1723+
public function getAnalyticsRegion($storeId = null)
1724+
{
1725+
return $this->configInterface->getValue(
1726+
self::ANALYTICS_REGION,
1727+
ScopeInterface::SCOPE_STORE,
1728+
$storeId
1729+
);
1730+
}
1731+
17181732
/**
17191733
* @param $storeId
17201734
* @return bool

Model/Source/AnalyticsRegion.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Algolia\AlgoliaSearch\Model\Source;
4+
5+
use Magento\Framework\Option\ArrayInterface;
6+
7+
class AnalyticsRegion implements ArrayInterface
8+
{
9+
public function toOptionArray()
10+
{
11+
return [
12+
['value' => 'us', 'label' => __('United States')],
13+
['value' => 'de', 'label' => __('Europe (Germany)')],
14+
];
15+
}
16+
}

etc/adminhtml/system.xml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,13 @@
111111
</field>
112112
</group>
113113
<group id="algolia_cookie_configuration" translate="label" type="text" sortOrder="70" showInDefault="1" showInWebsite="1" showInStore="1">
114-
<label>Algolia Cookie Configuration</label>
114+
<label>Algolia Cookie Configuration</label>
115115
<attribute type="expanded">1</attribute>
116116
<comment>
117117
<![CDATA[
118118
If your Magento cookie settings, specifically <b>General > Web > Default Cookie Settings > Cookie Restriction Mode</b> is set to "No," we will consider it as Implicit Cookie Consent. In this case, the useCookie will be set to True by default for all insight events. Conversely, if <b>Cookie Restriction Mode is set to 'Yes,'</b> Insight events will not be allowed without explicit cookie consent.
119119
]]>
120-
</comment>
120+
</comment>
121121
<field id="default_consent_cookie_name" translate="label comment" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
122122
<label>Consent Cookie Name</label>
123123
<comment>
@@ -1170,7 +1170,7 @@
11701170
<field id="customer_groups_enable" translate="label comment" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
11711171
<label>Enable Customer Groups</label>
11721172
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
1173-
<backend_model>Algolia\AlgoliaSearch\Model\Backend\Replica</backend_model>
1173+
<backend_model>Algolia\AlgoliaSearch\Model\Backend\Replica</backend_model>
11741174
<comment>
11751175
<![CDATA[
11761176
Do you want to take into account customer groups and display the price of the logged-in group instead of the default price?
@@ -1259,6 +1259,10 @@
12591259
If your Algolia plan allows a higher record size limit, you can customize the record size limit.]]>
12601260
</comment>
12611261
</field>
1262+
<field id="analytics_region" translate="label comment" type="select" sortOrder="96" showInDefault="1">
1263+
<label>Analytics Region</label>
1264+
<source_model>Algolia\AlgoliaSearch\Model\Source\AnalyticsRegion</source_model>
1265+
</field>
12621266
<field id="connection_timeout" translate="label comment" type="text" sortOrder="100" showInDefault="1">
12631267
<label>Connection Timeout (In Seconds)</label>
12641268
</field>

etc/config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
<algoliasearch_advanced>
8282
<advanced>
8383
<max_record_size_limit>10000</max_record_size_limit>
84+
<analytics_region>us</analytics_region>
8485
<connection_timeout>2</connection_timeout>
8586
<read_timeout>30</read_timeout>
8687
<write_timeout>30</write_timeout>

0 commit comments

Comments
 (0)