Skip to content

Commit bd97983

Browse files
committed
Merge pull request #5690 in SW/shopware from sw-20188/5.3/improve-device-statistic to 5.3
* commit '1d7086815a19eb5d062773896d13f9df29b5dd0d': SW-20188 - Fix mobile statistic, improve device configurability
2 parents 15bf6de + 1d70868 commit bd97983

File tree

5 files changed

+68
-35
lines changed

5 files changed

+68
-35
lines changed

engine/Shopware/Controllers/Widgets/Index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Shopware_Controllers_Widgets_Index extends Enlight_Controller_Action
3232
*/
3333
public function preDispatch()
3434
{
35-
if ($this->Request()->getActionName() == 'refreshStatistic') {
35+
if ($this->Request()->getActionName() === 'refreshStatistic') {
3636
$this->Front()->Plugins()->ViewRenderer()->setNoRender();
3737
}
3838
}

engine/Shopware/Plugins/Default/Frontend/Statistics/Bootstrap.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,10 @@ public function checkIsBot($userAgent)
116116
}
117117

118118
/**
119-
* @param Enlight_Controller_Request_Request $request
120-
* @param $response
119+
* @param Enlight_Controller_Request_Request $request
120+
* @param Enlight_Controller_Response_ResponseHttp $response
121+
*
122+
* @throws \Exception
121123
*/
122124
public function updateLog($request, $response)
123125
{
@@ -194,7 +196,11 @@ public function cleanupStatistic()
194196
/**
195197
* Refresh current users
196198
*
199+
*
197200
* @param \Enlight_Controller_Request_Request $request
201+
*
202+
* @throws \Exception
203+
* @throws \Zend_Db_Adapter_Exception
198204
*/
199205
public function refreshCurrentUsers(Enlight_Controller_Request_Request $request)
200206
{
@@ -212,7 +218,10 @@ public function refreshCurrentUsers(Enlight_Controller_Request_Request $request)
212218
/**
213219
* Refresh visitor log
214220
*
221+
*
215222
* @param Enlight_Controller_Request_Request $request
223+
*
224+
* @throws \Exception
216225
*/
217226
public function refreshLog(Enlight_Controller_Request_Request $request)
218227
{
@@ -250,8 +259,7 @@ public function refreshLog(Enlight_Controller_Request_Request $request)
250259
$isNewRecord = true;
251260
}
252261

253-
$sql = 'SELECT 1 FROM s_statistics_pool WHERE datum = CURDATE() AND remoteaddr = ?';
254-
$result = Shopware()->Db()->fetchOne($sql, [$ip]);
262+
$result = Shopware()->Db()->fetchOne('SELECT 1 FROM s_statistics_pool WHERE datum = CURDATE() AND remoteaddr = ?', [$ip]);
255263
if (empty($result)) {
256264
$sql = 'INSERT INTO s_statistics_pool (`remoteaddr`, `datum`) VALUES (?, NOW())';
257265
Shopware()->Db()->query($sql, [$ip]);
@@ -310,7 +318,7 @@ public function refreshArticleImpression($request)
310318
}
311319
$shopId = Shopware()->Shop()->getId();
312320
/** @var $repository \Shopware\Models\Tracking\Repository */
313-
$repository = Shopware()->Models()->getRepository('Shopware\Models\Tracking\ArticleImpression');
321+
$repository = Shopware()->Models()->getRepository(\Shopware\Models\Tracking\ArticleImpression::class);
314322
$articleImpressionQuery = $repository->getArticleImpressionQuery($articleId, $shopId, null, $deviceType);
315323
/** @var $articleImpression \Shopware\Models\Tracking\ArticleImpression */
316324
$articleImpression = $articleImpressionQuery->getOneOrNullResult();

themes/Frontend/Bare/frontend/index/index.tpl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,12 @@
167167
asyncCallbacks.push(callback);
168168
};
169169
170+
var statisticDevices = [
171+
{ device: 'mobile', enter: 0, exit: 767 },
172+
{ device: 'tablet', enter: 768, exit: 1259 },
173+
{ device: 'desktop', enter: 1260, exit: 5160 }
174+
];
175+
170176
var controller = controller || {ldelim}
171177
'vat_check_enabled': '{config name='vatcheckendabled'}',
172178
'vat_check_required': '{config name='vatcheckrequired'}',

themes/Frontend/Bare/widgets/index/statistic_include.tpl

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,27 @@
2121
url += '&articleId=' + encodeURI("{$sArticle.articleID}");
2222
{/if}
2323
24-
var statisticRequest = document.getElementById('refresh-statistic');
25-
statisticRequest.setAttribute('src', url);
24+
{* Early simple device detection for statistics, duplicated in StateManager for resizes *}
25+
if (document.cookie.indexOf('x-ua-device') === -1) {
26+
var i = 0,
27+
device = 'desktop',
28+
width = window.innerWidth,
29+
breakpoints = window.statisticDevices;
2630
31+
if (typeof width !== 'number') {
32+
width = (document.documentElement.clientWidth !== 0) ? document.documentElement.clientWidth : document.body.clientWidth;
33+
}
34+
35+
for (; i < breakpoints.length; i++) {
36+
if (width >= ~~(breakpoints[i].enter) && width <= ~~(breakpoints[i].exit)) {
37+
device = breakpoints[i].device;
38+
}
39+
}
40+
41+
document.cookie = 'x-ua-device=' + device + '; path=/';
42+
}
43+
44+
document.getElementById('refresh-statistic').setAttribute('src', url);
2745
})(window, document);
2846
</script>
29-
{/block}
47+
{/block}

