You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

多子域名下Magento店铺视图共享购物车的实现问题

Fixing Cross-Subdomain Shopping Cart Sharing in Magento

Hey there, let's work through this issue where your Magento stores on subdomains aren't sharing the shopping cart—even with global customer accounts enabled. Here's the breakdown of what's going wrong and how to fix it:

Why This Happens

Magento stores shopping cart data in browser cookies, and by default, these cookies are tied to the specific subdomain you're on (e.g., store1.mysite.com). When you switch to store2.mysite.com, the browser won't send the cookies from the first subdomain, so the cart appears empty. Even with shared customer accounts, this cookie isolation blocks cart data from being accessed across subdomains.

Step-by-Step Fixes

This is the most critical step to enable cross-subdomain cookie sharing:

  • Go to Store > Configuration > Web > Default Cookie Settings in your Magento admin
  • Set the Cookie Domain field to .mysite.com (make sure to include the leading dot—this tells the browser to share cookies across all subdomains of mysite.com)
  • Save the configuration and flush all Magento caches (System > Cache Management)

2. Fix Typos in Apache Virtual Host Config

I noticed a typo in your first VirtualHost block that could cause store identification issues:

# Wrong:
SetEnv MAGE_RUN_CODE "stoe1"
# Correct:
SetEnv MAGE_RUN_CODE "store1"

Update this in your Apache vhost file, then restart Apache to apply the change.

After making the above changes, test to confirm cookies are shared:

  • Visit store1.mysite.com, add an item to your cart
  • Open your browser's developer tools (F12) > Go to Application > Cookies > store1.mysite.com
  • Check that the Domain property for cookies like mage-cache-storage, mage-cache-storage-section-invalidation, and PHPSESSID is set to .mysite.com
  • Switch to store2.mysite.com and check the same section—you should see the same cookies, and your cart should now display the item added from the first store

4. Double-Check Session Validation Settings

To ensure sessions aren't being blocked across subdomains:

  • Go to Store > Configuration > Web > Session Validation Settings
  • Ensure options like Validate REMOTE_ADDR and Validate HTTP_VIA are disabled (or adjusted if you have specific security needs, but default settings should work once the cookie domain is configured)

Final Notes

Since you already set Share Customer Accounts to global, customer data is already being shared across stores. The missing piece was configuring the cookie domain to allow cart-related cookies to be accessed across all your subdomains. Once these steps are done, your shopping cart should sync seamlessly between store1.mysite.com and store2.mysite.com.

内容的提问来源于stack exchange,提问作者Karan Adhikari

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.08 11:17:47