Voglio salvare i dati temporanei (ID e nome) dalla pagina del prodotto al carrello tramite Ajax. Il problema è registrare nuove variabili nei cookie, usando il file Joomla in sospeso. Provai:
$inputCookie = JFactory::getApplication()->input->cookie;
$value = $inputCookie->get($name = 'myCookie', $defaultValue = null);
$cookieExists = ($value !== null);
$inputCookie->set($name = 'myCookie', $value = '123', $expire = 0);
ma in var_dump ($ _ COOKIE) non esiste una variabile 'myCoolie' con valore.
E forse per sicurezza devo usare Session invece Cookie per mantenere i prodotti nel carrello?
Il problema è che il tuo codice non funzionerà mai la prima volta che provi a impostare un valore di cookie basato sul valore get, che è sempre null
come te non stai mai impostando il valore iniziale.
Per impostare un cookie, è possibile utilizzare quanto segue:
$app = JFactory::getApplication();
// Get the cookie
$value = $app->input->cookie->get('myCookie', null);
// If there's no cookie value, manually set it
if ($value == null)
{
$value = HOWEVER YOU GET THE CART DATA
}
// Set the cookie
$time = time() + 604800; // 1 week
$app->input->cookie->set('myCookie', $value, $time, $app->get('cookie_path', '/'), $app->get('cookie_domain'), $app->isSSLConnection());
Questo può aiutarti.
https://stackoverflow.com/questions/16206662/how-to-use-cookies-from-a-component
usa i metodi setvar e getString
JRequest::setVar($var, $value, 'cookie');
JRequest::getString($var, $default, 'cookie')
O
https://api.joomla.org/cms-3/classes/Joomla.Input.Cookie.html
O
http://blog.tormix.com/joomla/set-and-get-cookies-in-joomla-cms/