2

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). New report in list

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. Reports Array and Class Error

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 (support@exp-resso.com)
 */

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()
    {

    }
} 
?>
2

It's not a file path, but a class path. In this function: add_location_reports, change:

$reports["location_summary"] = "\Expresso_store_add_location_reports_ext\LocationReports";

to:

$reports["location_summary"] = '\Store\Report\LocationReports';

I believe you also have to load the class before returning the variable:

$path = rtrim(dirname(__FILE__), '/') . "/LocationReports.php";
if (is_file($path)) {
    require $path;
}

Alas I've not found a way to set the name and description outside of Store, so have manually added the following entries to the language/english/store_lang.php file in the store module:

'store.reports.location_summary' => 'My Custom Title',
'store.reports.location_summary_desc' => 'My Custom Description',
| improve this answer | |
  • HI Peter, Thanks for your response. I had tried using the Class path (instead of file path) but hadn't had any luck, but its possible that its the loading of the class that needs to happen. I've tried inserting your snippet in various places but I am still getting the same error. Where would you suggest the $path code goes please? – Tomtids Oct 27 '15 at 9:38
  • Require it within the same function, before you 'return $reports;' – Peter Lewis Oct 27 '15 at 9:41
  • Hi Peter, Thanks. I've done a little playing... I actually had to change the code to $path = dirname(__FILE__) . "/LocationReports.php"; otherwise it wasn't a valid path. I seem to be up and running with a report interface now however. So many thanks for your help! – Tomtids Oct 27 '15 at 9:47
  • Help me anyone? I tried the above, including the last code mentioned in the reply. I get my extension to appear in control panel > Add Ons > Extensions, but if i then go to Store > Reports i get following error: A PHP Error was encountered Severity: Notice Message: Undefined index: expresso_store_add_location_reports Filename: libraries/Extensions.php Line Number: 194 Error Unable to load the following extension file: ext.expresso_store_add_location_reports.php ============================================================ <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed') – Bart Aug 23 '17 at 14:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.