Can someone explain where session variables are held?
I have added some session variables in header.php in the controller, for example:
$this->session->data['day']=date("d",strtotime($row['startdate']));
This works when loading the site, and when I click on a product, all the variables are gone, except for the [language]
, [currency]
and [cart]
which are set by Opencart.
I guess there is another file or controller file where I set the variables, or where [language]
, [currency]
and [cart]
are set but I cannot find it.
Thanks in advance.
Session values are not set in a file. If you want to set a session variable, use
$this->session->data['variable_name_here'] = 'data value here';
and to retrieve the value you just access
$this->session->data['variable_name_here']
For example, to echo it use
echo $this->session->data['variable_name_here'];
Here I would save the variables into a session:
public function receive() {
$this->session->data['guest_name'] = $this->request->post['name'];
$this->session->data['guest_address'] = $this->request->post['address'];
}
Now in catalog/controller/checkout/guest.php
at index
method check for that session variables and if set, store the value in the $this->data
array for presenting to the template:
if(isset($this->session->data['guest_name'])) { // it is enough to check only for one variable and only if it is set
$this->data['guest_name'] = $this->session->data['guest_name'];
$this->data['guest_address'] = $this->session->data['guest_address'];
}
After that You can simply echo these values in Your template (still checking whether exists):
<?php if(isset($guest_name)) { ?>
<div><?php echo $guest_name . ' - ' . $guest_address; ?></div>
<?php } ?>
Now You should be done while avoiding any undefined variable
notices...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With