how to make opencart multi-store share same cart over multiple TLDs?

你离开我真会死。 提交于 2019-12-02 01:33:09

I just found a solution for this problem so here's what I did:

I modified /system/library/session.php as follows:

if ($_SERVER['HTTP_HOST'] != 'store1.loc') {
   if (!isset($_COOKIE["PHPSESSID"]) && !isset($_GET['session_id'])) { 
      $actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";//get current URL
      header('Location: http://store1.loc?getsession=true&url='.base64_encode($actual_link));
   }
   elseif (isset($_GET['session_id'])) { //set session based on the session_id received from main store
      session_destroy();
      session_id($_GET['session_id']);
      session_start();
      header('Location: '. base64_decode($_GET['url'])); //redirect to original requested url
   }
}
else {
   if (isset($_GET['getsession'])) { //send back session_id
      header('Location: http://store2.loc?session_id='.urlencode(session_id()) . '&url=' . $_GET['url']);
   }
}

Explanation: If the user enters any store that is not the main store a redirect is made to the main store, a session is started if not present, then the session id is sent back to the requester via GET parameter in url, then a session is started using the same session id, then it redirects back to the original requested URL. The drawback to this is the fact that when the user visits for the first time store2 the page loading will be at least double because of the redirects.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!