1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Plugins\Goals\Reports;
use Piwik\Common;
use Piwik\Metrics\Formatter;
use Piwik\Piwik;
use Piwik\Plugin\Report;
use Piwik\Plugin\ViewDataTable;
use Piwik\Plugins\Goals\Goals;
use Piwik\Plugins\Goals\Metrics\AveragePrice;
use Piwik\Plugins\Goals\Metrics\AverageQuantity;
use Piwik\Plugins\Goals\Metrics\ProductConversionRate;
abstract class BaseEcommerceItem extends BaseEcommerce
{
protected function init()
{
parent::init();
$this->processedMetrics = array(
new AveragePrice(),
new AverageQuantity(),
new ProductConversionRate()
);
$this->metrics = array(
'revenue', 'quantity', 'orders', 'nb_visits'
);
}
public function getMetrics()
{
$metrics = parent::getMetrics();
$metrics['revenue'] = Piwik::translate('General_ProductRevenue');
$metrics['orders'] = Piwik::translate('General_UniquePurchases');
return $metrics;
}
public function getMetricsDocumentation()
{
if ($this->isAbandonedCart()) {
return array(
'revenue' => Piwik::translate('Goals_ColumnRevenueDocumentation',
Piwik::translate('Goals_DocumentationRevenueGeneratedByProductSales')),
'quantity' => Piwik::translate('Goals_ColumnQuantityDocumentation', $this->name),
'orders' => Piwik::translate('Goals_ColumnOrdersDocumentation', $this->name),
'avg_price' => Piwik::translate('Goals_ColumnAveragePriceDocumentation', $this->name),
'avg_quantity' => Piwik::translate('Goals_ColumnAverageQuantityDocumentation', $this->name),
'nb_visits' => Piwik::translate('Goals_ColumnVisitsProductDocumentation', $this->name),
'conversion_rate' => Piwik::translate('Goals_ColumnConversionRateProductDocumentation', $this->name),
);
}
return array();
}
public function configureView(ViewDataTable $view)
{
$idSite = Common::getRequestVar('idSite');
$view->config->show_ecommerce = true;
$view->config->show_table = false;
$view->config->show_all_views_icons = false;
$view->config->show_exclude_low_population = false;
$view->config->show_table_all_columns = false;
$moneyColumns = array('revenue');
$formatter = array(new Formatter(), 'getPrettyMoney');
$view->config->filters[] = array('ColumnCallbackReplace', array($moneyColumns, $formatter, array($idSite)));
$view->requestConfig->filter_limit = 10;
$view->requestConfig->filter_sort_column = 'revenue';
$view->requestConfig->filter_sort_order = 'desc';
$view->config->custom_parameters['isFooterExpandedInDashboard'] = true;
// set columns/translations which differ based on viewDataTable TODO: shouldn't have to do this check...
// amount of reports should be dynamic, but metadata should be static
$columns = array_merge($this->getMetrics(), $this->getProcessedMetrics());
$columnsOrdered = array('label', 'revenue', 'quantity', 'orders', 'avg_price', 'avg_quantity',
'nb_visits', 'conversion_rate');
$abandonedCart = $this->isAbandonedCart();
if ($abandonedCart) {
$columns['abandoned_carts'] = Piwik::translate('General_AbandonedCarts');
$columns['revenue'] = Piwik::translate('Goals_LeftInCart', $columns['revenue']);
$columns['quantity'] = Piwik::translate('Goals_LeftInCart', $columns['quantity']);
$columns['avg_quantity'] = Piwik::translate('Goals_LeftInCart', $columns['avg_quantity']);
unset($columns['orders']);
unset($columns['conversion_rate']);
$view->requestConfig->request_parameters_to_modify['abandonedCarts'] = '1';
$columnsOrdered = array('label', 'revenue', 'quantity', 'avg_price', 'avg_quantity', 'nb_visits',
'abandoned_carts');
}
$translations = array_merge(array('label' => $this->name), $columns);
$view->config->addTranslations($translations);
$view->config->columns_to_display = $columnsOrdered;
$view->config->custom_parameters['viewDataTable'] =
$abandonedCart ? Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_CART : Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER;
}
private function isAbandonedCart()
{
return Common::getRequestVar('viewDataTable', 'ecommerceOrder', 'string') == 'ecommerceAbandonedCart';
}
}
|