prestashop (php / SESSION变量)如何从表单中存储变量并在if / else命令中使用它们


prestashop (php / SESSION variables ) how to store variables from a form and use them in if / else commands

在prestshop 1.5上,我想做的是首先在右侧创建一个表单,询问客户

你想要:

(1)含税显示价格(2)不含税陈列价格

然后答案存储在smarty会话变量中。(我认为这是最好的方法?)

然后在产品上。TPL页面,会有if, else命令

如果会话变量'displaytax'

含税价格

如果会话变量'displaynotax'

含税价格

其他如果

谁能帮我写一下代码:

(1)最初创建这个简单的表单并存储会话变量?(2)带回会话变量,以便您可以在if else语句中使用它?

非常感谢您花时间看

在prestshop 1.5中,不支持使用全局变量。

在cookie中设置一些内容:

在控制器中:

$this->context->cookie->__set($key,$value);

其他文件:

$context = Context::getContext();
$context->cookie->__set($key,$value); 

你可以用:

访问你的值

在控制器

$this->context->cookie->key

其他文件:

$context = Context::getContext();
$context->cookie->key;

prestshop没有使用$ _session,所以你不能访问$smarty.session.key

你必须把变量赋值给smarty

在控制器中:

$this->context->smarty->assign(array('key' => $this->context->cookie->key));

其他文件:

$context = Context::getContext();
$context->smarty->assign(array('key' => $context->cookie->key));