diff --git a/Gemfile b/Gemfile index 10094e8b94..56a19150d0 100644 --- a/Gemfile +++ b/Gemfile @@ -8,7 +8,6 @@ gem 'spree', :github => 'eaterprises/spree', :branch => '1-3-stable' gem 'spree_i18n', :github => 'spree/spree_i18n' gem 'spree_auth_devise', :github => 'spree/spree_auth_devise', :branch => '1-3-stable' gem 'spree_paypal_express', :github => 'spree/spree_paypal_express', :branch => '1-3-stable' -gem 'spree_last_address', :github => 'eaterprises/spree_last_address' gem 'comfortable_mexican_sofa' diff --git a/Gemfile.lock b/Gemfile.lock index 83c4295657..f9e079fb18 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -56,13 +56,6 @@ GIT spree_sample (1.3.3) spree_core (= 1.3.3) -GIT - remote: git://github.com/eaterprises/spree_last_address.git - revision: ab1b66cc7930405e5cc59ce9b71ea81b59d1c8ed - specs: - spree_last_address (1.0.0) - spree_core (~> 1.0) - GIT remote: git://github.com/spree/deface.git revision: 1110a1336252109bce7f98f9182042e0bc2930ae @@ -512,7 +505,6 @@ DEPENDENCIES spree! spree_auth_devise! spree_i18n! - spree_last_address! spree_paypal_express! therubyracer timecop diff --git a/app/controllers/spree/checkout_controller_decorator.rb b/app/controllers/spree/checkout_controller_decorator.rb index b288b2da24..c5ff01d3ff 100644 --- a/app/controllers/spree/checkout_controller_decorator.rb +++ b/app/controllers/spree/checkout_controller_decorator.rb @@ -1,5 +1,30 @@ Spree::CheckoutController.class_eval do + + private + def before_payment current_order.payments.destroy_all if request.put? end -end \ No newline at end of file + + # Adapted from spree_last_address gem: https://github.com/TylerRick/spree_last_address + # Originally, we used a forked version of this gem, but encountered strange errors where + # it worked in dev but only intermittently in staging/prod. + def before_address + associate_user + + last_used_bill_address, last_used_ship_address = find_last_used_addresses(@order.email) + preferred_bill_address, preferred_ship_address = spree_current_user.bill_address, spree_current_user.ship_address if spree_current_user.respond_to?(:bill_address) && spree_current_user.respond_to?(:ship_address) + @order.bill_address ||= preferred_bill_address || last_used_bill_address || Spree::Address.default + @order.ship_address ||= preferred_ship_address || last_used_ship_address || Spree::Address.default + end + + def find_last_used_addresses(email) + past = Spree::Order.order("id desc").where(:email => email).where("state != 'cart'").limit(8) + if order = past.detect(&:bill_address) + bill_address = order.bill_address.clone if order.bill_address + ship_address = order.ship_address.clone if order.ship_address + end + + [bill_address, ship_address] + end +end