PipBoy2000
PipBoy2000

Reputation: 440

How to get values from Prestashop module database

I have quite simple Prestashop module that i want to rework to use own database table with separate language etc.

Previously this module was writen without multilingual function with simple ps_configuration table use.

 public function hookDisplayFooter($params)
     {
         $value = Configuration::get('MYMODULE_SETTINGS');

and now i have

 public function hookDisplayFooter($params)
     {
         $value = Tools::getValue('mymodule_settings');

Everything works good but i can't get the mymodle_settings values in this function anymore. This my input array.

array(
    'type' => 'text',
    'label' => $this->l('Settings'),
    'desc' => $this->l('My module settings.'),
    'name' => 'mymodule_settings',
    'lang' => true,
    'size' => 64,
),

This is my database table

 `mymodule_settings` varchar(255) NOT NULL,

The mymodule_settings values are correctly placed in database and i see them in module BO, and the question is how to get them to function $value =

Upvotes: 0

Views: 3072

Answers (1)

PipBoy2000
PipBoy2000

Reputation: 440

tools::getValue returns value stored in $_POST / $_GET variable so it does not return the database entries.

So in this case we need to use Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(''); function

In my case this does the job

public function hookDisplayFooter($params)
    {
        $sql = 'SELECT mymodule_settings FROM '._DB_PREFIX_.'mymodule';
        $value = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);

Upvotes: 2

Related Questions