7

My website is with Three different Stores and I'd like to disable the cart sharing feature between stores. So when I switch from one store to the other store, the product in my cart shouldn't be valid or not display to another store.

Product added to the specific store should be displayed on the specific store only.
  • I think you have one web -> one store -> multiple views ? – Hassan Ali Shahzad Feb 27 at 7:24
  • I have 1 website, 2 stores and 2 store views (one for each store). – amitshree Feb 27 at 10:22
2
+50

I'm not sure if this works, it's just an idea: The quote has the functionality to specify the stores which are sharing the quote. By default this are all stores of a website. Anyway if it is possible to set a list of spefic stores before loading the quote, I think it is possible to restrict the quote to a subset of all stores of a website, in your case just to the actual store.

One idea could be to set the store restriction in a plugin before the get method in Magento\Quote\Model\QuoteRepository, which should always be called when a quote is loaded.

Again, it's just an idea which might not work and the code is not tested and just to demonstrate my thoughts.

class MyPlugin{

    protected $storeManager;

    public function __construct( 
        \Magento\Store\Model\StoreManagerInterface $storeManager
    ){
        $this->storeManager = $storeManager;
    }

    public function beforeGet(
        \Magento\Quote\Model\QuoteRepository $quoteRepository, 
         $cartId, 
         array $sharedStoreIds
    ){
        return [$cartId, [$this->storeManager->getStore()->getId()]];
    }
}

Looking forward to hearing what you think about this approach.

  • I will try and update if it works. – amitshree Mar 5 at 6:34
  • Great Man !!! :) +1 – Rohan Hapani Mar 7 at 4:18
  • Tried it. Only items are hidden from minicart section but they are visible is other sections like cart, checkout. – amitshree Mar 20 at 7:19
0

By default, Magento support to share cart between websites and to do so you need to ensure the following settings:

  1. Cookie Path & Cookie Domain

cookie setting

  1. Share Customer Account -> Global

share customer account

To disable cart sharing functionality, I suggest to change your cookie domain. E.g

store 1: https://mystore.com => cookie domain: .mystore.com

store 2: https://mystore2.com => cookie domain: .mystore2.com

And disable the share customer account functionality, otherwise you may need to find a way to regenerate the session ID between stores (SID), Magento store switcher automatically added SID for store, I recommend not use their store switcher but develop your owned store switcher to avoid SID appended.

Hope this help.

  • I have only one website and loading second store using website.com/store2 . Is is compulsory to create 2 websites? – amitshree Mar 5 at 6:31
  • @amitshree If your store using domain such as website.com/store2, you should look into the cookie path instead of the cookie domain. – Toan Nguyen Mar 6 at 7:02
  • I have changed cookie path as /default and /retail for both stores view. Still I see cart is shared. – amitshree Mar 20 at 6:48

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.