Magento Multipe websites Share Shopping cart session

Magento Multipe websites Share Shopping cart session

August 5, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento Multipe websites Share Shopping cart session

Sharing Magento Shopping Carts Across Multiple Websites

As a new Magento developer, you’re likely to encounter challenges when trying to share shopping cart sessions across different stores. While the solution provided in this StackOverflow post works for some scenarios, it has limitations that can cause issues with session sharing.

Understanding the Current Limitation

The method described in the StackOverflow post enables basic cart sharing across stores. However, there are two significant problems:

  1. Products added to the cart from the root category (default store) remain in the session even after switching to other stores. This means all stores share the same cart contents.

  2. When a product is added to the cart from a non-default store and then moved to a different store, a new independent cart session is created for each subsequent store visited.

Analyzing the Root Cause

The issue arises because Magento uses separate database sessions for each website and store combination by default. Even though you’ve modified the core files as suggested in the StackOverflow post, Magento still maintains this separation when switching between stores with different root categories.

A Practical Approach to Solve the Issue

To resolve this problem, we need to ensure that all stores share a single database session. This involves modifying the Mage_Core_Model_Session and creating a custom Zend_Session_SaveHandler_DbTable:

  1. Create a new table in your MySQL database (e.g., core_session) with the following schema:
CREATE TABLE core_session (
  session_id char(32) NOT NULL default '',
  session_data text NOT NULL,
  session_lifetime int(10) unsigned NOT NULL default '0',
  PRIMARY KEY (session_id)
);
  1. Create a custom Zend_Session_SaveHandler_DbTable class to store sessions in the database:
class Mage_Core_Model_Zend_Session_SaveHandler_DbTable extends Zend_Session_SaveHandler_DbTable
{
    public function open($savePath, $sessionName)
    {
        // Implement your logic here
    }

    public function close()
    {
        // Implement your logic here
    }

    public function read($sessionId)
    {
        // Implement your logic here
    }

    public function write($sessionId, $data)
    {
        // Implement your logic here
    }

    public function destroy($sessionId)
    {
        // Implement your logic here
    }
}
  1. Update the Mage_Core_Model_Session constructor to use the custom session save handler:
class Mage_Core_Model_Session extends Mage_Core_Model_Abstract
{
    public function __construct()
    {
        $this->init($this->_sessionName)
            ->start();
    }

    protected function _init($sessionName = null)
    {
        if (!$sessionName) {
            $sessionName = Mage::app()->getRequest()->getParam('___store');
        }

        Zend_Session::setSaveHandlerClass('Mage_Core_Model_Zend_Session_SaveHandler_DbTable');

        // Additional initialization logic
    }
}

Conclusion

To successfully share shopping cart sessions across different Magento stores with distinct root categories, you need to implement a single database session for all websites and stores. By creating a custom Zend_Session_SaveHandler_DbTable class and updating the Mage_Core_Model_Session constructor, you can ensure that all stores use the same session data.

Remember to thoroughly test this solution in your development environment before deploying it to production. Always have a backup strategy in place when modifying core Magento files.

If you need further assistance or want to explore more advanced Magento customizations, consider reaching out to Laravel Company for expert guidance and support.

Checkout Catalog Database Errors

Our network