Jump to content

Test module


vishakha

Recommended Posts

[PrestaShopException]

Method of module cannot be found

at line 802 in file controllers/admin/AdminModulesController.php

796. 						$echo = '';797. 						if ($key != 'update' && $key != 'checkAndUpdate')798. 						{799. 						// We check if method of module exists800. 							if (!method_exists($module, $method))801. 								throw new PrestaShopException('Method of module cannot be found');802. 803. 							// Get the return value of current method804. 							$echo = $module->{$method}();805. 806. 							// After a successful install of a single module that has a configuration method, to the configuration page
Link to comment
Share on other sites

<?php

if (!defined('_PS_VERSION_'))
    exit;

class testmodule extends Module
{
    /* @var boolean error */
    protected $_errors = false;
    
    public function __construct()
    {
        $this->name = 'testmodule';
        $this->tab = 'front_office_features';
        $this->version = '1.0';
        $this->author = 'Nemo';
        $this->need_instance = 0;

         parent::__construct();

        $this->displayName = $this->l('testmodule');
        $this->description = $this->l('Adds a block.');
        $this->confirmUninstall = $this->l('Are you sure you want to delete this module?');
    }
    
    public function install()
    {
        if (!parent::install())
            return false;
        return true;
    }
    
    public function uninstall()
    {
        if (!parent::uninstall())
            return false;
        return true;
    }

    public function countAllProducts()
    {
        return Db::getInstance()->getValue('SELECT COUNT(*) from ps_product WHERE active = 1');
    }
}
 

Link to comment
Share on other sites

Your module markup is missing some default functions:

 

/**
* Load the configuration form
*/
public function getContent()
{
/**
* If values have been submitted in the form, process.
*/
$this->_postProcess();


$this->context->smarty->assign('module_dir', $this->_path);


$output = $this->context->smarty->fetch($this->local_path.'views/templates/admin/configure.tpl');


return $output.$this->renderForm();
}


/**
* Create the form that will be displayed in the configuration of your module.
*/
protected function renderForm()
{
$helper = new HelperForm();


$helper->show_toolbar = false;
$helper->table = $this->table;
$helper->module = $this;
$helper->default_form_language = $this->context->language->id;
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG', 0);


$helper->identifier = $this->identifier;
$helper->submit_action = 'submitMyModule';
$helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false)
.'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
$helper->token = Tools::getAdminTokenLite('AdminModules');


$helper->tpl_vars = array(
'fields_value' => $this->getConfigFormValues(), /* Add values for your inputs */
'languages' => $this->context->controller->getLanguages(),
'id_language' => $this->context->language->id,
);


return $helper->generateForm(array($this->getConfigForm()));
}


/**
* Create the structure of your form.
*/
protected function getConfigForm()
{
return array(
'form' => array(
'legend' => array(
'title' => $this->l('Settings'),
'icon' => 'icon-cogs',
),
'input' => array(
array(
'type' => 'switch',
'label' => $this->l('Live mode'),
'name' => 'MYMODULE_LIVE_MODE',
'is_bool' => true,
'desc' => $this->l('Use this module in live mode'),
'values' => array(
array(
'id' => 'active_on',
'value' => true,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => false,
'label' => $this->l('Disabled')
)
),
),
array(
'col' => 3,
'type' => 'text',
'prefix' => '<i class="icon icon-envelope"></i>',
'desc' => $this->l('Enter a valid email address'),
'name' => 'MYMODULE_ACCOUNT_EMAIL',
'label' => $this->l('Email'),
),
array(
'type' => 'password',
'name' => 'MYMODULE_ACCOUNT_PASSWORD',
'label' => $this->l('Password'),
),
),
'submit' => array(
'title' => $this->l('Save'),
),
),
);
}


/**
* Set values for the inputs.
*/
protected function getConfigFormValues()
{
return array(
'MYMODULE_LIVE_MODE' => Configuration::get('MYMODULE_LIVE_MODE', true),
'MYMODULE_ACCOUNT_EMAIL' => Configuration::get('MYMODULE_ACCOUNT_EMAIL', '[email protected]'),
'MYMODULE_ACCOUNT_PASSWORD' => Configuration::get('MYMODULE_ACCOUNT_PASSWORD', null),
);
}


/**
* Save form data.
*/
protected function _postProcess()
{
$form_values = $this->getConfigFormValues();


foreach (array_keys($form_values) as $key)
Configuration::updateValue($key, Tools::getValue($key));
}
Edited by jsmit2 (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...