diff --git a/core/API/DataTablePostProcessor.php b/core/API/DataTablePostProcessor.php index 352771464e2c03e2e22167c22edbff9a6eae44c9..ba99229db3f472dfa2979333fe2bffa6d6cf64ff 100644 --- a/core/API/DataTablePostProcessor.php +++ b/core/API/DataTablePostProcessor.php @@ -68,7 +68,11 @@ class DataTablePostProcessor $this->apiMethod = $apiMethod; $this->request = $request; - $this->report = Report::factory($apiModule, $apiMethod); + foreach (Report::getAllReports() as $report) { + if ($apiMethod === $report->getAction() && $apiModule === $report->getModule()) { + $this->report = $report; + } + } $this->apiInconsistencies = new Inconsistencies(); $this->formatter = new Formatter(); } diff --git a/plugins/Ecommerce/Reports/Base.php b/plugins/Ecommerce/Reports/Base.php index e8c23a4bb28685d837eaeee88dd1082becf3370f..c2d7f6eada5f35dc4d240419182030afb0a75881 100644 --- a/plugins/Ecommerce/Reports/Base.php +++ b/plugins/Ecommerce/Reports/Base.php @@ -14,6 +14,7 @@ use Piwik\Piwik; use Piwik\Plugin\Report; use Piwik\Site; use Piwik\ViewDataTable\Factory as ViewDataTableFactory; +use Piwik\WidgetsList; abstract class Base extends Report { @@ -99,4 +100,15 @@ abstract class Base extends Report return $rendered; } + public function configureWidget(WidgetsList $widget) + { + if ($this->widgetTitle) { + $params = array(); + if (!empty($this->widgetParams) && is_array($this->widgetParams)) { + $params = $this->widgetParams; + } + $widget->add($this->category, $this->widgetTitle, 'Ecommerce', $this->action, $params); + } + } + } diff --git a/plugins/Ecommerce/Widgets.php b/plugins/Ecommerce/Widgets.php new file mode 100644 index 0000000000000000000000000000000000000000..0a2541473d0999db08bdbc9879d605218821e558 --- /dev/null +++ b/plugins/Ecommerce/Widgets.php @@ -0,0 +1,35 @@ +<?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 Piwik\Common; +use Piwik\Site; +use Piwik\Piwik; + +class Widgets extends \Piwik\Plugin\Widgets +{ + protected $category = 'Goals_Ecommerce'; + + protected function init() + { + $idSite = $this->getIdSite(); + + $site = new Site($idSite); + if ($site->isEcommerceEnabled()) { + $this->addWidget('Goals_EcommerceOverview', 'widgetGoalReport', array('idGoal' => Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER)); + $this->addWidget('Goals_EcommerceLog', 'getEcommerceLog'); + } + } + + private function getIdSite() + { + return Common::getRequestVar('idSite', null, 'int'); + } + +} diff --git a/plugins/Ecommerce/tests/UI/Ecommerce_spec.js b/plugins/Ecommerce/tests/UI/Ecommerce_spec.js new file mode 100644 index 0000000000000000000000000000000000000000..07ff64486b6b986f53d86a540734c93a6ba0e4a0 --- /dev/null +++ b/plugins/Ecommerce/tests/UI/Ecommerce_spec.js @@ -0,0 +1,56 @@ +/*! + * Piwik - free/libre analytics platform + * + * GoalsTable screenshot tests. + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + +describe("Ecommerce", function () { + this.timeout(0); + + var url = "?module=Widgetize&action=iframe&moduleToWidgetize=Referrers&idSite=1&period=year&date=2012-08-09&" + + "actionToWidgetize=getKeywords&viewDataTable=table&filter_limit=5&isFooterExpandedInDashboard=1"; + + it("should load when the goals icon is clicked", function (done) { + expect.screenshot('initial').to.be.capture(function (page) { + page.load(url); + page.click('.tableIconsGroup a[data-footer-icon-id=tableGoals]'); + }, done); + }); + + it("should show columns for all goals when idGoal is 0", function (done) { + expect.screenshot('goals_table_full').to.be.capture(function (page) { + var url = page.getCurrentUrl().replace(/viewDataTable=[^&]*/, "viewDataTable=tableGoals") + "&idGoal=0"; + page.load(url); + }, done); + }); + + it("should show columns for a single goal when idGoal is 1", function (done) { + expect.screenshot('goals_table_single').to.be.capture(function (page) { + page.load(page.getCurrentUrl().replace(/idGoal=[^&]*/, "idGoal=1")); + }, done); + }); + + it("should show an ecommerce view when idGoal is ecommerceOrder", function (done) { + expect.screenshot('goals_table_ecommerce').to.be.capture(function (page) { + page.load(page.getCurrentUrl().replace(/idGoal=[^&]*/, "idGoal=ecommerceOrder")); + }, done); + }); + + it("should show a special view when idGoal is ecommerceOrder and viewDataTable is ecommerceOrder", function (done) { + expect.screenshot('goals_table_ecommerce_view').to.be.capture(function (page) { + var url = page.getCurrentUrl().replace(/moduleToWidgetize=[^&]*/, "moduleToWidgetize=Ecommerce") + .replace(/actionToWidgetize=[^&]*/, "actionToWidgetize=getItemsSku") + .replace(/viewDataTable=[^&]*/, "viewDataTable=ecommerceOrder"); + page.load(url); + }, done); + }); + + it("should show abandoned carts data when the abandoned carts link is clicked", function (done) { + expect.screenshot('goals_table_abandoned_carts').to.be.capture(function (page) { + page.click('.tableIconsGroup a[data-footer-icon-id=ecommerceAbandonedCart]'); + }, done); + }); +}); \ No newline at end of file diff --git a/plugins/Goals/Widgets.php b/plugins/Goals/Widgets.php index 30c113e9a2a8cbdc5997ff75cbcd858cb0ff28ad..94d91bda5ce4d7763da6e7e4d8c889664ba896fe 100644 --- a/plugins/Goals/Widgets.php +++ b/plugins/Goals/Widgets.php @@ -9,8 +9,6 @@ namespace Piwik\Plugins\Goals; use Piwik\Common; -use Piwik\Site; -use Piwik\Piwik; class Widgets extends \Piwik\Plugin\Widgets { @@ -31,12 +29,6 @@ class Widgets extends \Piwik\Plugin\Widgets $this->addWidget($name, 'widgetGoalReport', $params); } } - - $site = new Site($idSite); - if ($site->isEcommerceEnabled()) { - $this->addWidgetWithCustomCategory('Goals_Ecommerce', 'Goals_EcommerceOverview', 'widgetGoalReport', array('idGoal' => Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER)); - $this->addWidgetWithCustomCategory('Goals_Ecommerce', 'Goals_EcommerceLog', 'getEcommerceLog'); - } } private function getIdSite() diff --git a/tests/PHPUnit/Unit/Plugin/Dimension/ConversionDimensionTest.php b/tests/PHPUnit/Unit/Plugin/Dimension/ConversionDimensionTest.php index 04fdc37b8e0c0519073850dd0957c3c4b46d6bd5..3b8b2d9049005d1f0d2cd087c5e58cedfc8c9611 100644 --- a/tests/PHPUnit/Unit/Plugin/Dimension/ConversionDimensionTest.php +++ b/tests/PHPUnit/Unit/Plugin/Dimension/ConversionDimensionTest.php @@ -155,7 +155,7 @@ class Plugin_ConversionDimensionTest extends \PHPUnit_Framework_TestCase foreach ($dimensions as $dimension) { $this->assertInstanceOf('\Piwik\Plugin\Dimension\ConversionDimension', $dimension); - $this->assertRegExp('/Piwik.Plugins.(ExampleTracker|Goals).Columns/', get_class($dimension)); + $this->assertRegExp('/Piwik.Plugins.(ExampleTracker|Ecommerce|Goals).Columns/', get_class($dimension)); } } } \ No newline at end of file