Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 242 Vote(s) - 3.31 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Custom Cookie variable + Prestashop

#1
Prestashop

I am stuck we one problem for cookie. In prestashop 1.4.7 I create a custom cookie variable using setcookie but when i am try to access and assign it on front-controller, I am not getting cookies set value.
here is my script:

**page: checkpostcode.php**

include(dirname(__FILE__).'/config/config.inc.php');
include(dirname(__FILE__).'/init.php');
global $cookie;

setcookie("is_postcode_checked", 1, time()+600, "/", "", 1); // Set the cookie in basepath

**On frontcontroller.php page :**
I am access it using `$_COOKIE` and assign it into smarty array.

'is_postcode_checked' => $_COOKIE['is_postcode_checked'] // Getting null value for cookie
**page: checkpostcode.tpl**

{$cookie->_get(postcode_checked_msg)} // here get the is_postcode_checked value but

but I am not able to get `is_postcode_checked` variable value.
Reply

#2
You should use Prestashop's own cookie class entirely rather than using the PHP `setcookie()` function. The class uses the "magic methods" `__get()`, `__set()`, `__unset()` and `__isset()` which should allow you to do this easily.

Try in your "page" code (not sure how you're executing this since it doesn;t look like an additional page controller):

global $cookie;

$cookie->is_postcode_checked = 1;
$cookie->write(); // I think you'll need this as it doesn't automatically save
...

And in your FrontController override:

global $cookie;

if (isset($cookie->is_postcode_checked))
$is_postcode_checked = $cookie->is_postcode_checked;
else
$is_postcode_checked = 0;

You can assign the variable $is_postcode_checked to a corresponding smarty variable to use in your template.
Reply

#3
In prestashop 1.5, global are deprecated.

To set something in the cookie :

In a controller :

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

Other file :

$context = Context::getContext();
$context->cookie->__set($finger_print,$result);

You can access to your value with :

In a controller

$this->context->cookie->key

Other file :

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

#4
If you want to fetch the cookie from Prestashop cookie class, you should store it in this class too.

Use `die()` function in your controller, to find out is that cookie set

It is better, as Paul said, to use only global `$cookie` class to store and getting data.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through