app/controllers/store/store_controller.rb in artfully_ose-1.1.0 vs app/controllers/store/store_controller.rb in artfully_ose-1.2.0.alpha.1

- old
+ new

@@ -1,30 +1,28 @@ class Store::StoreController < ActionController::Base layout "storefront" + include CartFinder + before_filter :store_organization - helper_method :current_cart - def current_cart(reseller_id = nil) - return @current_cart if @current_cart - - @current_cart ||= Cart.find_by_id(session[:order_id]) - - if @current_cart.nil? || @current_cart.completed? || !@current_cart.reseller_is?(reseller_id) - create_current_cart(reseller_id) - end - - @current_cart + def store_organization + @store_organization ||= load_store_organization end - def current_cart=(cart) - @current_cart = cart + # + # Raises ActionController::RoutingError if a bad organization_slug is passed + # + def load_store_organization + if params[:organization_slug].present? + org = Organization.find_using_slug(params[:organization_slug]) + raise ActionController::RoutingError.new("Not Found") if org.nil? + org + elsif params[:controller].end_with? "events" + Event.find(params[:id]).organization + elsif params[:controller].end_with? "shows" + Show.where(:uuid => params[:id]).first.organization + elsif current_member + current_member.organization + else + nil + end end - - private - def create_current_cart(reseller_id) - if reseller_id.blank? - @current_cart = Cart.create - else - @current_cart = Reseller::Cart.create( {:reseller => Organization.find(reseller_id)} ) - end - session[:order_id] = @current_cart ? @current_cart.id : nil - end end