Merge branch 'bootstrap' of https://github.com/PrestaShop/PrestaShop into bootstrap

This commit is contained in:
Vincent Augagneur
2013-09-12 10:08:32 +02:00
36 changed files with 882 additions and 440 deletions
File diff suppressed because one or more lines are too long
+29 -22
View File
@@ -1,5 +1,5 @@
//$brand-primary: #1BA6E5
$brand-primary: #6992AF
//light
//$main-color: #F7F7F7
@@ -8,13 +8,15 @@ $brand-primary: #6992AF
//$main-color: #E0E0E0 //gris
//$main-color: #D7D6DE //violet
//$main-color: #F1F8FE //theme wordpress
//dark
//$main-color: #272A31 //bleu PrestaShop
//$main-color: #3D3D3D //gris
//$main-color: #515561 //gris bleu clair
$main-color: #515561 //gris bleu clair
//$main-color: #4D4645 //taupe
//$main-color: #272822 //gris vert
$main-color: #313A45 //gris bleu
//$main-color: #313A45 //gris bleu
//$main-color: #7B8676
//$main-color: #443A42 //violet
//$main-color: #373E35 //vert camo
//$main-color: #262C3F //bleu nuit - pretty sure that a girl could do better naming the colors, sorry about that...
@@ -30,14 +32,17 @@ $main-color: #313A45 //gris bleu
//$secondary-color: #4691D2 //bleu ciel
//$secondary-color: #814C76 //violet
//$secondary-color: #FE635F //saumon
//$secondary-color: #F8235A //rose
//$secondary-color: #FFB4B8 //rose
//$secondary-color: #F2B100 //moutarde
//$secondary-color: #F7854E //abricot
//$secondary-color: #F6A88A //abricot
//$secondary-color: #937976 //taupe clair
//$secondary-color: #60C276 //vert
//$secondary-color: #9DC44B //vert pomme
$secondary-color: #6992AF //theme wordpress
//$secondary-color: #6992AF //theme wordpress
//$secondary-color: #8BC954 //vert PrestaShop
$secondary-color: #AB7073
$brand-primary: #89AFE5
//some tests
//$secondary-color: #79C09D
@@ -68,7 +73,7 @@ $bg-page-head-color : $secondary-color
$bg-panel-heading-color: hsl(hue($secondary-color), 10, 90)
//others
$badge-notif-color: #EF1778
$badge-notif-color: #8BC954
$icon-color: #87C795
@import "compass"
@@ -150,7 +155,7 @@ html, body
background-image: url('../img/patterns/bedge_grunge.png') // texture
#content
padding: 90px 20px 0
padding: 80px 20px 0
margin-left: 240px
@include transition-property(margin)
@include transition-duration(0.4s)
@@ -356,21 +361,21 @@ html, body
text-decoration: none
&:last-child a
border-bottom: none
&.active
a
&.active a
color: contrast-color($brand-primary, white, #333, 10%)
background-color: $brand-primary
border-bottom: solid 1px darken($brand-primary,10%)
#nav-topbar
position: fixed
height: 28px
top: 36px
top: 35px
left: 80
width: 100%
z-index: 600
background-color: white
border-top: black solid 1px
border-bottom: black solid 1px
border-bottom: darken($secondary-color,20%) solid 1px
ul.menu
height: 28px
margin: 0
@@ -415,12 +420,12 @@ html, body
ul.submenu
display: none!important
@include box-shadow(rgba(black,0.3) 0 2px 4px)
> ul.menu > li
ul.submenu.expanded
> ul.menu > li.expanded
ul.submenu
display: block!important
> ul.menu > li
ul.submenu
display: none
display: none!important
position: absolute
margin: 0
padding: 0
@@ -445,9 +450,9 @@ html, body
&:last-child a
border-bottom: none
&.active a
color: contrast-color($main-color, white, #333, 10%)
background-color: $main-color
border-bottom: solid 1px darken($main-color,10%)
color: contrast-color($brand-primary, white, #333, 10%)
background-color: $brand-primary
border-bottom: solid 1px darken($brand-primary,10%)
.page-topbar
#main
@@ -455,7 +460,7 @@ html, body
#nav-sidebar
display: none
.page-head
top: 64px
top: 63px
#content
margin-left: 0
width: 100%
@@ -1262,6 +1267,11 @@ fieldset > .row
margin: 0 4px 0 6px
background-color: #ccc
+border-radius(6px)
.tree-item-disable, .tree-folder-name-disable
color: #ccc
&:hover
color: #ccc
background-color: none
#carrier_wizard
position: relative
@@ -1405,6 +1415,3 @@ fieldset > .row
width: auto
.field_error
border-color: $brand-danger
+76 -34
View File
@@ -25,42 +25,84 @@
$( document ).ready(function() {
//nav side bar
$('#nav-sidebar li.maintab.has_submenu').append('<span class="submenu_expand"></span>');
$('#nav-sidebar .submenu_expand').click(function(){
var $navId = $(this).parent();
$(".submenu-collapse").remove();
if($(".expanded").length ){
$(".expanded > ul").slideUp(
"fast",
function(){
var $target = $(".expanded");
$target.removeClass("expanded");
$($navId).not($target).not(".active").addClass("expanded");
$($navId).not($target).not(".active").children("ul:first").hide().slideDown();
}
);
}
else {
$($navId).not(".active").addClass("expanded");
$($navId).not(".active").children("ul:first").hide().slideDown();
}
});
//nav top bar
$(window).on("resize", function() {
$("#nav-topbar ul.menu").find("li.maintab").each(function(){
if ($(this).position().top > 0) {
$(this).addClass("hide");
function navSidebar(){
$('#nav-sidebar li.maintab.has_submenu').append('<span class="submenu_expand"></span>');
$('#nav-sidebar .submenu_expand').on('click',function(){
var $navId = $(this).parent();
$('.submenu-collapse').remove();
if($('.expanded').length ){
$('.expanded > ul').slideUp(
'fast',
function(){
var $target = $('.expanded');
$target.removeClass('expanded');
$($navId).not($target).not('.active').addClass('expanded');
$($navId).not($target).not('.active').children('ul:first').hide().slideDown();
}
);
}
else {
$($navId).not('.active').addClass('expanded');
$($navId).not('.active').children('ul:first').hide().slideDown();
}
});
});
$("#nav-topbar li.maintab.has_submenu").hover(function(){
$(this).find("ul.submenu").fadeIn("fast").addClass("expanded");
}, function(){
//$(this).removeClass("expanded");
$(this).find("ul.submenu").fadeOut("fast").removeClass("expanded");
});
}
//nav top bar
function navTopbar(){
$('.expanded').removeClass('expanded');
$('#nav-topbar').on('mouseenter', 'li.maintab.has_submenu',
function(){
$(this).addClass('expanded');
});
$('#nav-topbar').on('mouseleave', 'li.maintab.has_submenu',
function(){
$(this).removeClass('expanded');
});
//todo hide element over menu width on load
$('#nav-topbar').find('li.maintab').each(
function(){
if ($(this).position().top > 0) {
$(this).addClass('hide');
}
});
//todo hide element over menu width on resize
$(window).on('resize', function() {
$('#nav-topbar ul.menu').find('li.maintab').each(function(){
if ($(this).position().top > 0) {
$(this).addClass('hide');
}
});
});
}
//nav switch
function navSwitch(){
if ($('body').hasClass('page-sidebar')||$('body').hasClass('page-sidebar-closed')) {
$('body').removeClass('page-sidebar').removeClass('page-sidebar-closed').addClass('page-topbar');
$('#nav-sidebar').attr('id','nav-topbar');
$('#nav-topbar').off();
navTopbar();
} else {
$('body.page-topbar').removeClass('page-topbar').addClass('page-sidebar');
$('#nav-topbar').attr('id','nav-sidebar');
$('#nav-sidebar').off();
navSidebar();
}
}
//todo add condition
navTopbar();
$('#header_shopname').on('click',
function(e){
e.preventDefault();
navSwitch();
}
);
//tooltip
$('.label-tooltip').tooltip();
@@ -0,0 +1,108 @@
{*
* 2007-2013 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2013 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*}
<div class="panel">
{if isset($header)}{$header}{/if}
{if isset($nodes)}
<ul id="{$id}" class="tree">
{$nodes}
</ul>
{/if}
</div>
<script type="text/javascript">
{if isset($use_checkbox) && $use_checkbox == true}
function checkAllAssociatedCategories($tree)
{
$tree.find(":input[type=checkbox]").each(
function()
{
$(this).prop("checked", true);
$(this).parent().addClass("tree-selected");
}
);
}
function uncheckAllAssociatedCategories($tree)
{
$tree.find(":input[type=checkbox]").each(
function()
{
$(this).prop("checked", false);
$(this).parent().removeClass("tree-selected");
}
);
}
{/if}
{if isset($use_search) && $use_search == true}
$("#{$id}-categories-search").bind("typeahead:selected", function(obj, datum) {
$("#{$id}").find(":input").each(
function()
{
if ($(this).val() == datum.id_category)
{
$(this).prop("checked", true);
$(this).parent().addClass("tree-selected");
$(this).parents("ul.tree").each(
function()
{
$(this).children().children().children(".icon-folder-close")
.removeClass("icon-folder-close")
.addClass("icon-folder-open");
$(this).show();
}
);
}
}
);
});
{/if}
$(document).ready(function () {
$("#{$id}").tree("collapseAll");
{if isset($selected_categories)}
{assign var=imploded_selected_categories value='","'|implode:$selected_categories}
var selected_categories = new Array("{$imploded_selected_categories}");
$("#{$id}").find(":input").each(
function()
{
if ($.inArray($(this).val(), selected_categories) != -1)
{
$(this).prop("checked", true);
$(this).parent().addClass("tree-selected");
$(this).parents("ul.tree").each(
function()
{
$(this).children().children().children(".icon-folder-close")
.removeClass("icon-folder-close")
.addClass("icon-folder-open");
$(this).show();
}
);
}
}
);
{/if}
});
</script>
@@ -0,0 +1,34 @@
{*
* 2007-2013 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2013 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*}
<li class="tree-folder">
<span class="tree-folder-name{if isset($node['disabled']) && $node['disabled'] == true} tree-folder-name-disable{/if}">
<input type="radio" name="id_parent" value="{$node['id_category']}"{if isset($node['disabled']) && $node['disabled'] == true} disabled="disabled"{/if} />
<i class="icon-folder-close"></i>
<label class="tree-toggler ">{$node['name']}</label>
</span>
<ul class="tree">
{$children}
</ul>
</li>
@@ -0,0 +1,31 @@
{*
* 2007-2013 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2013 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*}
<li class="tree-item{if isset($node['disabled']) && $node['disabled'] == true} tree-item-disable{/if}">
<label class="tree-item-name">
<input type="radio" name="id_parent" value="{$node['id_category']}"{if isset($node['disabled']) && $node['disabled'] == true} disabled="disabled"{/if} />
<i class="tree-dot"></i>
{$node['name']}
<label>
</li>
@@ -1,27 +0,0 @@
{*
* 2007-2013 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2013 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*}
<a href="{$link}"{if isset($action)}onclick="{$action}"{/if} class="btn btn-default btn-xs">
{if isset($icon_class)}<i class="{$icon_class}"></i>&nbsp;{/if}{l s=$label}
</a>
@@ -1,39 +0,0 @@
{*
* 2007-2013 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2013 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*}
<label for="node-search">{l s=$label}</label>&nbsp;<input type="text"{if isset($id)} id="{$id}"{/if}{if isset($name)} name="{$name}"{/if}{if isset($class)} class="{$class}"{/if} />
{if isset($typeahead_source) && isset($id)}
<script type="text/javascript">
$(document).ready(
function()
{
$("#{$id}").typeahead(
{
name: "{$name}",
local: [{$typeahead_source}]
});
}
);
</script>
{/if}
+1 -2
View File
@@ -289,8 +289,7 @@
<div id="main">
{include file='nav-top.tpl'}
{include file='nav-side.tpl'}
<div id="content" class="page-content">
{if $display_header && $install_dir_exists}
<div class="alert alert-warning">
@@ -158,7 +158,19 @@
{if isset($input.disabled) && $input.disabled}disabled="disabled"{/if}
{if isset($input.autocomplete) && !$input.autocomplete}autocomplete="off"{/if} />
{if isset($input.suffix)}{$input.suffix}{/if}
{if !empty($input.desc)}<div class="alert alert-info">{$input.desc}</div>{/if}
{if !empty($input.desc)}
<div class="alert alert-info">
{if is_array($input.desc)}
<ul>
{foreach $input.desc as $desc}
<li>{$desc}</li>
{/foreach}
</ul>
{else}
{$input.desc}
{/if}
</div>
{/if}
{/if}
{elseif $input.type == 'select'}
{if isset($input.options.query) && !$input.options.query && isset($input.empty_message)}
@@ -405,7 +417,7 @@
{elseif $input.type == 'shop'}
{$input.html}
{elseif $input.type == 'categories'}
{include file='helpers/form/form_category.tpl' categories=$input.values}
{$categories_tree}
{elseif $input.type == 'categories_select'}
{$input.category_tree}
{elseif $input.type == 'asso_shop' && isset($asso_shop) && $asso_shop}
@@ -0,0 +1,116 @@
{*
* 2007-2013 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2013 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*}
<div class="panel">
{if isset($header)}{$header}{/if}
{if isset($nodes)}
<ul id="{$id}" class="tree">
{$nodes}
</ul>
{/if}
</div>
<script type="text/javascript">
{if isset($use_checkbox) && $use_checkbox == true}
function checkAllAssociatedCategories($tree)
{
$tree.find(":input[type=checkbox]").each(
function()
{
$(this).prop("checked", true);
$(this).parent().addClass("tree-selected");
}
);
}
function uncheckAllAssociatedCategories($tree)
{
$tree.find(":input[type=checkbox]").each(
function()
{
$(this).prop("checked", false);
$(this).parent().removeClass("tree-selected");
}
);
}
{/if}
{if isset($use_search) && $use_search == true}
$("#{$id}-categories-search").bind("typeahead:selected", function(obj, datum) {
$("#{$id}").find(":input").each(
function()
{
if ($(this).val() == datum.id_category)
{
$(this).prop("checked", true);
$(this).parent().addClass("tree-selected");
$(this).parents("ul.tree").each(
function()
{
$(this).children().children().children(".icon-folder-close")
.removeClass("icon-folder-close")
.addClass("icon-folder-open");
$(this).show();
}
);
}
}
);
});
{/if}
$(document).ready(function () {
$("#{$id}").tree("collapseAll");
$("#{$id}").find(":input[type=radio]").click(
function()
{
location.href = location.href.replace(
/&id_category=[0-9]*/, "")+"&id_category="
+$(this).val();
}
);
{if isset($selected_categories)}
{assign var=imploded_selected_categories value='","'|implode:$selected_categories}
var selected_categories = new Array("{$imploded_selected_categories}");
$("#{$id}").find(":input").each(
function()
{
if ($.inArray($(this).val(), selected_categories) != -1)
{
$(this).prop("checked", true);
$(this).parent().addClass("tree-selected");
$(this).parents("ul.tree").each(
function()
{
$(this).children().children().children(".icon-folder-close")
.removeClass("icon-folder-close")
.addClass("icon-folder-open");
$(this).show();
}
);
}
}
);
{/if}
});
</script>
@@ -22,7 +22,6 @@
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*}
<li class="tree-folder">
<span class="tree-folder-name">
<i class="icon-folder-close"></i>
@@ -23,8 +23,8 @@
* International Registered Trademark & Property of PrestaShop SA
*}
<li class="tree-folder">
<span class="tree-folder-name">
<input type="checkbox" name="categoryBox[]" value="{$node['id_category']}" />
<span class="tree-folder-name{if isset($node['disabled']) && $node['disabled'] == true} tree-folder-name-disable{/if}">
<input type="checkbox" name="categoryBox[]" value="{$node['id_category']}"{if isset($node['disabled']) && $node['disabled'] == true} disabled="disabled"{/if} />
<i class="icon-folder-close"></i>
<label class="tree-toggler">{$node['name']}</label>
</span>
@@ -23,8 +23,8 @@
* International Registered Trademark & Property of PrestaShop SA
*}
<li class="tree-folder">
<span class="tree-folder-name">
<input type="radio" name="id-category" value="{$node['id_category']}" />
<span class="tree-folder-name{if isset($node['disabled']) && $node['disabled'] == true} tree-folder-name-disable{/if}">
<input type="radio" name="id-category" value="{$node['id_category']}"{if isset($node['disabled']) && $node['disabled'] == true} disabled="disabled"{/if} />
<i class="icon-folder-close"></i>
<label class="tree-toggler ">{$node['name']}</label>
</span>
@@ -22,9 +22,9 @@
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*}
<li class="tree-item">
<li class="tree-item{if isset($node['disabled']) && $node['disabled'] == true} tree-item-disable{/if}">
<label class="tree-item-name">
<input type="checkbox" name="categoryBox[]" value="{$node['id_category']}" />
<input type="checkbox" name="categoryBox[]" value="{$node['id_category']}"{if isset($node['disabled']) && $node['disabled'] == true} disabled="disabled"{/if} />
<i class="tree-dot"></i>
{$node['name']}
</label>
@@ -22,9 +22,9 @@
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*}
<li class="tree-item">
<li class="tree-item{if isset($node['disabled']) && $node['disabled'] == true} tree-item-disable{/if}">
<label class="tree-item-name">
<input type="radio" name="id-category" value="{$node['id_category']}" />
<input type="radio" name="id-category" value="{$node['id_category']}"{if isset($node['disabled']) && $node['disabled'] == true} disabled="disabled"{/if} />
<i class="tree-dot"></i>
{$node['name']}
<label>
@@ -1,4 +1,4 @@
<nav id="nav-topbar" data-spy="affix" data-offset-top="34px" role="navigation">
<nav id="nav-topbar" data-spy="affix" data-offset-top="0" role="navigation">
{if !$tab}
<div class="mainsubtablist" style="display:none"></div>
{/if}
+5 -1
View File
@@ -477,15 +477,19 @@ class CategoryCore extends ObjectModel
return $categories;
}
public static function getNestedCategories($root_category = 1,
public static function getNestedCategories($root_category = null,
$id_lang = false, $active = true, $sql_filter = '', $sql_sort = '',
$sql_limit = '')
{
if (!isset($root_category))
$root_category = self::getRootCategory($id_lang)->id;
if (!Validate::isInt($root_category))
die(Tools::displayError());
if (!Validate::isBool($active))
die(Tools::displayError());
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT *
FROM `'._DB_PREFIX_.'category` c
+11 -8
View File
@@ -89,16 +89,18 @@ class HelperFormCore extends Helper
case 'categories':
if ($categories)
{
// Added Jquery plugin treeview (css and js files)
$this->context->controller->addJqueryPlugin('treeview-categories');
$tree = new HelperTreeCategories($params['tree']['id'], isset($params['tree']['title']) ? $params['tree']['title'] : null);
// Added JS files
$this->context->controller->addJS(_PS_JS_DIR_.'jquery/plugins/treeview-categories/jquery.treeview-categories.async.js');
$this->context->controller->addJS(_PS_JS_DIR_.'jquery/plugins/treeview-categories/jquery.treeview-categories.edit.js');
$this->context->controller->addJS(_PS_JS_DIR_.'admin-categories-tree.js');
if (isset($params['tree']['selected_categories']))
$tree->setSelectedCategories($params['tree']['selected_categories']);
if (isset($params['use_search']) && $params['use_search'])
$this->context->controller->addJS(_PS_JS_DIR_.'jquery/plugins/autocomplete/jquery.autocomplete.js');
if (isset($params['tree']['disabled_categories']))
$tree->setDisabledCategories($params['tree']['disabled_categories']);
if (isset($params['tree']['root_category']))
$tree->setRootCategory($params['tree']['root_category']);
$this->context->smarty->assign('categories_tree', $tree->render());
$categories = false;
}
break;
@@ -225,6 +227,7 @@ class HelperFormCore extends Helper
}
}
$tpl = $this->createTemplate('assoshop.tpl');
$tree = Shop::getTree();
$nb_shop = 0;
+265
View File
@@ -0,0 +1,265 @@
<?php
/*
* 2007-2013 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2013 PrestaShop SA
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class HelperTreeCategories extends TreeCore
{
const DEFAULT_TEMPLATE = 'tree_categories.tpl';
const DEFAULT_NODE_FOLDER_TEMPLATE = 'tree_node_folder_radio.tpl';
const DEFAULT_NODE_ITEM_TEMPLATE = 'tree_node_item_radio.tpl';
private $_disabled_categories;
private $_lang;
private $_root_category;
private $_selected_categories;
private $_shop;
private $_use_checkbox;
private $_use_search;
public function __construct($id, $title = null, $root_category = null,
$lang = null, $shop = null)
{
parent::__construct($id);
if (isset($title))
$this->setTitle($title);
if (isset($root_category))
$this->setRootCategory($root_category);
$this->setLang($lang);
$this->setShop($shop);
}
public function getData()
{
if (!isset($this->_data))
$this->setData(Category::getNestedCategories(
$this->getRootCategory(), $this->getLang()));
return $this->_data;
}
public function setDisabledCategories($value)
{
$this->_disabled_categories = $value;
return $this;
}
public function getDisabledCategories()
{
return $this->_disabled_categories;
}
public function setLang($value)
{
$this->_lang = $value;
return $this;
}
public function getLang()
{
if (!isset($this->_lang))
$this->setLang($this->getContext()->employee->id_lang);
return $this->_lang;
}
public function getNodeFolderTemplate()
{
if (!isset($this->_node_folder_template))
$this->setNodeFolderTemplate(self::DEFAULT_NODE_FOLDER_TEMPLATE);
return $this->_node_folder_template;
}
public function getNodeItemTemplate()
{
if (!isset($this->_node_item_template))
$this->setNodeItemTemplate(self::DEFAULT_NODE_ITEM_TEMPLATE);
return $this->_node_item_template;
}
public function setRootCategory($value)
{
if (!Validate::isInt($value))
throw new PrestaShopException('Root category must be an integer value');
$this->_root_category = $value;
return $this;
}
public function getRootCategory()
{
if (!isset($this->_root_category))
$this->setRootCategory(Category::getRootCategory($this->getLang())
->id);
return $this->_root_category;
}
public function setSelectedCategories($value)
{
if (!is_array($value))
throw new PrestaShopException('Selected categories value must be an array');
$this->_selected_categories = $value;
return $this;
}
public function getSelectedCatgories()
{
if (!isset($this->_selected_categories))
$this->_selected_categories = array();
return $this->_selected_categories;
}
public function setShop($value)
{
$this->_shop = $value;
return $this;
}
public function getShop()
{
if (!isset($this->_shop))
{
if (Tools::isSubmit('id_shop'))
$this->setShop(new Shop(Tools::getValue('id_shop')));
else
if ($this->getContext()->shop->id)
$this->setShop(new Shop($this->getContext()->shop->id));
else
if (!Shop::isFeatureActive())
$this->setShop(new Shop(Configuration::get('PS_SHOP_DEFAULT')));
else
$this->setShop(new Shop(0));
}
return $this->_shop;
}
public function getTemplate()
{
if (!isset($this->_template))
$this->setTemplate(self::DEFAULT_TEMPLATE);
return $this->_template;
}
public function setUseCheckBox($value)
{
$this->_use_checkbox = (bool)$value;
return $this;
}
public function setUseSearch($value)
{
$this->_use_search = (bool)$value;
return $this;
}
public function useCheckBox()
{
return (isset($this->_use_checkbox) && $this->_use_checkbox);
}
public function useSearch()
{
return (isset($this->_use_search) && $this->_use_search);
}
public function render($data = NULL)
{
if (!isset($data))
$data = $this->getData();
if (isset($this->_disabled_categories)
&& !empty($this->_disabled_categories))
$this->_disableCategories($data, $this->getDisabledCategories());
$this->setActions(array(
new TreeToolbarLink(
'Collapse All',
'#',
'$(\'#'.$this->getId().'\').tree(\'collapseAll\')',
'icon-collapse-alt'),
new TreeToolbarLink(
'Expand All',
'#',
'$(\'#'.$this->getId().'\').tree(\'expandAll\')',
'icon-expand-alt')
));
if ($this->useCheckBox())
{
$this->addAction(new TreeToolbarLink(
'Check All',
'#',
'checkAllAssociatedCategories($(\'#'.$this->getId().'\'));',
'icon-check-sign')
);
$this->addAction(new TreeToolbarLink(
'Uncheck All',
'#',
'uncheckAllAssociatedCategories($(\'#'.$this->getId().'\'));',
'icon-check-empty')
);
$this->setNodeFolderTemplate('tree_node_folder_checkbox.tpl');
$this->setNodeItemTemplate('tree_node_item_checkbox.tpl');
$this->setAttribute('use_checkbox', $this->useCheckBox());
}
if ($this->useSearch())
{
$this->addAction(new TreeToolbarSearch(
'Find a category:',
$this->getId().'-categories-search')
);
$this->setAttribute('use_search', $this->useSearch());
}
$this->setAttribute('selected_categories', $this->getSelectedCatgories());
return parent::render($data);
}
private function _disableCategories(&$categories, $disabled_categories = null)
{
foreach ($categories as &$category)
{
if (!isset($disabled_categories) || in_array($category['id_category'], $disabled_categories))
{
$category['disabled'] = true;
if (array_key_exists('children', $category) && is_array($category['children']))
self::_disableCategories($category['children']);
}
else if (array_key_exists('children', $category) && is_array($category['children']))
self::_disableCategories($category['children'], $disabled_categories);
}
}
}
@@ -24,7 +24,7 @@
* International Registered Trademark & Property of PrestaShop SA
*/
interface HelperITreeToolbarCore
interface ITreeToolbarCore
{
public function __toString();
public function setActions($value);
@@ -24,7 +24,7 @@
* International Registered Trademark & Property of PrestaShop SA
*/
interface HelperITreeToolbarButtonCore
interface ITreeToolbarButtonCore
{
public function __toString();
public function setAttribute($name, $value);
@@ -24,7 +24,7 @@
* International Registered Trademark & Property of PrestaShop SA
*/
class HelperTreeCore
class TreeCore
{
const DEFAULT_TEMPLATE_DIRECTORY = 'helpers/tree';
const DEFAULT_TEMPLATE = 'tree.tpl';
@@ -32,15 +32,16 @@ class HelperTreeCore
const DEFAULT_NODE_FOLDER_TEMPLATE = 'tree_node_folder.tpl';
const DEFAULT_NODE_ITEM_TEMPLATE = 'tree_node_item.tpl';
private $_context;
private $_data;
private $_headerTemplate;
private $_id;
private $_node_folder_template;
private $_node_item_template;
private $_template;
private $_template_directory;
private $_title;
protected $_attributes;
private $_context;
protected $_data;
protected $_headerTemplate;
private $_id;
protected $_node_folder_template;
protected $_node_item_template;
protected $_template;
private $_template_directory;
private $_title;
public function __construct($id, $data = null)
{
@@ -58,7 +59,7 @@ class HelperTreeCore
public function setActions($value)
{
if (!isset($this->_toolbar))
$this->setToolbar(new HelperTreeToolbarCore());
$this->setToolbar(new TreeToolbarCore());
$this->getToolbar()->setActions($value);
return $this;
@@ -67,7 +68,7 @@ class HelperTreeCore
public function getActions()
{
if (!isset($this->_toolbar))
$this->setToolbar(new HelperTreeToolbarCore());
$this->setToolbar(new TreeToolbarCore());
return $this->getToolbar()->getActions();
}
@@ -75,12 +76,43 @@ class HelperTreeCore
public function addAction($action)
{
if (!isset($this->_toolbar))
$this->setToolbar(new HelperTreeToolbarCore());
$this->setToolbar(new TreeToolbarCore());
$this->getToolbar()->addAction($action);
return $this;
}
public function setAttribute($name, $value)
{
if (!isset($this->_attributes))
$this->_attributes = array();
$this->_attributes[$name] = $value;
return $this;
}
public function getAttribute($name)
{
return $this->hasAttribute($name) ? $this->_attributes[$name] : null;
}
public function setAttributes($value)
{
if (!is_array($value) && !$value instanceof Traversable)
throw new PrestaShopException('Data value must be an traversable array');
$this->_attributes = $value;
return $this;
}
public function getAttributes()
{
if (!isset($this->_attributes))
$this->_attributes = array();
return $this->_attributes;
}
public function setContext($value)
{
$this->_context = $value;
@@ -250,7 +282,7 @@ class HelperTreeCore
$reflection = new ReflectionClass($value);
if (!$reflection->implementsInterface('HelperITreeToolbarCore'))
if (!$reflection->implementsInterface('ITreeToolbarCore'))
throw new PrestaShopException('Toolbar class must implements ITreeToolbarCore interface');
$this->_toolbar = $value;
@@ -315,7 +347,9 @@ class HelperTreeCore
}
//Assign Tree nodes
$template->assign(array(
$template
->assign($this->getAttributes())
->assign(array(
'id' => $this->getId(),
'nodes' => $this->renderNodes($data)
));
@@ -24,7 +24,7 @@
* International Registered Trademark & Property of PrestaShop SA
*/
class HelperTreeToolbarCore implements HelperITreeToolbarCore
class TreeToolbarCore implements ITreeToolbarCore
{
const DEFAULT_TEMPLATE_DIRECTORY = 'helpers/tree';
const DEFAULT_TEMPLATE = 'tree_toolbar.tpl';
@@ -159,7 +159,7 @@ class HelperTreeToolbarCore implements HelperITreeToolbarCore
$reflection = new ReflectionClass($action);
if (!$reflection->implementsInterface('HelperITreeToolbarButtonCore'))
if (!$reflection->implementsInterface('ITreeToolbarButtonCore'))
throw new PrestaShopException('Action class must implements ITreeToolbarButtonCore interface');
if (!isset($this->_actions))
@@ -173,7 +173,7 @@ class HelperTreeToolbarCore implements HelperITreeToolbarCore
{
foreach ($this->getActions() as $action)
{
if ($action instanceof HelperTreeToolbarSearchCore)
if ($action instanceof TreeToolbarSearchCore)
$action->setAttribute('data', $this->getData());
}
@@ -24,7 +24,7 @@
* International Registered Trademark & Property of PrestaShop SA
*/
abstract class HelperTreeToolbarButtonCore
abstract class TreeToolbarButtonCore
{
const DEFAULT_TEMPLATE_DIRECTORY = 'helpers/tree';
@@ -24,8 +24,8 @@
* International Registered Trademark & Property of PrestaShop SA
*/
class HelperTreeToolbarLinkCore extends HelperTreeToolbarButtonCore implements
HelperITreeToolbarButtonCore
class TreeToolbarLinkCore extends TreeToolbarButtonCore implements
ITreeToolbarButtonCore
{
private $_action;
private $_icon_class;
@@ -24,8 +24,8 @@
* International Registered Trademark & Property of PrestaShop SA
*/
class HelperTreeToolbarSearchCore extends HelperTreeToolbarButtonCore implements
HelperITreeToolbarButtonCore
class TreeToolbarSearchCore extends TreeToolbarButtonCore implements
ITreeToolbarButtonCore
{
protected $_template = 'tree_toolbar_search.tpl';
@@ -340,7 +340,7 @@ class AdminCategoriesControllerCore extends AdminController
$this->initToolbar();
$obj = $this->loadObject(true);
$id_shop = Context::getContext()->shop->id;
$selected_cat = array((isset($obj->id_parent) && $obj->isParentCategoryAvailable($id_shop))? (int)$obj->id_parent : (int)Tools::getValue('id_parent', Category::getRootCategory()->id));
$selected_categories = array((isset($obj->id_parent) && $obj->isParentCategoryAvailable($id_shop))? (int)$obj->id_parent : (int)Tools::getValue('id_parent', Category::getRootCategory()->id));
$unidentified = new Group(Configuration::get('PS_UNIDENTIFIED_GROUP'));
$guest = new Group(Configuration::get('PS_GUEST_GROUP'));
$default = new Group(Configuration::get('PS_CUSTOMER_GROUP'));
@@ -348,8 +348,7 @@ class AdminCategoriesControllerCore extends AdminController
$unidentified_group_information = sprintf($this->l('%s - All people without a valid customer account.'), '<b>'.$unidentified->name[$this->context->language->id].'</b>');
$guest_group_information = sprintf($this->l('%s - Customer who placed an order with the guest checkout.'), '<b>'.$guest->name[$this->context->language->id].'</b>');
$default_group_information = sprintf($this->l('%s - All people who have created an account on this site.'), '<b>'.$default->name[$this->context->language->id].'</b>');
$root_category = Category::getRootCategory();
$root_category = array('id_category' => $root_category->id, 'name' => $root_category->name);
$this->fields_form = array(
'tinymce' => true,
'legend' => array(
@@ -386,23 +385,13 @@ class AdminCategoriesControllerCore extends AdminController
)
),
array(
'type' => 'categories',
'type' => 'categories',
'label' => $this->l('Parent category:'),
'name' => 'id_parent',
'values' => array(
'trads' => array(
'Root' => $root_category,
'selected' => $this->l('Selected'),
'Collapse All' => $this->l('Collapse All'),
'Expand All' => $this->l('Expand All')
),
'selected_cat' => $selected_cat,
'input_name' => 'id_parent',
'use_radio' => true,
'use_search' => false,
'disabled_categories' => array(4),
'top_category' => Category::getTopCategory(),
'use_context' => true,
'name' => 'id_parent',
'tree' => array(
'id' => 'categories-tree',
'selected_categories' => $selected_categories,
'disabled_categories' => !Tools::isSubmit('add'.$this->table) ? array($this->_category->id) : null
)
),
array(
+10 -183
View File
@@ -2309,7 +2309,9 @@ class AdminProductsControllerCore extends AdminController
$this->tpl_list_vars['is_category_filter'] = (bool)$this->id_current_category;
// Generate category selection tree
$this->tpl_list_vars['category_tree'] = $this->renderCategoriesTree((int)$id_category);
$tree = new HelperTreeCategories('categories-tree', 'Filter by category');
$tree->setSelectedCategories(array((int)$id_category));
$this->tpl_list_vars['category_tree'] = $tree->render();
// used to build the new url when changing category
$this->tpl_list_vars['base_url'] = preg_replace('#&id_category=[0-9]*#', '', self::$currentIndex).'&token='.$this->token;
@@ -2328,186 +2330,6 @@ class AdminProductsControllerCore extends AdminController
return parent::renderList();
}
public function renderCategoriesTree($selected_category = null)
{
if (Tools::isSubmit('id_shop'))
$id_shop = Tools::getValue('id_shop');
else
if (Context::getContext()->shop->id)
$id_shop = Context::getContext()->shop->id;
else
if (!Shop::isFeatureActive())
$id_shop = Configuration::get('PS_SHOP_DEFAULT');
else
$id_shop = 0;
$shop = new Shop($id_shop);
$root_category = Category::getRootCategory(null, $shop);
$tree = new HelperTree('categories-tree', Category::getNestedCategories(
$root_category->id, $this->context->employee->id_lang));
$html = $tree->setTitle('Filter by category')
->setActions(array(
new HelperTreeToolbarLink(
'Collapse All',
'#',
'$(\'#categories-tree\').tree(\'collapseAll\')',
'icon-collapse-alt'),
new HelperTreeToolbarLink(
'Expand All',
'#',
'$(\'#categories-tree\').tree(\'expandAll\')',
'icon-expand-alt')
))
->render();
$html .= '<script type="text/javascript">
$(document).ready(function () {
$("#categories-tree").tree("collapseAll");
$("#categories-tree").find(":input[type=radio]").click(
function()
{
location.href = location.href.replace(
/&id_category=[0-9]*/, "")+"&id_category="
+$(this).val();
}
);';
if (isset($selected_category))
$html .= '$("#categories-tree").find(":input").each(
function()
{
if ($(this).val() == '.$selected_category.')
{
$(this).prop("checked", true);
$(this).parent().addClass("tree-selected");
$(this).parents("ul.tree").each(
function()
{
$(this).children().children(".icon-folder-close")
.removeClass("icon-folder-close")
.addClass("icon-folder-open");
$(this).show();
}
);
}
}
);';
$html .= '});
</script>';
return $html;
}
public function renderAssociationsCategoriesTree($root_category,
$selected_categories)
{
$tree = new HelperTree('associated-categories-tree',
Category::getNestedCategories($root_category, $this->context->employee->id_lang));
$html = $tree->setTitle('Associated categories')
->setActions(array(
new HelperTreeToolbarLink(
'Collapse All',
'#',
'$(\'#associated-categories-tree\').tree(\'collapseAll\')',
'icon-collapse-alt'),
new HelperTreeToolbarLink(
'Expand All',
'#',
'$(\'#associated-categories-tree\').tree(\'expandAll\')',
'icon-expand-alt'),
new HelperTreeToolbarLink(
'Check All',
'#',
'checkAllAssociatedCategories();',
'icon-check-sign'),
new HelperTreeToolbarLink(
'Uncheck All',
'#',
'uncheckAllAssociatedCategories();',
'icon-check-empty'),
new HelperTreeToolbarSearch(
'Find a category:',
'categories-search')
))
->setNodeFolderTemplate('tree_node_folder_associations.tpl')
->setNodeItemTemplate('tree_node_item_associations.tpl')
->render();
$html .= '<script type="text/javascript">
function checkAllAssociatedCategories()
{
$("#associated-categories-tree").find(":input[type=checkbox]").each(
function()
{
$(this).prop("checked", true);
$(this).parent().addClass("tree-selected");
}
);
}
function uncheckAllAssociatedCategories()
{
$("#associated-categories-tree").find(":input[type=checkbox]").each(
function()
{
$(this).prop("checked", false);
$(this).parent().removeClass("tree-selected");
}
);
}
$("#categories-search").bind("typeahead:selected", function(obj, datum) {
$("#associated-categories-tree").find(":input").each(
function()
{
if ($(this).val() == datum.id_category)
{
$(this).prop("checked", true);
$(this).parent().addClass("tree-selected");
$(this).parents("ul.tree").each(
function()
{
$(this).children().children().children(".icon-folder-close")
.removeClass("icon-folder-close")
.addClass("icon-folder-open");
$(this).show();
}
);
}
}
);
});
$(document).ready(
function()
{
$("#associated-categories-tree").tree("collapseAll");
var selected_categories = new Array("'.implode('","', $selected_categories).'");
$("#associated-categories-tree").find(":input").each(
function()
{
if ($.inArray($(this).val(), selected_categories) != -1)
{
$(this).prop("checked", true);
$(this).parent().addClass("tree-selected");
$(this).parents("ul.tree").each(
function()
{
$(this).children().children().children(".icon-folder-close")
.removeClass("icon-folder-close")
.addClass("icon-folder-open");
$(this).show();
}
);
}
}
);
}
);
</script>';
return $html;
}
public function ajaxProcessProductManufacturers()
{
$manufacturers = Manufacturer::getManufacturers();
@@ -3114,12 +2936,17 @@ class AdminProductsControllerCore extends AdminController
foreach ($selected_cat as $key => $category)
$categories[] = $key;
$tree = new HelperTreeCategories('associated-categories-tree', 'Associated categories');
$tree->setRootCategory($root->id)
->setUseCheckBox(true)
->setUseSearch(true)
->setSelectedCategories($categories);
$data->assign(array('default_category' => $default_category,
'selected_cat_ids' => implode(',', array_keys($selected_cat)),
'selected_cat' => $selected_cat,
'id_category_default' => $product->getDefaultCategory(),
'category_tree' => $this->renderAssociationsCategoriesTree(
$root->id, $categories),
'category_tree' => $tree->render(),
'product' => $product,
'link' => $this->context->link,
'is_shop_context' => Shop::getContext() == Shop::CONTEXT_SHOP
+57 -44
View File
@@ -79,12 +79,14 @@ class Dashactivity extends Module
$gapi = Module::isInstalled('gapi') ? Module::getInstanceByName('gapi') : false;
if (Validate::isLoadedObject($gapi) && $gapi->isConfigured())
{
$visits = $unique_visitors = 0;
$visits = $unique_visitors = $online_visitor = 0;
if ($result = $gapi->requestReportData('', 'ga:visits,ga:visitors', $params['date_from'], $params['date_to'], null, null, 1, 1))
{
$visits = $result[0]['metrics']['visits'];
$unique_visitors = $result[0]['metrics']['visitors'];
}
if ($result = $gapi->requestReportData('', 'ga:activeVisitors', null, null, null, null, 1, 1))
$online_visitor = $result[0]['metrics']['activeVisitors'];
}
else
{
@@ -94,6 +96,24 @@ class Dashactivity extends Module
WHERE `date_add` BETWEEN "'.pSQL($params['date_from']).'" AND "'.pSQL($params['date_to']).'"
'.Shop::addSqlRestriction(false));
extract($row);
if ($maintenance_ips = Configuration::get('PS_MAINTENANCE_IP'))
$maintenance_ips = implode(',', array_map('ip2long', array_map('trim', explode(',', $maintenance_ips))));
if (Configuration::get('PS_STATSDATA_CUSTOMER_PAGESVIEWS'))
$sql = 'SELECT COUNT(DISTINCT c.id_connections)
FROM `'._DB_PREFIX_.'connections` c
LEFT JOIN `'._DB_PREFIX_.'connections_page` cp ON c.id_connections = cp.id_connections
WHERE TIME_TO_SEC(TIMEDIFF(NOW(), cp.`time_start`)) < 900
AND cp.`time_end` IS NULL
'.Shop::addSqlRestriction(false, 'c').'
'.($maintenance_ips ? 'AND c.ip_address NOT IN ('.preg_replace('/[^,0-9]/', '', $maintenance_ips).')' : '');
else
$sql = 'SELECT COUNT(*)
FROM `'._DB_PREFIX_.'connections`
WHERE TIME_TO_SEC(TIMEDIFF(NOW(), `date_add`)) < 900
'.Shop::addSqlRestriction(false).'
'.($maintenance_ips ? 'AND ip_address NOT IN ('.preg_replace('/[^,0-9]/', '', $maintenance_ips).')' : '');
$online_visitor = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
}
$order_nbr = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
@@ -129,25 +149,7 @@ class Dashactivity extends Module
LEFT JOIN `'._DB_PREFIX_.'customer_message` cm ON ct.id_customer_thread = cm.id_customer_thread
WHERE cm.`date_add` BETWEEN "'.pSQL($params['date_from']).'" AND "'.pSQL($params['date_to']).'"
'.Shop::addSqlRestriction(false, 'ct'));
if ($maintenance_ips = Configuration::get('PS_MAINTENANCE_IP'))
$maintenance_ips = implode(',', array_map('ip2long', array_map('trim', explode(',', $maintenance_ips))));
if (Configuration::get('PS_STATSDATA_CUSTOMER_PAGESVIEWS'))
$sql = 'SELECT COUNT(DISTINCT c.id_connections)
FROM `'._DB_PREFIX_.'connections` c
LEFT JOIN `'._DB_PREFIX_.'connections_page` cp ON c.id_connections = cp.id_connections
WHERE TIME_TO_SEC(TIMEDIFF(NOW(), cp.`time_start`)) < 900
AND cp.`time_end` IS NULL
'.Shop::addSqlRestriction(false, 'c').'
'.($maintenance_ips ? 'AND c.ip_address NOT IN ('.preg_replace('/[^,0-9]/', '', $maintenance_ips).')' : '');
else
$sql = 'SELECT COUNT(*)
FROM `'._DB_PREFIX_.'connections`
WHERE TIME_TO_SEC(TIMEDIFF(NOW(), `date_add`)) < 900
'.Shop::addSqlRestriction(false).'
'.($maintenance_ips ? 'AND ip_address NOT IN ('.preg_replace('/[^,0-9]/', '', $maintenance_ips).')' : '');
$online_visitor = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
$active_shopping_cart = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
SELECT COUNT(*)
FROM `'._DB_PREFIX_.'cart`
@@ -208,7 +210,7 @@ class Dashactivity extends Module
'orders_trends' => array('way' => 'down', 'value' => 0.42),
),
'data_list_small' => array(
'dash_traffic_source' => $this->getReferer($params['date_from'], $params['date_to']),
'dash_traffic_source' => $this->getReferer($params['date_from'], $params[ 'date_to']),
),
'data_chart' => array(
'dash_trends_chart1' => $this->getChartTrafficSource($params['date_from'], $params['date_to']),
@@ -228,31 +230,42 @@ class Dashactivity extends Module
public function getReferer($date_from, $date_to, $limit = 10)
{
$directLink = $this->l('Direct link');
$sql = 'SELECT http_referer
FROM '._DB_PREFIX_.'connections
WHERE 1
'.Shop::addSqlRestriction().'
AND date_add BETWEEN '.$date_from.' AND '.$date_to.'
LIMIT 0, '.(int)$limit;
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->query($sql);
$websites = array($directLink => 0);
while ($row = Db::getInstance(_PS_USE_SQL_SLAVE_)->nextRow($result))
$gapi = Module::isInstalled('gapi') ? Module::getInstanceByName('gapi') : false;
if (Validate::isLoadedObject($gapi) && $gapi->isConfigured())
{
if (!isset($row['http_referer']) || empty($row['http_referer']))
++$websites[$directLink];
else
{
$website = preg_replace('/^www./', '', parse_url($row['http_referer'], PHP_URL_HOST));
if (!isset($websites[$website]))
$websites[$website] = 1;
else
++$websites[$website];
}
$websites = array();
if ($result = $gapi->requestReportData('ga:source', 'ga:visitors', $date_from, $date_to, '-ga:visitors', null, 1, 3))
foreach ($result as $row)
$websites[$row['dimensions']['source']] = $row['metrics']['visitors'];
}
else
{
$directLink = $this->l('Direct link');
$sql = 'SELECT http_referer
FROM '._DB_PREFIX_.'connections
WHERE 1
'.Shop::addSqlRestriction().'
AND date_add BETWEEN '.$date_from.' AND '.$date_to.'
LIMIT 0, '.(int)$limit;
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->query($sql);
$websites = array($directLink => 0);
while ($row = Db::getInstance(_PS_USE_SQL_SLAVE_)->nextRow($result))
{
if (!isset($row['http_referer']) || empty($row['http_referer']))
++$websites[$directLink];
else
{
$website = preg_replace('/^www./', '', parse_url($row['http_referer'], PHP_URL_HOST));
if (!isset($websites[$website]))
$websites[$website] = 1;
else
++$websites[$website];
}
}
arsort($websites);
}
arsort($websites);
return $websites;
}
+1 -1
View File
@@ -93,7 +93,7 @@ class Dashtrends extends Module
$gapi = Module::isInstalled('gapi') ? Module::getInstanceByName('gapi') : false;
if (Validate::isLoadedObject($gapi) && $gapi->isConfigured())
{
if ($result = $gapi->requestReportData('ga:date', 'ga:visits', $params['date_from'], $params['date_to'], null, null, 1, 1))
if ($result = $gapi->requestReportData('ga:date', 'ga:visits', $params['date_from'], $params['date_to'], null, null, 1, 9999))
foreach ($result as $row)
$tmp_data['visits_score'][strtotime(preg_replace('/^([0-9]{4})([0-9]{2})([0-9]{2})$/', '$1-$2-$3', $row['dimensions']['date']))] = $row['metrics']['visits'];
}
+22 -21
View File
@@ -29,8 +29,8 @@ if (!defined('_PS_VERSION_'))
class Gapi extends Module
{
public function __construct($type = null)
{
public function __construct()
{
$this->name = 'gapi';
$this->tab = 'administration';
$this->version = 0.9;
@@ -40,8 +40,8 @@ class Gapi extends Module
parent::__construct();
$this->displayName = $this->l('Google Analytics API');
}
}
public function isConfigured()
{
return ($this->active && $this->api_3_0_isConfigured());
@@ -64,7 +64,7 @@ class Gapi extends Module
'.(($curl && $allow_url_fopen) ? '' : '<li>'.$this->l('You are not allowed to open external URLs').'</li>').'
'.(($curl && $allow_url_fopen) ? '' : '<li>'.$this->l('cURL is not enabled').'</li>').'
'.($openssl ? '' : '<li>'.$this->l('OpenSSL is not enabled').'</li>').'
'.(($allow_url_fopen AND $openssl AND !$ping) ? '<li>'.$this->l('Google is unreachable').' ('.$this->l('check your firewall').')</li>' : '').'
'.(($allow_url_fopen && $openssl && !$ping) ? '<li>'.$this->l('Google is unreachable').' ('.$this->l('check your firewall').')</li>' : '').'
'.($online ? '' : '<li>'.$this->l('Your store is not online').'</li>').'
</ul>');
}
@@ -73,7 +73,7 @@ class Gapi extends Module
return $html.$this->api_3_0_getContent();
}
public function requestReportData($dimensions, $metrics, $date_from, $date_to, $sort = null, $filters = null, $start = 1, $limit = 30)
public function requestReportData($dimensions, $metrics, $date_from = null, $date_to = null, $sort = null, $filters = null, $start = 1, $limit = 30)
{
// You can switch to the 1.3 API by replacing the following function call by $this->api_1_3_requestReportData()
return $this->api_3_0_requestReportData($dimensions, $metrics, $date_from, $date_to, $sort, $filters, $start, $limit);
@@ -93,7 +93,7 @@ class Gapi extends Module
);
Tools::redirectLink('https://accounts.google.com/o/oauth2/auth?'.http_build_query($params));
}
public function api_3_0_refreshtoken()
{
$params = array(
@@ -179,7 +179,7 @@ class Gapi extends Module
$html .= $this->displayConfirmation(sprintf($this->l('Yesterday, your store received the visit of %d people for a total of %d unique page views.'), $result_test[0]['metrics']['visits'], $result_test[0]['metrics']['uniquePageviews']));
}
}
if ($display_slider)
{
$slides = array(
@@ -195,7 +195,7 @@ class Gapi extends Module
'Google API - 10 - Profile ID.png' => $this->l('Now you need the ID of the Analytics Profile you want to connect. In order to find you Profile ID, connect to the Analytics dashboard look at the URL in the address bar. Your Profile ID is the number following a "p", as shown underlined in red on the screenshot')
);
$first_slide = key($slides);
$html .= '
<a id="screenshots_button" href="#screenshots"><button class="btn btn-default"><i class="icon-question-sign"></i> How to configure Google Analytics API</button></a>
<div style="display:none">
@@ -264,7 +264,7 @@ class Gapi extends Module
return $html.$helper->generateOptions($fields_options);
}
public function api_3_0_oauth2callback()
{
if (!Tools::getValue('state'))
@@ -326,9 +326,10 @@ class Gapi extends Module
'timeout' => 5,
)
));
if (!$response_json = Tools::file_get_contents('https://www.googleapis.com/analytics/v3/data/ga?'.$content, false, $stream_context))
$api = ($date_from && $date_to) ? 'ga' : 'realtime';
if (!$response_json = Tools::file_get_contents('https://www.googleapis.com/analytics/v3/data/'.$api.'?'.$content, false, $stream_context))
return false;
// https://developers.google.com/analytics/devguides/reporting/core/v3/reference
$response = Tools::jsonDecode($response_json, true);
@@ -337,7 +338,7 @@ class Gapi extends Module
{
$metrics = array();
$dimensions = array();
foreach($row as $key => $value)
foreach ($row as $key => $value)
if ($response['columnHeaders'][$key]['columnType'] == 'DIMENSION')
$dimensions[str_replace('ga:', '', $response['columnHeaders'][$key]['name'])] = $value;
elseif ($response['columnHeaders'][$key]['columnType'] == 'METRIC')
@@ -351,7 +352,7 @@ class Gapi extends Module
{
return (Configuration::get('PS_GAPI13_EMAIL') && Configuration::get('PS_GAPI13_PASSWORD') && Configuration::get('PS_GAPI13_PROFILE'));
}
public function api_1_3_getContent()
{
$html = '';
@@ -448,17 +449,17 @@ class Gapi extends Module
if ($filters !== null)
$params['filters'] = $filters;
$content = str_replace('&amp;', '&', urldecode(http_build_query($params)));
$stream_context = stream_context_create(array(
'http' => array(
'method'=> 'GET',
'header' => "Authorization: GoogleLogin auth=".$this->auth_token."\r\n",
'header' => 'Authorization: GoogleLogin auth='.$this->auth_token."\r\n",
'timeout' => 5,
)
));
if (!$response = Tools::file_get_contents('https://www.google.com/analytics/feeds/data?'.$content, false, $stream_context))
return false;
$xml = simplexml_load_string($response);
/* Meta data not useful at this time */
@@ -485,21 +486,21 @@ class Gapi extends Module
$metrics = array();
foreach ($entry->children('http://schemas.google.com/analytics/2009')->metric as $metric)
{
$key = str_replace('ga:','',$metric->attributes()->name);
$key = str_replace('ga:', '', $metric->attributes()->name);
$metric_value = strval($metric->attributes()->value);
if (preg_match('/^(\d+\.\d+)|(\d+E\d+)|(\d+.\d+E\d+)$/',$metric_value))
if (preg_match('/^(\d+\.\d+)|(\d+E\d+)|(\d+.\d+E\d+)$/', $metric_value))
$metrics[$key] = floatval($metric_value);
else
$metrics[$key] = intval($metric_value);
}
$dimensions = array();
foreach($entry->children('http://schemas.google.com/analytics/2009')->dimension as $dimension)
foreach ($entry->children('http://schemas.google.com/analytics/2009')->dimension as $dimension)
$dimensions[str_replace('ga:', '', $dimension->attributes()->name)] = strval($dimension->attributes()->value);
$result[] = array('metrics' => $metrics, 'dimensions' => $dimensions);
}
return $result;
}
}
+24
View File
@@ -1,4 +1,28 @@
<?php
/*
* 2007-2013 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2013 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
include(dirname(__FILE__).'/../../config/config.inc.php');
include(dirname(__FILE__).'/gapi.php');