Skip to content
Extraits de code Groupes Projets
Valider d6a1f172 rédigé par Benaka's avatar Benaka Validation de Matthieu Aubry
Parcourir les fichiers

Show ecommerce sales by reports under Ecommerce - Sales in dashboard manager. (#11995)

Reports did not show currently, because widget configs in containers with ByDimension layout have modified categories/subcategories.

They thus did not show up under the right category (the category of the widget container). Fixed by using the right category
in getWidgetMetadata (but not getPagesMetadata).
parent 74f63f14
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Affichage de
avec 1035 ajouts et 503 suppressions
...@@ -10,6 +10,7 @@ namespace Piwik\Plugins\API; ...@@ -10,6 +10,7 @@ namespace Piwik\Plugins\API;
use Piwik\Category\CategoryList; use Piwik\Category\CategoryList;
use Piwik\Piwik; use Piwik\Piwik;
use Piwik\Plugins\CoreHome\CoreHome;
use Piwik\Report\ReportWidgetConfig; use Piwik\Report\ReportWidgetConfig;
use Piwik\Category\Category; use Piwik\Category\Category;
use Piwik\Category\Subcategory; use Piwik\Category\Subcategory;
...@@ -33,6 +34,7 @@ class WidgetMetadata ...@@ -33,6 +34,7 @@ class WidgetMetadata
$flat = array(); $flat = array();
foreach ($widgetsList->getWidgetConfigs() as $widgetConfig) { foreach ($widgetsList->getWidgetConfigs() as $widgetConfig) {
$metadataOverrides = [];
/** @var WidgetConfig[] $widgets */ /** @var WidgetConfig[] $widgets */
$widgets = array($widgetConfig); $widgets = array($widgetConfig);
...@@ -47,7 +49,21 @@ class WidgetMetadata ...@@ -47,7 +49,21 @@ class WidgetMetadata
continue; continue;
} }
$flat[] = $this->buildWidgetMetadata($widget, $categoryList); // widgets in containers with ByDimension layout have a special, unrecognized category/subcategory
// (eg, "Sales by Referrer Type"). we change it to the container's category/subcategory so the widget
// will appear in the dashboard manager.
if ($widgetConfig instanceof WidgetContainerConfig
&& $widgetConfig->getLayout() == CoreHome::WIDGET_CONTAINER_LAYOUT_BY_DIMENSION
) {
$metadataOverrides = [
'category' => $widgetConfig->getCategoryId(),
'subcategory' => $widgetConfig->getSubcategoryId(),
'name' => Piwik::translate($widget->getCategoryId()) . ': '
. Piwik::translate($widget->getName()),
];
}
$flat[] = $this->buildWidgetMetadata($widget, $categoryList, $metadataOverrides);
} }
} }
...@@ -61,17 +77,26 @@ class WidgetMetadata ...@@ -61,17 +77,26 @@ class WidgetMetadata
* @param CategoryList|null $categoryList If null, no category information will be added to the widgets in first * @param CategoryList|null $categoryList If null, no category information will be added to the widgets in first
* level (they will be added to nested widgets as potentially needed eg for * level (they will be added to nested widgets as potentially needed eg for
* widgets in ByDimensionView where they are needed to build the left menu) * widgets in ByDimensionView where they are needed to build the left menu)
* @param array $metadataOverrides Overrides for data in `$widget`. Currently only 'name', 'category', 'subcategory'
* are recognized.
* @return array * @return array
*/ */
public function buildWidgetMetadata(WidgetConfig $widget, $categoryList = null) public function buildWidgetMetadata(WidgetConfig $widget, $categoryList = null, array $metadataOverrides = [])
{ {
$widgetName = !empty($metadataOverrides['name']) ? $metadataOverrides['name'] : $widget->getName();
$item = array( $item = array(
'name' => Piwik::translate($widget->getName()) 'name' => Piwik::translate($widgetName),
); );
if (isset($categoryList)) { if (isset($categoryList)) {
$category = $categoryList->getCategory($widget->getCategoryId()); $widgetCategory = !empty($metadataOverrides['category'])
$subcategory = $category ? $category->getSubcategory($widget->getSubcategoryId()) : null; ? $metadataOverrides['category'] : $widget->getCategoryId();
$widgetSubcategory = !empty($metadataOverrides['subcategory'])
? $metadataOverrides['subcategory'] : $widget->getSubcategoryId();
$category = $categoryList->getCategory($widgetCategory);
$subcategory = $category ? $category->getSubcategory($widgetSubcategory) : null;
$item['category'] = $this->buildCategoryMetadata($category); $item['category'] = $this->buildCategoryMetadata($category);
$item['subcategory'] = $this->buildSubcategoryMetadata($subcategory); $item['subcategory'] = $this->buildSubcategoryMetadata($subcategory);
......
...@@ -183,6 +183,45 @@ class WidgetMetadataTest extends \PHPUnit_Framework_TestCase ...@@ -183,6 +183,45 @@ class WidgetMetadataTest extends \PHPUnit_Framework_TestCase
), $widget2); ), $widget2);
} }
public function test_buildWidgetMetadata_ShouldUseOverrideValues_IfSupplied()
{
$categoryList = $this->createCategoryList([
'Category' => ['Subcategory'],
'Category2' => ['Subcategory2'],
]);
$config = $this->createWidgetConfig('name', 'Category', 'Subcategory');
$metadata = $this->metadata->buildWidgetMetadata($config, $categoryList, [
'name' => 'changed name',
'category' => 'Category2',
'subcategory' => 'Subcategory2',
]);
$this->assertEquals([
'name' => 'changed name',
'category' => [
'id' => 'Category2',
'name' => 'Category2',
'order' => 99,
'icon' => '',
],
'subcategory' => [
'id' => 'Subcategory2',
'name' => 'Subcategory2Name',
'order' => 99,
],
'module' => 'CoreHome',
'action' => 'render',
'order' => 99,
'parameters' => [
'module' => 'CoreHome',
'action' => 'render',
],
'uniqueId' => 'widgetCoreHomerender',
'isWide' => false,
], $metadata);
}
public function test_buildPageMetadata_ShouldAddContainerInformtion_IfWidgetContainerConfigGiven() public function test_buildPageMetadata_ShouldAddContainerInformtion_IfWidgetContainerConfigGiven()
{ {
$config = new WidgetContainerConfig(); $config = new WidgetContainerConfig();
......
...@@ -302,7 +302,11 @@ class Pages ...@@ -302,7 +302,11 @@ class Pages
$widget->setCategoryId($categoryText); $widget->setCategoryId($categoryText);
$widget->setSubcategoryId($categoryText); $widget->setSubcategoryId($categoryText);
$widget->setOrder($order); $widget->setOrder($order);
$widget->setIsNotWidgetizable(); if ($ecommerce) {
$widget->setIsWidgetizable();
} else {
$widget->setIsNotWidgetizable();
}
if (!empty($report['viewDataTable'])) { if (!empty($report['viewDataTable'])) {
$widget->forceViewDataTable($report['viewDataTable']); $widget->forceViewDataTable($report['viewDataTable']);
......
Ce diff est replié.
Le fichier a été supprimé par une entrée .gitattributes, ou son encodage n'est pas pris en charge.
Le fichier a été supprimé par une entrée .gitattributes, ou son encodage n'est pas pris en charge.
Le fichier a été supprimé par une entrée .gitattributes, ou son encodage n'est pas pris en charge.
Le fichier a été supprimé par une entrée .gitattributes, ou son encodage n'est pas pris en charge.
Le fichier a été supprimé par une entrée .gitattributes, ou son encodage n'est pas pris en charge.
Le fichier a été supprimé par une entrée .gitattributes, ou son encodage n'est pas pris en charge.
Le fichier a été supprimé par une entrée .gitattributes, ou son encodage n'est pas pris en charge.
Le fichier a été supprimé par une entrée .gitattributes, ou son encodage n'est pas pris en charge.
Le fichier a été supprimé par une entrée .gitattributes, ou son encodage n'est pas pris en charge.
Le fichier a été supprimé par une entrée .gitattributes, ou son encodage n'est pas pris en charge.
Le fichier a été supprimé par une entrée .gitattributes, ou son encodage n'est pas pris en charge.
Le fichier a été supprimé par une entrée .gitattributes, ou son encodage n'est pas pris en charge.
Le fichier a été supprimé par une entrée .gitattributes, ou son encodage n'est pas pris en charge.
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter