If you have multi-stores configured in your Magento and you want to have single cart for all multi-stores this article is what you need.
All your multi-stores will be not separate websites, they all will have single cart (share cart content between multi-stores).
Also your customers will have single account for all multi-stores.
1. Share customer accounts.
First step is to share customers account between multi-stores.
You can configure this feature here: System -> Configuration -> Customer Configuration -> Share Customer Accounts.
2. Share sessions between Magento websites.
Next step is to share customers session between Magento websites.
There are 3 possible store configurations:
1. If your websites are located in one domain, but in different directories, e.g. "www.example.com/stores/store1" and "www.example.com/stores/store2" you can setup your "Cookie Path" to "/stores/" in System -> Configuration -> Web -> Session Cookie Management.
2. If your websites are located in different sub-domains e.g. "store1.example.com" and "store2.example.com" you can setup "Cookie Domain" to ".example.com" in System -> Configuration -> Web -> Session Cookie Management.
3. If you have different domains, in this case you can add session ID to the URL for another store. Use this construction "Mage::getModel('core/url')->addSessionParam()->getUrl('...')" to get the URL with session parameter.
After that your customers will be able to switch between multi-stores Magento websites without re-login. In other words, if customer will login in one Magento website, he will be able to see another multi-store Magento website using his first store account.
But the cart will be different for each Magento website.
3. Share the cart content between Magento multi-store websites.
Magento uses separate cart sessions for each store, the reason is that different multi-store websites have different set of products and different product settings for each store (like price, quantity, etc).
To overcome this limitation, you need to have a website/store which will have all available products from all other websites. If you do not have such Magento website, just create it in the System -> Manage stores. The idea is use single store and website in the checkout session, that is why we need Magento store with all products in it.
To use one website on the checkout session you need to modify the "Mage_Checkout_Model_Session" class.
Copy this file: app/code/core/Mage/Checkout/Model/Session.php
to: app/code/local/Mage/Checkout/Model/Session.php.
After that add the following source code to the class:
class Mage_Checkout_Model_Session extends Mage_Core_Model_Session_Abstract { const CHECKOUT_STORE_ID = 1; public function getCheckoutStoreId() { return self::CHECKOUT_STORE_ID; } ...
Change CHECKOUT_STORE_ID value "1" to your Magento store ID with all products.
Next, find all such elements in the file:
Mage::app()->getStore()
and change them to:
Mage::app()->getStore($this->getCheckoutStoreId())
Clear Magento cache and check your store. Now your Magento will use one cart for different multi-stores websites.
Note that there are several limitations of this solution:
1. All prices in the cart will be from the store you selected (using CHECKOUT_STORE_ID). So if you have different prices for different stores it will not work in the cart.
2. The currency in the cart will be the same as in the store you selected.
3. The link for editing items in the cart will redirect customer to original cart website. It is possible to change it, you can override getUrl method for cart items block or override controller.
What if we were to add a third domain in the solution, say example.net, and add some sort of ajax-request in our websites on example.com and example.org that requests a certain document from example.net . On a new visit to example.com it will write a cookie with our session id from example.com for example.net . Would we afterwards visit example.org it will perform the same ajax-request to example.net but now detects the previous session id from example.com and updates the session id from example.org along with its cart accordingly.
Would this work, and if so, wouldn't it be a far better solution?
Could you please tell me how i can make it work for non logged in users?
Also were do i need to set this code?
3. If you have different domains, in this case you can add session ID to the URL for another store. Use this construction "Mage::getModel('core/url')->addSessionParam()->getUrl('...')" to get the URL with session parameter.
do i litterly need to set "Mage::getModel('core/url')->addSessionParam()->getUrl('...')" or do i need to set a variabel at the ...
With kinnd regards,
Rene
Could anyone help me to change item price on cart page according to store for multiple store with different price.
Thanks
1. All prices in the cart will be from the store you selected (using CHECKOUT_STORE_ID). So if you have different prices for different stores it will not work in the cart.
2. The link for editing items in the cart will redirect customer to original cart website. It is possible to change it, you can override getUrl method for cart items block or override controller.
Copy Core\Mage\Sales\Model\Quote\Item\Abstract.php To local\Mage\Sales\Model\Quote\Item\Abstract.php
Replace the getProduct() function with below code.
public function getProduct()
{
$product = $this->_getData('product');
if ($product === null && $this->getProductId()) {
$product = Mage::getModel('catalog/product')
->setStoreId($this->getQuote()->getStoreId())
->load($this->getProductId());
$this->setProduct($product);
}
/**
* Get Store specific product details.Check if the product storeID is same as the Session->item->storeID
*/
if($this->_getData('store_id')!= $product->getData('store_id')){
$product = Mage::getModel('catalog/product')
->setStoreId($this->_getData('store_id'))
->load($this->getProductId());
}
/**
* Reset product final price because it related to custom options
*/
$product->setFinalPrice(null);
if (is_array($this->_optionsByCode)) {
$product->setCustomOptions($this->_optionsByCode);
}
return $product;
}
Let me know if its a bad code. Happy to learn :)