spree-contrib / spree-multi-domain

Multiple Spree stores on different domains - single unified backed for processing orders
https://guides.spreecommerce.org
194 stars 191 forks source link

Cart shared between domains? #82

Open imella opened 10 years ago

imella commented 10 years ago

It's ok that the Cart is shared between different domains? I don't know if this is the default behavior or is a bug.

In any case, is there a way to have independent shopping carts between different domains?

Thanks!

imella commented 10 years ago

Well i found out how to do this, so if anyone is stuck with the same problem, here is what I did.

I just made a decorator of the set_current_order method in Spree::Core::ControllerHelpers::Order module.

module Spree
  module Core
    module ControllerHelpers
      module Order
        def set_current_order
          if user = try_spree_current_user
            last_incomplete_order = user.spree_orders.incomplete.where(:created_by_id => user.id, store_id: current_store.id).order('created_at DESC').first
            if session[:order_id].nil? && last_incomplete_order
              session[:order_id] = last_incomplete_order.id
            elsif current_order && last_incomplete_order && current_order != last_incomplete_order
              current_order.merge!(last_incomplete_order, user)
            end
          end
        end
      end
    end
  end
end
Senjai commented 10 years ago

@imella This just happened to us. Do you know how you were able to reproduce that behavior?