سؤال

I'm a kind of newbye at PRESTASHOP/SMARTY environment, but I need to support some friend in trouble. After several wasted hours I`ve decided to ask you.

Are there any particularity or standard procedure to access to PRESTASHOP classes (/classes), i.e Product.php from an SMARTY default template? there are any scope problems within this environment?

I've found that I need to use the $smarty.const to access to prestashop constants... but no clue in order to get access to already defined classes.

I know that we werent suppoused to do such kind of functionality from the template view. But it is legacy code. Any walkthrought?

Thank you in advance.

هل كانت مفيدة؟

المحلول

I suggest you to focus on the controller or module which calls the smarty template. There you can use classes to get the information you want and then pass it to smarty in the $this->context->smarty->assign() array as an independent variable:

$this->context->smarty->assign(array(
       'category' => $this->category,
        //OTHER VARIABLES
       'ancestors' => $ancestors
)

or by modifying an existing one:

$this->category['ancestors'] = $ancestors;
$this->context->smarty->assign(array(
       'category' => $this->category,
        //OTHER VARIABLES
)

نصائح أخرى

You can directly access static methods and fields of a class in smarty, like

<a href="{Tools::getShopDomain()}"> {Tools::$round_mode} </a>

The above is very crude example, just showing how to do it.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top