The documentation suggests that you should be able to (fairly easily) create a custom report type and add it to the Exp:resso Store Reports section. But beyond the hook $reports = ee()->extensions->call('store_reports', $reports);
I can find no other documentation on how to achieve this.
Following my nose I have created a new extension to tap into the hook and have added a new record to the reports array, (however there is no way in the new Class to assign what the Report Name and Description should be - this seems to be embeded in the translation files - which I am little concerned will be overwritten when performing an upgrade).
In order to get a good working base for my new report I've just copied an existing report, however when clicking through to view my report I can't prevent the error "Fatal error: Class '\Expresso_store_add_location_reports_ext\LocationReports' not found in /path/from/server/root/expressionengine/third_party/store/src/Cp/ReportsController.php on line 56" from appearing. I've tried adding my new report to the Store/src/Report folder, but the same error appears there too.
I'm clearly doing something quite wrong here, but in the absence of any documentation I'm at a loss as to how to proceed. Any pointers very much appreciated, thank you!
My Full Extension File:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Expresso_store_add_location_reports Class
*/
class Expresso_store_add_location_reports_ext
{
var $name = 'Expresso Store - Add location reporting';
var $version = '1.0';
var $description = 'Shows a new report type to sort by location';
var $settings_exist = 'n';
var $docs_url = ''; // 'https://ellislab.com/expressionengine/user-guide/';
var $settings = array();
/**
* Constructor
*
* @param mixed Settings array or empty string if none exist.
*/
function __construct($settings = '')
{
$this->settings = $settings;
$this->EE =& get_instance();
}
// --------------------------------------------------------------------
/**
* Activate Extension
*
* This function enters the extension into the exp_extensions table
*
* @see https://ellislab.com/codeigniter/user-guide/database/index.html for
* more information on the db class.
*
* @return void
*/
public function activate_extension()
{
$this->settings = array(
);
$data = array(
'class' => __CLASS__,
'method' => 'add_location_reports',
'hook' => 'store_reports',
'settings' => serialize($this->settings),
'priority' => 10,
'version' => $this->version,
'enabled' => 'y'
);
ee()->db->insert('extensions', $data);
}
/**
* Update Extension
*
* This function performs any necessary db updates when the extension
* page is visited
*
* @return mixed void on update / false if none
*/
public function update_extension($current = '')
{
if ($current == '' OR $current == $this->version)
{
return FALSE;
}
if ($current < $this->version)
{
// Update to version 1.0
}
ee()->db->where('class', __CLASS__);
ee()->db->update(
'extensions',
array('version' => $this->version)
);
}
/**
* Disable Extension
*
* This method removes information from the exp_extensions table
*
* @return void
*/
public function disable_extension()
{
ee()->db->where('class', __CLASS__);
ee()->db->delete('extensions');
}
public function add_location_reports($reports)
{
// call the development log?
$reports["location_summary"] = "\Expresso_store_add_location_reports_ext\LocationReports";
echo "<pre>";
print_r($reports);
echo "</pre>";
return $reports;
}
public function options()
{
return $this->options;
}
// --------------------------------------------------------------------
/**
* Usage
*
* This function describes how the plugin is used.
*
* @access public
* @return string
*/
public static function usage()
{
ob_start(); ?>
This plugin should add a location report to the reports area.
<?php
$buffer = ob_get_contents();
ob_end_clean();
return $buffer;
}
// END
}
/* End of file pi.expresso_store_most_popular_items.php */
/* Location: ./system/expressionengine/third_party/expresso_store_add_location_reports/ext.expresso_store_add_location_reports.php */
?>
My new Report file:
<?php
/*
* Exp:resso Store module for ExpressionEngine
* Copyright (c) 2010-2014 Exp:resso ([email protected])
*/
namespace Store\Report;
use Store\DateTime;
use Store\Model\Order;
use Store\Model\OrderItem;
class LocationReports extends AbstractReport
{
public function default_options()
{
return array(
'from' => array('type' => 'month_select', 'default' => -12),
'to' => array('type' => 'month_select', 'default' => -1),
);
}
public function run()
{
}
}
?>