如何使opencart多商店在多个TLD上共享同一购物车? [英] how to make opencart multi-store share same cart over multiple TLDs?

查看:80
本文介绍了如何使opencart多商店在多个TLD上共享同一购物车?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下情况:

  • domain1.com-商店1-已安装opencart 1.5.6
  • domain2.com-store2
  • domain3.com-store3

我设法将所有3个商店安装在不同的域上,并且它们都使用相同的opencart安装(store1).到目前为止,一切似乎都工作正常.我需要的是用户在 domain1.com 上,在购物车中添加 product1 ,然后导航到 store2(domain2.com),然后在购物车中添加 product2 -现在他应该同时具有 shop1 product1 shop2 product2 /em>在他的购物车中.换句话说,所有商店都应表现得与之相似,如果用户登录到 store1 ,则当他导航至 store2 时,他应保留其登录会话,购物车和所有其他选项. em>或 store3 .

I managed to install all 3 stores on different domains and all of them are using the same opencart install (store1). So far all seems to work properly. What I need is when the user is on domain1.com, adds product1 in his cart, then navigates to store2 (domain2.com) and adds product2 in his cart - now he should have both product1 from shop1 and product2 from shop2 in his cart. In other words, all stores should behave like one, if the user is logged in into store1 then he should keep his login session, his cart and all other options when he navigates to store2 or store3.

有什么方法可以实现这一目标?

注意::如果商店安装在多个子域中,但不使用其他域,我知道如何实现这一目标.

NOTE: I know how to achieve this if the stores are installed in multiple subdomains, but not using different domains.

推荐答案

我刚刚找到了解决此问题的方法,所以这是我做的事情:

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

我对/system/library/session.php进行了如下修改:

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']);
   }
}

说明::如果用户输入的不是主存储库,则将重定向到主存储库,如果不存在则启动会话,然后将会话ID发送回给主存储库.通过url中的GET参数访问请求者,然后使用相同的会话ID启动会话,然后将其重定向回原始请求的URL.这样做的缺点是,由于重定向,当用户第一次访问store2时,页面加载量至少会翻倍.

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.

这篇关于如何使opencart多商店在多个TLD上共享同一购物车?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