kuskov Posted November 10, 2014 Share Posted November 10, 2014 Hello guys, i have a question: i have 2 stores on the same domain:1. domain.de/store1 2. domain.de/store2 In the frontend i have a dropdown where user can switch between those 2 shops. Question: how can i make user loggedin in BOTH shops after sucess login? Right now i can login in one shop and see the store. When i change to "store2" it asks me to login. Best regards, Link to comment Share on other sites More sharing options...
kuskov Posted November 12, 2014 Author Share Posted November 12, 2014 (edited) This is exactly the problem, that all my shops use the same domain! And the cookie has this "_shopUrl" in it. Is it possible to maintain cookies only on domain base without "_shopUrl"? shop.de/berlinshop.de/munchenshop.de/stuttgartUsers are available to switch the shop to be able to order the goods from their local store. Edited November 12, 2014 by kuskov (see edit history) Link to comment Share on other sites More sharing options...
Rolige Posted November 12, 2014 Share Posted November 12, 2014 In your case, and because your multistore is within the same domain maybe can be possible by making changes in the cookie class: /classes/Cookie.php Or override this. Link to comment Share on other sites More sharing options...
Rolige Posted November 12, 2014 Share Posted November 12, 2014 Well, I have tried a little changes and apparently works , obviously need more tests, try this below...Create a new override file in: /override/classes/Cookie.phpPaste this code: <?php class Cookie extends CookieCore { public function __construct($name, $path = '', $expire = null, $shared_urls = null, $standalone = false) { parent::__construct('ps'); } } Delete the file: /cache/class_index.phpPlease let me know what happen, cheers. 1 Link to comment Share on other sites More sharing options...
kuskov Posted November 12, 2014 Author Share Posted November 12, 2014 Works like a charm, can you explain why it works? And do the expiration still works? Link to comment Share on other sites More sharing options...
Rolige Posted November 12, 2014 Share Posted November 12, 2014 Works like a charm, can you explain why it works? And do the expiration still works? You need have the same expiration days in all shops, if you has changed this parameter, just put the same days for all. Link to comment Share on other sites More sharing options...
DrGren Posted January 16, 2015 Share Posted January 16, 2015 COTOKO, You are King! Works perfectly. Thank you! Link to comment Share on other sites More sharing options...
iiMKenny Posted May 1, 2015 Share Posted May 1, 2015 Well, I have tried a little changes and apparently works , obviously need more tests, try this below... Create a new override file in: /override/classes/Cookie.php Paste this code: <?php class Cookie extends CookieCore { public function __construct($name, $path = '', $expire = null, $shared_urls = null, $standalone = false) { parent::__construct('ps'); } } Delete the file: /cache/class_index.php Please let me know what happen, cheers. I hope this finds you in time I have a little dilemma How would I insert this if I have the agile module on my shops cookie.php? <?php class Cookie extends CookieCore { /* * module: agilemultipleseller * date: 2015-04-29 19:31:26 * version: 3.0.6.2 */ protected function _setcookie($cookie = null) { if(Module::isInstalled('agilemultipleshop')) { $_SESSION[$this->_name] = $this->_cipherTool->encrypt($cookie); } return parent::_setcookie($cookie); } /* * module: agilemultipleseller * date: 2015-04-29 19:31:26 * version: 3.0.6.2 */ public function update($nullValues = false) { if(Module::isInstalled('agilemultipleshop')) { if(isset($_SESSION[$this->_name])) { $_COOKIE[$this->_name] = $_SESSION[$this->_name]; } } parent::update($nullValues); } } Link to comment Share on other sites More sharing options...
Rolige Posted May 1, 2015 Share Posted May 1, 2015 I hope this finds you in time I have a little dilemma How would I insert this if I have the agile module on my shops cookie.php? <?php class Cookie extends CookieCore { /* * module: agilemultipleseller * date: 2015-04-29 19:31:26 * version: 3.0.6.2 */ protected function _setcookie($cookie = null) { if(Module::isInstalled('agilemultipleshop')) { $_SESSION[$this->_name] = $this->_cipherTool->encrypt($cookie); } return parent::_setcookie($cookie); } /* * module: agilemultipleseller * date: 2015-04-29 19:31:26 * version: 3.0.6.2 */ public function update($nullValues = false) { if(Module::isInstalled('agilemultipleshop')) { if(isset($_SESSION[$this->_name])) { $_COOKIE[$this->_name] = $_SESSION[$this->_name]; } } parent::update($nullValues); } } I think just need add the construct method there and should work... public function __construct($name, $path = '', $expire = null, $shared_urls = null, $standalone = false) { parent::__construct('ps'); } 1 Link to comment Share on other sites More sharing options...
iiMKenny Posted May 2, 2015 Share Posted May 2, 2015 I think just need add the construct method there and should work... public function __construct($name, $path = '', $expire = null, $shared_urls = null, $standalone = false) { parent::__construct('ps'); } Sorry for my lack of knowledge. Where exactly would I insert that in the code? Link to comment Share on other sites More sharing options...
Rolige Posted May 2, 2015 Share Posted May 2, 2015 This should be the code merged with the other... <?php class Cookie extends CookieCore { public function __construct($name, $path = '', $expire = null, $shared_urls = null, $standalone = false) { parent::__construct('ps'); } /* * module: agilemultipleseller * date: 2015-04-29 19:31:26 * version: 3.0.6.2 */ protected function _setcookie($cookie = null) { if(Module::isInstalled('agilemultipleshop')) { $_SESSION[$this->_name] = $this->_cipherTool->encrypt($cookie); } return parent::_setcookie($cookie); } /* * module: agilemultipleseller * date: 2015-04-29 19:31:26 * version: 3.0.6.2 */ public function update($nullValues = false) { if(Module::isInstalled('agilemultipleshop')) { if(isset($_SESSION[$this->_name])) { $_COOKIE[$this->_name] = $_SESSION[$this->_name]; } } parent::update($nullValues); } } 1 Link to comment Share on other sites More sharing options...
jnaudin84 Posted October 21, 2015 Share Posted October 21, 2015 Hi, I have the same problem but in different domains. www.store1.com www.store2.com ¿Its possible to have the same user session in two domains? Thanks. Link to comment Share on other sites More sharing options...
jmeca Posted June 12, 2016 Share Posted June 12, 2016 Yes It's, how can we do share cart and customer whit diferent domains?? Any help please Link to comment Share on other sites More sharing options...
ExpertoPrestaShop Posted August 22, 2016 Share Posted August 22, 2016 (edited) If you want to share just some cookie data between your multishops you should override CookieCore like this: class Cookie extends CookieCore { public function setName($name) { $this->_name = $name; $this->update(); } } This funtion will set a global name for your cookie without any relation to context shop or group. You can use it like this: $cookie = new Cookie('cookie_name'); $cookie->setName('cookie_name'); $cookie->__set('key', $value); Good luck!!! Edited August 22, 2016 by PrestaAlba (see edit history) 1 Link to comment Share on other sites More sharing options...
ingeis Posted September 13, 2016 Share Posted September 13, 2016 But this solution don't works in differents domains, only works for the same domain with diferents paths (stores.com/st1, store.com/st2...). If you want the same cookies for diferents domains( store1.co, store2.com, store3.com,...) the solution is shared the cookies in the link to chenga the store. My solution (in spanish, sorry): Hola a todos, os explico mi solución que es sencilla y efectiva, a ver si os vale. Vamos a suponer que tenemos un prestashop con multitienda y cada una de ellas con un dominio (exampl1.com, example2.com,example3.com...),da igual el número de dominios/tiendas que tengais. Paso 1) Codificamos las cookies del dominio actual (creamos una cadena) y se las pasamos al .tpl dónde tengamos los links de las diferentes tiendas. Para hacerlo, vamos al PHP que "genera" los datos para el .tpl (en mi caso es un simple módulo que genera un menu superior dónde estan los enlaces a las diferentes tiendas). Así, en el PHP: //config. Multicarrito//codificamos la variable global $_COOKIE$cookies_compartidas=htmlentities(base64_encode(serialize($_COOKIE)));// Y la metemos en smarty para que el tpl la pueda leer$this->smarty->assign('cookies_compartidas', $cookies_compartidas); Seguidamente, vamos a editar el tpl que és el que muestra el menu. en Mi caso es una lista <UL><LI> con CSS para hacerlo bonito: La cuestión es que cuándo hagamos click sobre el enlace para ir a otra tienda/dominio, envíe esa cookie que hemos codificado al nuevo dominio al que queremos ir. Modificamos el .tpl: {* creamos un formulario "invisible" que enviará las cookies *}<form action="foo" method="post" id="frmC000" STYLE='display:none;'><input type='hidden' id='shC000' name='shC000' value='{$cookies_compartidas}'></form><div class="menu_tiendas"><ul>{* links a las diferentes tiendas, la etiqueta Alt contiene la URL de la tienda, que lo ponemos como 'action' al formulario*}<li><A alt="http://www.dominio1.com" onClick="$('#frmC000').attr('action',$(this).attr('alt'));$('#frmC000').submit();">Tienda 1</A></li><li><A alt="http://www.dominio2.com" onClick="$('#frmC000').attr('action',$(this).attr('alt'));$('#frmC000').submit();">Tienda 2</A></li><li><A alt="http://www.dominio3.com" onClick="$('#frmC000').attr('action',$(this).attr('alt'));$('#frmC000').submit();">Tienda 3</A></li></ul> Ahora, con eso, cuándo hagámos click en cualquier enlace a nuestras tiendas, en vez de ir directamente al dominio, irá pero enviando la cookie. Paso 2) leemos las cookies. Ahora, debemos leer esas cookies justo antes de actualizar nuestro carrito. Para ello, sobreescribiremos la función init del FrontController (recordad crear un nuevo FrontController.php en override/classes/controller para que con las actualizaciones continuen funcionando). class FrontController extends FrontControllerCore{ public function init() {// la variable $_POST ya debería ser global, pero por algún motivo, si no la declaro, no funcionaglobal $_POST;// BY SAM, hemos recibido cookies??if(isset($_POST['shC000'])){//descodificamos las cookies$cookies_import=ToolsCore::unSerialize(base64_decode($_POST['shC000']),true);$cookie_lifetime = time() + 24 * 3600);foreach($cookies_import as $nombre=>$valor){//borramos la cooki anteriorsetcookie($nombre,'',time()-3600*100,'/', $_SERVER['HTTP_HOST'],isset($_SERVER['HTTPS'])?true:false);// establecemos la nueva cookiesetcookie($nombre,$valor,$cookie_lifetime,'/', $_SERVER['HTTP_HOST'],isset($_SERVER['HTTPS'])?true:false);// si descomentamos, generará una linea en en log de errores para ver si se establecen//error_log("Cookie establecida en ".$_SERVER['HTTP_HOST'].": ".$nombre."=".$valor,0);}} // lamamos al init de la clase FrontController original parent::init(); } Et voilà, magia hecha, rápido y funcional. 4 Link to comment Share on other sites More sharing options...
ajutge Posted September 26, 2016 Share Posted September 26, 2016 Hello, I have a multi-boutique with three different domain names and I'd like cookies follow from one domain to another. I followed exactly the procedure you explain, but it does not work. Are there things to configure out more? Thank you Link to comment Share on other sites More sharing options...
trevorgilligan Posted November 21, 2016 Share Posted November 21, 2016 Can anyone explain what code would be needed for this: with multistore.com/ShopA works multistore.com/ShopB works to add to cart. However , using ShopA.com or ShopB.com doesnt work... Thank you Link to comment Share on other sites More sharing options...
Recommended Posts