themes/Frontend/Responsive/frontend/_public/src/js/jquery.state-manager.js

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -259,21 +259,21 @@
259259
* many parameters.
260260
*/
261261
switch (args.length) {
262-
case 0:
263-
while (++i < len) (event = eventList[i]).callback.call(event.context);
264-
return me;
265-
case 1:
266-
while (++i < len) (event = eventList[i]).callback.call(event.context, a1);
267-
return me;
268-
case 2:
269-
while (++i < len) (event = eventList[i]).callback.call(event.context, a1, a2);
270-
return me;
271-
case 3:
272-
while (++i < len) (event = eventList[i]).callback.call(event.context, a1, a2, a3);
273-
return me;
274-
default:
275-
while (++i < len) (event = eventList[i]).callback.apply(event.context, args);
276-
return me;
262+
case 0:
263+
while (++i < len) (event = eventList[i]).callback.call(event.context);
264+
return me;
265+
case 1:
266+
while (++i < len) (event = eventList[i]).callback.call(event.context, a1);
267+
return me;
268+
case 2:
269+
while (++i < len) (event = eventList[i]).callback.call(event.context, a1, a2);
270+
return me;
271+
case 3:
272+
while (++i < len) (event = eventList[i]).callback.call(event.context, a1, a2, a3);
273+
return me;
274+
default:
275+
while (++i < len) (event = eventList[i]).callback.apply(event.context, args);
276+
return me;
277277
}
278278
},
279279

@@ -1292,21 +1292,22 @@
12921292
},
12931293

12941294
_getCurrentDevice: function() {
1295-
var me = this,
1296-
devices = {
1297-
'xs': 'mobile',
1298-
's': 'mobile',
1299-
'm': 'tablet',
1300-
'l': 'tablet',
1301-
'xl': 'desktop'
1302-
};
1295+
var i = 0,
1296+
width = this.getViewportWidth(),
1297+
device = 'desktop',
1298+
devices = window.statisticDevices || [];
1299+
1300+
for (; i < devices.length; i++) {
1301+
if (width >= ~~(devices[i].enter) && width <= ~~(devices[i].exit)) {
1302+
device = devices[i].device;
1303+
}
1304+
}
13031305

1304-
return devices[me.getCurrentState()] || 'desktop';
1306+
return device;
13051307
},
13061308

13071309
_setDeviceCookie: function() {
1308-
var me = this,
1309-
device = me._getCurrentDevice();
1310+
var device = this._getCurrentDevice();
13101311

13111312
document.cookie = 'x-ua-device=' + device + '; path=/';
13121313
},

0 commit comments

Comments
 (0)