Skip to content

Instantly share code, notes, and snippets.

@dhonig
Created March 4, 2012 22:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhonig/1975219 to your computer and use it in GitHub Desktop.
Save dhonig/1975219 to your computer and use it in GitHub Desktop.
checkout controller
include ActiveMerchant::Shipping
Spree::CheckoutController.class_eval do
#we do not have accounts in phase one
#instead the checkout_method screen and state has been added and we will simply force the user to enter an e_mail
# address. therefore we will not take advantage of the :check_registration filter.
skip_before_filter :check_registration
def load_order
@order = current_order
redirect_to cart_path and return unless @order and @order.checkout_allowed?
raise_insufficient_quantity and return if @order.insufficient_stock_lines.present?
redirect_to cart_path and return if @order.completed?
#check for use shippping and set it in the order
#TODO look into why before_validation is not firing correctly
# (this has been doen because the before_validtion on the Order model does not seem to be functioning)
if defined?(params[:order]['use_shipping'])
@order.use_shipping=params[:order]['use_shipping']
end
@order.state = params[:state] if params[:state]
state_callback(:before)
end
def before_shipping_address
@order.ship_address ||= Spree::Address.default
end
def before_payment
current_order.payments.destroy_all if request.put?
@order.bill_address ||= Spree::Address.default
end
#TODO work in progress
def estimate_shipping
dest_zip=params[:dest_zip]
username=Spree::ActiveMerchant::Config[:ups_login]
password=Spree::ActiveMerchant::Config[:ups_password]
key=Spree::ActiveMerchant::Config[:ups_key]
country= Spree::ActiveShipping::Config[:origin_country]
city=Spree::ActiveShipping::Config[:origin_city]
state=Spree::ActiveShipping::Config[:origin_state]
zip=Spree::ActiveShipping::Config[:origin_zip]
origin = Location.new(:country =>country ,
:state =>state ,
:city =>city,
:zip =>zip )
destination=Location.new(:zip=>dest_zip)
UPS.new(:login => username, :password => password, :key => key)
response=ups.find_rates(origin,destination,packages,options={})
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment