I am just wondering that is it at all possible to set session across the Opencart website?
I mean I have created a subdirectory album on my Opencart website. What I want to achieve is on the product page when user clicks on the album icon it will be taken to the album subdirectory. On the album subdirectory, there will be a form, which the user will have to fill. After the user fills that form from the album directory on submit, user should redirect to that product page with the data of the form filled in the album directory. Also, the product page should have selected same options that he/she selected before clicking on the album.
I tried doing this by setting session data using following code on my album page.
sessionStorage.setItem("album", JSON.stringify(tdata));
And, then go back to the product page with window.history.go(-1);
But, I am still not being able to get the album session data on my product page. I tried both $_SESSION
as well as $this->session->data
Does anyone know how to achieve this?
Thanks
I created custom jquery file and injected it in my product page before $data['heading_title'] = $product_info['name'];
.
$this->document->addScript('catalog/view/javascript/jquery/album.js');
In my album.js
$(document).ready(function(e) {
if (sessionStorage.getItem("album_data") != null) {
var data = sessionStorage.getItem("album_data");
console.log(data);
}
}
In my custom album.php that is placed at mysite/album/
<script>
sessionStorage.setItem("album_data", JSON.stringify(tdata));
window.history.go(-1);
</script>
No need to create a session or anything. Creating a new session won't work in controller/product.php as OC has its own way of handling session data. So, we will not be able to access any $_SESSION data in it. OC only understands $this-session->data
.