Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Controller.php « Ecommerce « plugins - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7cfb95518416b245264b65e7e10a9a60f35b316d (plain)
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
117
118
119
120
121
122
123
124
<?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\Ecommerce;

use Exception;
use Piwik\DataTable;
use Piwik\FrontController;
use Piwik\Piwik;
use Piwik\Translation\Translator;
use Piwik\View;
use Piwik\Plugins\Goals\TranslationHelper;

class Controller extends \Piwik\Plugins\Goals\Controller
{
    /**
     * @var Translator
     */
    private $translator;

    public function __construct(Translator $translator, TranslationHelper $translationHelper)
    {
        $this->translator = $translator;

        parent::__construct($translator, $translationHelper);
    }

    public function ecommerceReport()
    {
        if (!\Piwik\Plugin\Manager::getInstance()->isPluginActivated('CustomVariables')) {
            throw new Exception("Ecommerce Tracking requires that the plugin Custom Variables is enabled. Please enable the plugin CustomVariables (or ask your admin).");
        }

        $view = $this->getGoalReportView($idGoal = Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER);
        $view->displayFullReport = false;
        $view->headline = $this->translator->translate('General_EvolutionOverPeriod');

        return $view->render();
    }

    public function ecommerceLogReport($fetch = false)
    {
        $view = new View('@Ecommerce/ecommerceLog');
        $this->setGeneralVariablesView($view);

        $view->ecommerceLog = $this->getEcommerceLog($fetch);

        return $view->render();
    }

    public function getEcommerceLog($fetch = false)
    {
        $saveGET = $_GET;
        $_GET['segment'] = urlencode('visitEcommerceStatus!=none');
        $_GET['widget'] = 1;
        $output = FrontController::getInstance()->dispatch('Live', 'getVisitorLog', array($fetch));
        $_GET   = $saveGET;

        return $output;
    }

    public function index()
    {
        return $this->ecommerceReport();
    }

    public function products()
    {
        $goal = $this->getMetricsForGoal(Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER);
        $conversions = 0;
        if (!empty($goal['nb_conversions'])) {
            $conversions = $goal['nb_conversions'];
        }

        $goal = $this->getMetricsForGoal(Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_CART);

        $cartNbConversions = 0;
        if (!empty($goal) && array_key_exists('nb_conversions', $goal)) {
            $cartNbConversions = $goal['nb_conversions'];
        }

        $preloadAbandonedCart = $cartNbConversions !== false && $conversions == 0;

        $goalReportsByDimension = new View\ReportsByDimension('Goals');

        $ecommerceCustomParams = array();
        if ($preloadAbandonedCart) {
            $ecommerceCustomParams['abandonedCarts'] = '1';
        } else {
            $ecommerceCustomParams['abandonedCarts'] = '0';
        }

        $goalReportsByDimension->addReport(
            'Goals_Products', 'Goals_ProductSKU', 'Goals.getItemsSku', $ecommerceCustomParams);
        $goalReportsByDimension->addReport(
            'Goals_Products', 'Goals_ProductName', 'Goals.getItemsName', $ecommerceCustomParams);
        $goalReportsByDimension->addReport(
            'Goals_Products', 'Goals_ProductCategory', 'Goals.getItemsCategory', $ecommerceCustomParams);

        $view = new View('@Ecommerce/products');
        $this->setGeneralVariablesView($view);

        $view->productsByDimension = $goalReportsByDimension->render();
        return $view->render();
    }

    public function sales()
    {
        $viewOverview = $this->getGoalReportView(Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER);
        $reportsByDimension = $viewOverview->goalReportsByDimension;

        $view = new View('@Ecommerce/sales');
        $this->setGeneralVariablesView($view);

        $view->goalReportsByDimension = $reportsByDimension;
        return $view->render();
    }

}