Is it possible to have independent cart for each store under single magento installation. Now i have created a site with 2 stores, but each store is sharing the single cart. How it is possible to have independent cart for each of my store.

Example site is https://www.usinger.com/

  • 1
    No, natively you can have the independent cart just in multi-websites (one cart per website), you need some extension or customisation to do that for storeviews – PЯINCƏ Mar 6 '19 at 8:36

The quote model has a method getSharedStoreIds() which by default returns all store ids of a website. The return of this method is applied to the quote select for loading. Therefore you can simply set the current store into the array of shared store ids before loading like this:

    ->setStoreId(Mage::app()->getStore()->getId()) //this is just a simple setter and does not restrict anything
    ->setData('shared_store_ids', [Mage::app()->getStore()->getStoreId()]) //here happens the magic of store restriction
    ->load([Put whatever quote id here]);

Now the problem is to identify where to use that approch and what you need to change?

The simplest would be to create an observer for the event sales_quote_load_before and use a method like this there:

public function addSharedStoreIdsFilter($observer)
    $quote = $observer->getQuote();
    $quote->setData('shared_store_ids', [Mage::app()->getStore()->getStoreId()]);

Unfortunatelly that will not work in all situations since in the quote model there are some 'loadXXX' methods which are bypassing the before loading method (for what ever reason), for example if a customer logs in the method loadByCustomer.

Therefore the "nice" solution from above can work only if you overwrite the quote model and add $this->_beforeLoad(); in loadByCustomer($customer) and loadActive($quoteId) before accessing the resource.

Just for information of others who are reading this question: In Magento 2 there is a nicer way to achieve this: Disable cart sharing between different Stores of website in Magento 2?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.