From a8e6dfe7f5e58ed504c5ca2ab6b561e5064a236a Mon Sep 17 00:00:00 2001 From: djfm Date: Wed, 4 Dec 2013 15:03:04 +0000 Subject: [PATCH 1/3] // fixed undefined variable in blocktopmenu --- modules/blocktopmenu/blocktopmenu.php | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/blocktopmenu/blocktopmenu.php b/modules/blocktopmenu/blocktopmenu.php index d739df782..4555df282 100644 --- a/modules/blocktopmenu/blocktopmenu.php +++ b/modules/blocktopmenu/blocktopmenu.php @@ -962,6 +962,7 @@ class Blocktopmenu extends Module { if ($link['label'] == '') { + $default_language = Configuration::get('PS_LANG_DEFAULT'); $link = MenuTopLinks::get($link['id_linksmenutop'], $default_language, (int)Shop::getContextShopID()); $html .= ''; } From 2f088c4ac33b35f183179499af0f256116c4cc42 Mon Sep 17 00:00:00 2001 From: Damien Metzger Date: Wed, 4 Dec 2013 16:06:42 +0100 Subject: [PATCH 2/3] [*] BO : changed dashgoals system --- modules/dashgoals/dashgoals.php | 125 ++++++++++++++++++------ modules/dashgoals/views/js/dashgoals.js | 5 +- 2 files changed, 99 insertions(+), 31 deletions(-) diff --git a/modules/dashgoals/dashgoals.php b/modules/dashgoals/dashgoals.php index d412a0614..ab25dd934 100644 --- a/modules/dashgoals/dashgoals.php +++ b/modules/dashgoals/dashgoals.php @@ -149,45 +149,110 @@ class Dashgoals extends Module public function getChartData($year) { + // Retrieve gross data from AdminStatsController $visits = AdminStatsController::getVisits(false, $year.date('-01-01'), $year.date('-12-31'), 'month'); $orders = AdminStatsController::getOrders($year.date('-01-01'), $year.date('-12-31'), 'month'); $sales = AdminStatsController::getTotalSales($year.date('-01-01'), $year.date('-12-31'), 'month'); - $stream1 = array('key' => $this->l('Traffic'), 'values' => array(), 'disabled' => true); - $stream2 = array('key' => $this->l('Conversion Rate'), 'values' => array()); - $stream3 = array('key' => $this->l('Average Cart Value'), 'values' => array()); - $stream4 = array('key' => $this->l('Sales'), 'values' => array()); + // There are stream types (different charts) and for each types there are 3 available zones (one color for the goal, one if you over perform and one if you under perfom) + $stream_types = array('traffic', 'conversion', 'avg_cart_value', 'sales'); + $stream_zones = array('real', 'more', 'less'); + // We initialize all the streams types for all the zones + $streams = array(); + $average_goals = array(); + foreach ($stream_types as $stream_type) + { + $streams[$stream_type] = array(); + foreach ($stream_zones as $stream_zone) + $streams[$stream_type][$stream_zone] = array( + 'key' => $stream_type.'_'.$stream_zone, + 'color' => ($stream_zone == 'more' ? '#333333' : ($stream_zone == 'less' ? '#DDDDDD' : '#999999')), + 'values' => array(), + 'disabled' => $stream_type == 'sales' ? false : true + ); + + $average_goals[$stream_type] = 0; + } + + // We need to calculate the average value of each goals for the year, this will be the base rate for "100%" + for ($i = '01'; $i <= 12; $i = sprintf('%02d', $i + 1)) + { + $average_goals['traffic'] += ConfigurationKPI::get('DASHGOALS_TRAFFIC_'.$i.'_'.$year); + $average_goals['conversion'] += ConfigurationKPI::get('DASHGOALS_CONVERSION_'.$i.'_'.$year) / 100; + $average_goals['avg_cart_value'] += ConfigurationKPI::get('DASHGOALS_AVG_CART_VALUE_'.$i.'_'.$year); + } + foreach ($average_goals as &$average_goal) + $average_goal /= 12; + $average_goals['sales'] = $average_goals['traffic'] * $average_goals['conversion'] * $average_goals['avg_cart_value']; + + // Now we can calculate the value for every months for ($i = '01'; $i <= 12; $i = sprintf('%02d', $i + 1)) { $timestamp = strtotime($year.'-'.$i.'-01'); - - $goal = ConfigurationKPI::get(strtoupper('dashgoals_traffic_'.$i.'_'.$year)); - $value = 0; - if ($goal && isset($visits[$timestamp])) - $value = round($visits[$timestamp] / $goal, 2); - $stream1['values'][] = array('x' => Dashgoals::$month_labels[$i], 'y' => $value); - $goal = ConfigurationKPI::get(strtoupper('dashgoals_conversion_'.$i.'_'.$year)); - $value = 0; - if ($goal && isset($visits[$timestamp]) && $visits[$timestamp] && isset($orders[$timestamp]) && $orders[$timestamp]) - $value = round((100 * $orders[$timestamp] / $visits[$timestamp]) / $goal, 2); - $stream2['values'][] = array('x' => Dashgoals::$month_labels[$i], 'y' => $value); - - $goal = ConfigurationKPI::get(strtoupper('dashgoals_avg_cart_value_'.$i.'_'.$year)); - $value = 0; - if ($goal && isset($orders[$timestamp]) && $orders[$timestamp] && isset($sales[$timestamp]) && $sales[$timestamp]) - $value = round(($sales[$timestamp] / $orders[$timestamp]) / $goal, 2); - $stream3['values'][] = array('x' => Dashgoals::$month_labels[$i], 'y' => $value); - - $goal = ConfigurationKPI::get(strtoupper('dashgoals_traffic_'.$i.'_'.$year)) - * ConfigurationKPI::get(strtoupper('dashgoals_conversion_'.$i.'_'.$year)) / 100 - * ConfigurationKPI::get(strtoupper('dashgoals_avg_cart_value_'.$i.'_'.$year)); - $value = 0; - if ($goal && isset($sales[$timestamp]) && $sales[$timestamp]) - $value = round($sales[$timestamp] / $goal, 2); - $stream4['values'][] = array('x' => Dashgoals::$month_labels[$i], 'y' => $value); + $month_goal = ConfigurationKPI::get('DASHGOALS_TRAFFIC_'.$i.'_'.$year); + $value = (isset($visits[$timestamp]) ? $visits[$timestamp] : 0); + $stream_values = $this->getValuesFromGoals($average_goals['traffic'], $month_goal, $value, Dashgoals::$month_labels[$i]); + foreach ($stream_zones as $stream_zone) + $streams['traffic'][$stream_zone]['values'][] = $stream_values[$stream_zone]; + + $month_goal = ConfigurationKPI::get('DASHGOALS_CONVERSION_'.$i.'_'.$year); + $value = 100 * ((isset($visits[$timestamp]) && $visits[$timestamp]) ? ($orders[$timestamp] / $visits[$timestamp]) : 0); + $stream_values = $this->getValuesFromGoals($average_goals['conversion'], $month_goal, $value, Dashgoals::$month_labels[$i]); + foreach ($stream_zones as $stream_zone) + $streams['conversion'][$stream_zone]['values'][] = $stream_values[$stream_zone]; + + $month_goal = ConfigurationKPI::get('DASHGOALS_AVG_CART_VALUE_'.$i.'_'.$year); + $value = ((isset($orders[$timestamp]) && $orders[$timestamp]) ? ($sales[$timestamp] / $orders[$timestamp]) : 0); + $stream_values = $this->getValuesFromGoals($average_goals['avg_cart_value'], $month_goal, $value, Dashgoals::$month_labels[$i]); + foreach ($stream_zones as $stream_zone) + $streams['avg_cart_value'][$stream_zone]['values'][] = $stream_values[$stream_zone]; + + $month_goal = ConfigurationKPI::get('DASHGOALS_TRAFFIC_'.$i.'_'.$year) * ConfigurationKPI::get('DASHGOALS_CONVERSION_'.$i.'_'.$year) / 100 * ConfigurationKPI::get('DASHGOALS_AVG_CART_VALUE_'.$i.'_'.$year); + $stream_values = $this->getValuesFromGoals($average_goals['sales'], $month_goal, isset($sales[$timestamp]) ? $sales[$timestamp] : 0, Dashgoals::$month_labels[$i]); + foreach ($stream_zones as $stream_zone) + $streams['sales'][$stream_zone]['values'][] = $stream_values[$stream_zone]; } - return array('chart_type' => 'bar_chart_goals', 'data' => array($stream1, $stream2, $stream3, $stream4)); + + // Merge all the streams before sending + $all_streams = array(); + foreach ($stream_types as $stream_type) + foreach ($stream_zones as $stream_zone) + $all_streams[] = $streams[$stream_type][$stream_zone]; + + return array('chart_type' => 'bar_chart_goals', 'data' => $all_streams); + } + + protected function getValuesFromGoals($average_goal, $month_goal, $value, $label) + { + // Initialize value for each zone + $stream_values = array('real' => array('x' => $label, 'y' => 0), 'less' => array('x' => $label, 'y' => 0), 'more' => array('x' => $label, 'y' => 0)); + + // Calculate the percentage of fullfilment of the goal + $fullfilment = 0; + if ($value && $month_goal) + $fullfilment = round($value / $month_goal, 2); + + // Base rate is essential here : it determines the value of the goal compared to the "100%" of the chart legend + $base_rate = $month_goal / $average_goal; + + // Fullfilment of 1 means that we performed exactly anticipated + if ($fullfilment == 1) + $stream_values['real'] = array('x' => $label, 'y' => $base_rate); + // Fullfilment lower than 1 means that we UNDER performed + elseif ($fullfilment < 1) // + { + $stream_values['real'] = array('x' => $label, 'y' => $fullfilment * $base_rate); + $stream_values['less'] = array('x' => $label, 'y' => $base_rate - ($fullfilment * $base_rate)); + } + // Fullfilment greater than 1 means that we OVER performed + elseif ($fullfilment > 1) + { + $stream_values['real'] = array('x' => $label, 'y' => $base_rate); + $stream_values['more'] = array('x' => $label, 'y' => ($fullfilment * $base_rate) - $base_rate); + } + + return $stream_values; } } \ No newline at end of file diff --git a/modules/dashgoals/views/js/dashgoals.js b/modules/dashgoals/views/js/dashgoals.js index d01a2209b..8168c4b27 100644 --- a/modules/dashgoals/views/js/dashgoals.js +++ b/modules/dashgoals/views/js/dashgoals.js @@ -2,10 +2,13 @@ function bar_chart_goals(widget_name, chart_details) { nv.addGraph(function() { var chart = nv.models.multiBarChart() - .stacked(false) + .stacked(true) .showControls(false) .tooltipContent(function(key, y, e, graph) { var perf = parseInt(e) - 100; + + return '/modules/dashgoals/views/js/dashgoals.js : Deprecated, now we need to retrieve the content with ajax'; + if (perf > 0) return '
' + key + '
+' + perf + '%
'; else if (perf < 0) From 33b5327b4db66390af57600f7d9899fe1a5ff953 Mon Sep 17 00:00:00 2001 From: Kevin Granger Date: Wed, 4 Dec 2013 16:58:34 +0100 Subject: [PATCH 3/3] // data-id-product instead of using rel tag --- .../js/products-comparison.js | 19 ++++++++++--------- themes/default-bootstrap/product-list.tpl | 2 +- .../default-bootstrap/products-comparison.tpl | 4 ++-- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/themes/default-bootstrap/js/products-comparison.js b/themes/default-bootstrap/js/products-comparison.js index 75666fe4c..5595d9f65 100644 --- a/themes/default-bootstrap/js/products-comparison.js +++ b/themes/default-bootstrap/js/products-comparison.js @@ -58,11 +58,12 @@ function addToCompare(productId){ function compareButtonsStatusRefresh(){ $('.addToCompare').each(function() { - if ($.inArray(parseInt($(this).prop('rel')),comparedProductsIds)!= -1){ + console.log($(this).data('id-product')); + if ($.inArray(parseInt($(this).data('id-product')),comparedProductsIds)!= -1){ $(this).addClass('checked'); } else { - $(this).removeClass('checked'); + $(this).removeClass('checked'); } }) } @@ -74,19 +75,19 @@ function totalValue(value) { reloadProductComparison = function() { $('a.cmp_remove').click(function(){ - var idProduct = $(this).prop('rel').replace('ajax_id_product_', ''); + var idProduct = $(this).data('id-product'); $.ajax({ - url: 'index.php?controller=products-comparison&ajax=1&action=remove&id_product=' + idProduct, - async: false, - cache: false, - success: function(){ + url: 'index.php?controller=products-comparison&ajax=1&action=remove&id_product=' + idProduct, + async: false, + cache: false, + success: function(){ return true; } - }); + }); }); } $(document).ready(function() { - compareButtonsStatusRefresh(); + compareButtonsStatusRefresh(); }); \ No newline at end of file diff --git a/themes/default-bootstrap/product-list.tpl b/themes/default-bootstrap/product-list.tpl index ee6152b40..cf3133be7 100644 --- a/themes/default-bootstrap/product-list.tpl +++ b/themes/default-bootstrap/product-list.tpl @@ -130,7 +130,7 @@ {hook h='displayProductListFunctionalButtons' product=$product} {if isset($comparator_max_item) && $comparator_max_item} {/if} diff --git a/themes/default-bootstrap/products-comparison.tpl b/themes/default-bootstrap/products-comparison.tpl index 76fbf314c..7b9043d19 100644 --- a/themes/default-bootstrap/products-comparison.tpl +++ b/themes/default-bootstrap/products-comparison.tpl @@ -50,7 +50,7 @@
- +