跨多个具有不同子域的商店的Opencart购物车 [英] Opencart cart across multiple stores with different subdomains

查看:105
本文介绍了跨多个具有不同子域的商店的Opencart购物车的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,您可以使用一个单一的opencart安装设置,其中包含多个具有不同子域(均位于同一域下)的商店.我希望客户能够将商品放入一个站点的购物车中,然后移至下一个站点并放入更多甚至更少的商品,直到最终客户在任何商店结帐.注意产品可能会出现在一家商店中,但不会出现在另一家商店中.

Hi have a single opencart install setup with several stores with different subdomains (all under the same domain). I want customers to be able to put items in the cart on one site, then move onto the next and put in more or even subtract, till eventually a customer checkouts out on any store. Note products might appear in one store but not another.

我注意到opencart会这样做.也就是说,它将把已经在购物车中的产品带到下一个商店,但前提是该产品同时出现在两个商店中.此外,如果客户随后删除其中一项,然后又搬回同一家商店,则他们的产品会重新出现.

I notice opencart does this somewhat. ie it will bring products already in the cart to the next store but only if the products appear in both stores. Further if a customer then deletes one of the items and moves back to the same store, they product reappears.

第一个问题似乎首先是因为我想查询的是通过store_id选择商品的购物车中显示的商品.我一直在努力寻找是否除了茫茫茫茫之外还能找到其他东西.

First Problem seems to firstly be products in the cart are being displayed through what i guess is a query that selects products by store_id. I have had a hard look to see if i can find anything but am at a loss.

第二个问题似乎与会话的内容有关.我仍在学习php,并且对如何甚至尝试修改会话的工作方式感到困惑.

Second problem seems to be with the contents of the session. I am still learning php and am a bit confused of how to even attempt to modify how the session works.

任何人都可以提供一些有关如何解决/更改此问题的指南.

Can anyone please provide some guidance on how i can go about fixing/changing this.

推荐答案

OpenCart将所有这些信息存储在您的PHP会话中.由于您的商店位于不同的子域下,因此当您从一家商店切换到另一家商店时,PHP会话会发生变化.

OpenCart stores all these information in you PHP session. Since your stores are located under different subdomains, the PHP session changes when you switch from one store to another.

因此,您要做的第一件事是在所有子域之间共享会话.默认情况下,PHP使用"PHPSESSID" cookie在多个页面之间传播会话数据,并且默认情况下,它使用cookie声明中的当前顶级域和子域.

So the first thing you need to do is to share the session between all subdomains. By default, PHP uses the 'PHPSESSID' cookie to propagate session data across multiple pages, and by default it uses the current top-level domain and subdomain in the cookie declaration.

示例:www.domain.com

Example: www.domain.com

此方法的缺点是会话数据无法与您一起传播到其他子域.因此,如果您在www.domain.com上开始会话,则该会话数据将在forums.domain.com上不可用.解决方案是更改PHP设置"PHPSESSID" cookie时使用的域.

The downside to this is that the session data can't travel with you to other subdomains. So if you started a session on www.domain.com, the session data would become unavailable on forums.domain.com. The solution is to change the domain PHP uses when it sets the 'PHPSESSID' cookie.

假设您有一个init文件,该文件包含在每个PHP页面的顶部,则可以使用ini_set()函数.只需将其添加到您的init页面顶部即可:

Assuming you have an init file that you include at the top of every PHP page, you can use the ini_set() function. Just add this to the top of your init page:

ini_set('session.cookie_domain',
substr($_SERVER['SERVER_NAME'],strpos($_SERVER['SERVER_NAME'],"."),100));

这行代码将域移出子域.

This line of code takes the domain and lops off the subdomain.

示例:forums.domain.com-> .domain.com

Example: forums.domain.com -> .domain.com

现在,每当PHP设置"PHPSESSID" cookie时,该cookie将可用于所有子域!

Now, every time PHP sets the 'PHPSESSID' cookie, the cookie will be available to all subdomains!

您可能还需要对OpenCart的核心进行一些小的修改才能使其正常工作.

You might also need to make some little modifications to the OpenCart's core in order to make it work.

玩得开心:)

这篇关于跨多个具有不同子域的商店的Opencart购物车的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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