Skip to content

Commit 7bbda48

Browse files
authored
Refactor loops and fix analytics overview issues (#1137)
1 parent 2d79a0b commit 7bbda48

File tree

7 files changed

+13
-33
lines changed

7 files changed

+13
-33
lines changed

Block/Configuration.php

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -286,13 +286,7 @@ public function getConfiguration()
286286

287287
private function areCategoriesInFacets($facets)
288288
{
289-
foreach ($facets as $facet) {
290-
if ($facet['attribute'] === 'categories') {
291-
return true;
292-
}
293-
}
294-
295-
return false;
289+
return in_array('categories', array_column($facets, 'attribute'));
296290
}
297291

298292
private function getUrlTrackedParameters()
@@ -336,28 +330,16 @@ private function isLandingPage()
336330

337331
private function getLandingPageId()
338332
{
339-
if (!$this->isLandingPage()) {
340-
return '';
341-
}
342-
343-
return $this->getCurrentLandingPage()->getId();
333+
return $this->isLandingPage() ? $this->getCurrentLandingPage()->getId() : '';
344334
}
345335

346336
private function getLandingPageQuery()
347337
{
348-
if (!$this->isLandingPage()) {
349-
return '';
350-
}
351-
352-
return $this->getCurrentLandingPage()->getQuery();
338+
return $this->isLandingPage() ? $this->getCurrentLandingPage()->getQuery() : '';
353339
}
354340

355341
private function getLandingPageConfiguration()
356342
{
357-
if (!$this->isLandingPage()) {
358-
return json_encode([]);
359-
}
360-
361-
return $this->getCurrentLandingPage()->getConfiguration();
343+
return $this->isLandingPage() ? $this->getCurrentLandingPage()->getConfiguration() : json_encode([]);
362344
}
363345
}

Helper/AnalyticsHelper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ public function isAnalyticsApiEnabled()
323323
{
324324
$clientData = $this->getClientData();
325325

326-
return (bool) $clientData && isset($clientData['analytics_api']) ? $clientData['analytics_api'] : 0;
326+
return (bool) $clientData && isset($clientData['analytics_api']) ? $clientData['analytics_api'] : 1;
327327
}
328328

329329
public function isClickAnalyticsEnabled()
@@ -334,7 +334,7 @@ public function isClickAnalyticsEnabled()
334334

335335
$clientData = $this->getClientData();
336336

337-
return (bool) $clientData && isset($clientData['click_analytics']) ? $clientData['click_analytics'] : 0;
337+
return (bool) $clientData && isset($clientData['click_analytics']) ? $clientData['click_analytics'] : 1;
338338
}
339339

340340
/**

Helper/Entity/CategoryHelper.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,7 @@ public function getCategoryCollectionQuery($storeId, $categoryIds = null)
165165
$storeRootCategoryPath = sprintf('%d/%d', $this->getRootCategoryId(), $store->getRootCategoryId());
166166

167167
$unserializedCategorysAttrs = $this->getAdditionalAttributes($storeId);
168-
169-
$additionalAttr = [];
170-
foreach ($unserializedCategorysAttrs as $attr) {
171-
$additionalAttr[] = $attr['attribute'];
172-
}
168+
$additionalAttr = array_column($unserializedCategorysAttrs, 'attribute');
173169

174170
$categories = $this->categoryCollectionFactory->create()
175171
->distinct(true)

Model/Backend/EnableClickAnalytics.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function beforeSave()
6868

6969
if ($result) {
7070
$result = json_decode($result);
71-
if ($result->status === 401 && $result->message === 'Feature not available') {
71+
if ($result->status === 402) {
7272
throw new LocalizedException(
7373
__('Click & Conversion analytics are not supported on your current plan. Please refer to <a target="_blank" href="https://www.algolia.com/pricing/">Algolia\'s pricing page</a> for more details.')
7474
);

ViewModel/Adminhtml/Analytics/Overview.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,7 @@ public function getDailySearchData()
199199
$search['conversion'] = $this->getDateValue($conversion, $search['date'], 'rate');
200200
}
201201

202-
$date = $this->getBackendView()->getDateTime()->date($search['date']);
203-
$search['formatted'] = date('M, d', $date->getTimestamp());
202+
$search['formatted'] = date('M, d', strtotime($search['date']));
204203
}
205204

206205
return $searches;

view/adminhtml/templates/analytics/graph.phtml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
?>
44
<?php if (!empty($block->getAnalytics())) : ?>
55
<div id="algolia-analyatics-diagram"></div>
6-
76
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
87
<script type="text/javascript">
98
google.charts.load("current", {packages:['corechart']});

view/adminhtml/web/css/analytics.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@
7373
padding: 2rem;
7474
}
7575

76+
.algoliasearch-analytics-overview .section.popular-results {
77+
margin-left: 2%
78+
}
79+
7680
.algoliasearch-analytics-overview .analytics-footer {
7781
margin-top: 1.5rem;
7882
text-align: left;

0 commit comments

Comments
 (0)