diff options
author | Thomas Steur <thomas.steur@gmail.com> | 2015-07-03 03:54:27 +0300 |
---|---|---|
committer | sgiehl <stefan@piwik.org> | 2015-10-06 18:25:13 +0300 |
commit | 9ba8f216fd7856ce5fef06bf82ecb8f8a2e7e630 (patch) | |
tree | 6ce07d18a85d00b39ab720abe042361c0775aead /plugins/Ecommerce/Controller.php | |
parent | 8ccc9dc05da021325cdbf141a548637fa52f16b2 (diff) |
generate pages instead of implementing them in each controller
Diffstat (limited to 'plugins/Ecommerce/Controller.php')
-rw-r--r-- | plugins/Ecommerce/Controller.php | 117 |
1 files changed, 49 insertions, 68 deletions
diff --git a/plugins/Ecommerce/Controller.php b/plugins/Ecommerce/Controller.php index 7cfb955184..780c905c7c 100644 --- a/plugins/Ecommerce/Controller.php +++ b/plugins/Ecommerce/Controller.php @@ -8,7 +8,8 @@ */ namespace Piwik\Plugins\Ecommerce; -use Exception; +use Piwik\API\Request; +use Piwik\Common; use Piwik\DataTable; use Piwik\FrontController; use Piwik\Piwik; @@ -30,95 +31,75 @@ class Controller extends \Piwik\Plugins\Goals\Controller parent::__construct($translator, $translationHelper); } - public function ecommerceReport() + public function getSparklines() { - 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)."); - } + $idGoal = Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER; - $view = $this->getGoalReportView($idGoal = Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER); - $view->displayFullReport = false; - $view->headline = $this->translator->translate('General_EvolutionOverPeriod'); + $view = new View('@Ecommerce/getSparklines'); + $view->onlyConversionOverview = false; + $view->conversionsOverViewEnabled = true; - return $view->render(); - } + if ($idGoal == Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER) { + $goalDefinition['name'] = $this->translator->translate('Goals_Ecommerce'); + $goalDefinition['allow_multiple'] = true; + } else { + if (!isset($this->goals[$idGoal])) { + Piwik::redirectToModule('Goals', 'index', array('idGoal' => null)); + } + $goalDefinition = $this->goals[$idGoal]; + } - public function ecommerceLogReport($fetch = false) - { - $view = new View('@Ecommerce/ecommerceLog'); $this->setGeneralVariablesView($view); - $view->ecommerceLog = $this->getEcommerceLog($fetch); - - return $view->render(); - } + $goal = $this->getMetricsForGoal($idGoal); + foreach ($goal as $name => $value) { + $view->$name = $value; + } - 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; + if ($idGoal == Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER) { + $goal = $this->getMetricsForGoal(Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_CART); + foreach ($goal as $name => $value) { + $name = 'cart_' . $name; + $view->$name = $value; + } + } - return $output; - } + $view->idGoal = $idGoal; + $view->goalAllowMultipleConversionsPerVisit = $goalDefinition['allow_multiple']; - public function index() - { - return $this->ecommerceReport(); + return $view->render(); } - public function products() + public function getConversionsOverview() { - $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']; - } + $view = new View('@Ecommerce/conversionOverview'); + $idGoal = Common::getRequestVar('idGoal', null, 'string'); - $preloadAbandonedCart = $cartNbConversions !== false && $conversions == 0; + $goalMetrics = Request::processRequest('Goals.get', array('idGoal' => $idGoal)); + $dataRow = $goalMetrics->getFirstRow(); - $goalReportsByDimension = new View\ReportsByDimension('Goals'); + $view->idSite = Common::getRequestVar('idSite', null, 'int'); - $ecommerceCustomParams = array(); - if ($preloadAbandonedCart) { - $ecommerceCustomParams['abandonedCarts'] = '1'; - } else { - $ecommerceCustomParams['abandonedCarts'] = '0'; + if ($dataRow) { + $view->revenue = $dataRow->getColumn('revenue'); + $view->revenue_subtotal = $dataRow->getColumn('revenue_subtotal'); + $view->revenue_tax = $dataRow->getColumn('revenue_tax'); + $view->revenue_shipping = $dataRow->getColumn('revenue_shipping'); + $view->revenue_discount = $dataRow->getColumn('revenue_discount'); } - $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() + public function getEcommerceLog($fetch = false) { - $viewOverview = $this->getGoalReportView(Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER); - $reportsByDimension = $viewOverview->goalReportsByDimension; - - $view = new View('@Ecommerce/sales'); - $this->setGeneralVariablesView($view); + $saveGET = $_GET; + $_GET['segment'] = urlencode('visitEcommerceStatus!=none'); + $_GET['widget'] = 1; + $output = FrontController::getInstance()->dispatch('Live', 'getVisitorLog', array($fetch)); + $_GET = $saveGET; - $view->goalReportsByDimension = $reportsByDimension; - return $view->render(); + return $output; } } |