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

Dav*_*ker 0 php forms variables smarty prestashop

在prestashop 1.5上,我想要做的是在右侧初始创建一个要求客户的表单

你想要_____吗:

(1)含税的显示价格(2)不含税的显示价格

然后答案存储在一个聪明的会话变量中.(我认为这是最好的方法吗?)

然后在product.tpl页面上,会有if,else命令

如果会话变量'displaytax'

含税价格

如果会话变量'displaynotax'

价格不含税

否则结束如果

任何人都可以帮助代码:

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

非常感谢花时间去看

Rap*_*aël 10

在prestashop 1.5中,全局被弃用.

要在cookie中设置内容:

在控制器中:

$this->context->cookie->__set($key,$value);
Run Code Online (Sandbox Code Playgroud)

其他档案:

$context = Context::getContext();
$context->cookie->__set($key,$value); 
Run Code Online (Sandbox Code Playgroud)

您可以通过以下方式访问您的价值:

在控制器中

$this->context->cookie->key
Run Code Online (Sandbox Code Playgroud)

其他档案:

$context = Context::getContext();
$context->cookie->key;
Run Code Online (Sandbox Code Playgroud)

Prestashop不使用$ _SESSSION,因此您无法访问 $smarty.session.key

你必须将你的变量分配给smarty

在控制器中:

$this->context->smarty->assign(array('key' => $this->context->cookie->key));
Run Code Online (Sandbox Code Playgroud)

其他档案:

$context = Context::getContext();
$context->smarty->assign(array('key' => $context->cookie->key));
Run Code Online (Sandbox Code Playgroud)