We avoided the route of loading both stacks for two reasons: it's so slow, and as both Magento and SilverStripe use autoloading, there seemed to be be no straightforward way of loading the Mage classes alongside the SilverStripe ones.
Instead we integrated at two points:
1) Static content (stuff that is probably not going to change during the user's session) was shared through SOAP calls from SilverStripe to Magento (to get categories and product info), and for calls from Magento to SilverStripe we wrote a simple SilverStripe controller that returned json encoded data to Magento. In order for this to perform at an acceptable speed we added a layer of caching to both sides, which as the data is relatively static is fairly easy to do.
2) Dynamic content (session related stuff like the basket count) was shared by getting Magento and SilverStripe to share a common session. We then stuffed in anything that we needed that wasn't already in there and retrieved it using each platforms standard session handling code.
The main problems we encountered were getting the two systems to share a session nicely. Things to be aware of:
- Magento stores it's sessions in MAGE_ROOT/var/session, whilst SilverStripe uses the default PHP session path. We fixed this by adding a static method to the SilverStripe Session class that allowed us to make it use the same path as Magento.
- Both systems need to use the same cookie path. By default, Magento uses /shop/ (assuming you have installed it in a subfolder called shop), but you can change this in the config.
- Both systems need to use the same cookie lifetime or you will experience weird behaviour.
- Both systems need to use the same cookie domain. This is a subtle one, as assuming your domain is "www.example.com", SilverStripe uses the cookie domain "www.example.com" whilst Magento uses ".www.example.com". We originally patched the Session code in SilverStripe again to fix this, but in 2.4.2 there is now a static call that you can use to do it from the config.
There may have been other things that I've forgotten, but those are the important ones I think.
We have modules for both silverstripe and magento which provide most of the required connectivity, but they are still quite inflexible and generally need customising for each site. If anyone is interested in taking a look and/or helping to polish them, then I'd be happy to publish the code.