class CartsController < ApplicationController layout 'default' before_filter :init_cart def order @products = @account.products.find(:all); if @order.orderdetails.length > 0 @product = @order.orderdetails[0].product end end def show_product_details @product = @account.products.find(params[:id]) unless params[:id]==nil render :partial => "product_details" end def products_list @products = @account.products.find(:all); render :partial => "products_list" end def cart_details render :partial => "cart_details" end def empty_cart session[:order] = Order.new session[:order].user = @user @order = session[:order] redirect_to :action => 'order' end def add_product_to_cart begin if @order.orderdetails.length>0 @order.orderdetails[0].product = @account.products.find(params[:id]) else orderdetail = Orderdetail.new orderdetail.product = @account.products.find(params[:id]) @order.orderdetails = Array.new @order.orderdetails << orderdetail end session[:order] = @order rescue StandardError => e puts e end cart_details end def add_product_billingcycle_to_cart begin if @order.orderdetails.length>0 @order.orderdetails[0].billingcycle = Billingcycle.find(params[:id]) else orderdetail = Orderdetail.new orderdetail.product = Billingcycle.find(params[:id]).product orderdetail.billingcycle = Billingcycle.find(params[:id]) @order.orderdetails = Array.new @order.orderdetails << orderdetail end session[:order] = @order rescue StandardError => e puts e end cart_details end def check_domain_availability template = "check_domain_availability" begin domain_name = params[:sld]+"."+params[:tld] domain = Whois.find(domain_name) if domain.available? template = "new_domain_available" else template = "new_domain_not_available" end rescue StandardError => e puts e end render :partial => template end def add_domain_to_cart domain_name = params[:sld]+"."+params[:tld] begin if @order.orderdetails.length>0 @order.orderdetails[0].domain_name = domain_name @order.orderdetails[0].tld = Tld.find_by_tld_name(params[:tld]) else orderdetail = Orderdetail.new orderdetail.domain_name = domain_name orderdetail.tld = Tld.find_by_tld_name(params[:tld]) @order.orderdetails = Array.new @order.orderdetails << orderdetail end session[:order] = @order rescue StandardError => e puts e end cart_details end def customer if params[:do]!=nil if params[:do]=="login" logout_keeping_session! user = User.authenticate(params[:login], params[:password]) if user && user.role.role_name == "Customer" self.current_user = user new_cookie_flag = (params[:remember_me] == "1") handle_remember_cookie! new_cookie_flag flash[:notice] = "Logged in successfully" @user = User.find(self.current_user.id) else note_failed_signin @login = params[:login] @remember_me = params[:remember_me] @user = User.new end init_cart else end end end def signup render :partial => "signupbox" end def login render :partial => "loginbox" end def logout logout_killing_session! flash[:notice] = "You have been logged out." @user = User.new redirect_to :action => 'order' end def checkout end protected def note_failed_signin flash[:error] = "Couldn't log you in as '#{params[:login]}'" logger.warn "Failed login for '#{params[:login]}' from #{request.remote_ip} at #{Time.now.utc}" end private def init_cart if authorized? @user = User.find(current_user.id) if @user.role.role_name == "Customer" session[:account_id] = @user.account_id else logout_killing_session! end else @user = User.new @user.account_id = session[:account_id] end if params[:account_id]!=nil session[:account_id] = params[:account_id] elsif session[:account_id]==nil session[:account_id]=1 end if session[:order]==nil session[:order] = Order.new session[:order].user = @user end @account = Account.find(session[:account_id]) @setting = @account.settings.find(:first) @tlds = @account.tlds @order = session[:order] end end