How to find where a special Smarty variable is declared in PrestaShop?

1.3k views Asked by At

I using prestashop 1.6 and I have some variable in my index.tpl like as $aslist that I Don't know where this variable is defined or assigned! I need to find this variable and do some change over that. anybody know how can I find a solution that show where smarty variables assigned ?

I need to a address file like as: $aslist assigned in .\www\controllers\front\CmsController.php - (line 58 )

1

There are 1 answers

0
unloco On BEST ANSWER

You can add this function to config/config.inc.php

function log_smarty_assign($var_name)
{
    $smarty_var_filter = 'aslist';
    if ($var_name == $smarty_var_filter)
    {
        $log = '';
        $trace = debug_backtrace(false);
        if (isset($trace[1]))
        {
            $log .= 'Variable '.$var_name.' assigned in ';
            $log .= $trace[1]['file'].' #'.$trace[1]['line'];
            echo "<pre>$log</pre>";
        }           
    }
}

Edit: $trace[1] should be used instead of $trace[2]

And then search for the smarty assign method and modify it to something like this: I found it in /tools/smarty/sysplugins/smarty_internal_data.php

public function assign($tpl_var, $value = null, $nocache = false)
{
    if (is_array($tpl_var)) {
        foreach ($tpl_var as $_key => $_val) {
            if ($_key != '') {
                $this->tpl_vars[$_key] = new Smarty_variable($_val, $nocache);
                //log the assignment 
                log_smarty_assign($_key);
            }
        }
    } else {
        if ($tpl_var != '') {
            $this->tpl_vars[$tpl_var] = new Smarty_variable($value, $nocache);
            //log the assignment 
            log_smarty_assign($tpl_var);
        }
    }

    return $this;
}

Output example:

Variable product assigned in ...\classes\controller\Controller.php #180