PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, October 26, 2022

[FIXED] How can I return an install error back to the Module Manager in Prestashop 1.7?

 October 26, 2022     module, php, prestashop-1.7     No comments   

Issue

I am trying to debug my Module installation where a few times it will return false based on certain fields. Depending on which fails, I want to display an output. I have tried:

\Tools::displayError('This worked.');
array_push($this->context->controller->errors, $this->l('This worked.'));

My install looks like this:

public function install() {
    \Tools::displayError('This worked.');
    array_push($this->context->controller->errors, $this->l('This worked.'));
    return (parent::install() && false); // Force a fail to test
}

However, all I seem to get is:

Unfortunately, the module did not return additional details.

I have looked on the internet for fixes but have only come across outdated ones. Any help would be appreciated.

Edit: my constructor has need_instance set to 1:

public function __construct() {
    ...
    $this->need_instance = 1;
    ...
    parent::__construct();
    ...
}

Update: To help future viewers, the insert function of the Db class automatically adds the prefix to the table name. Removing the self::DB_PREFIX fixed this issue.

return \Db::getInstance()->insert('iezon_portfolio', array(
    'img_link' => pSQL($img),
    'title' => pSQL($title),
    'description' => pSQL($description),
    'company_name' => pSQL($company),
    'company_url' => pSQL($company_url),
    'testimonial' => pSQL($testimonial),
    'is_favourite' => (int) $fav,
));

Solution

Try something like this:

public function install()
{
    if ($this->checkForErrors()) {
        $this->_errors[] = $this->l('Error message');
        return false;
    }

    ...rest of the code...
}


Answered By - Krystian Podemski
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing