mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-17 04:34:24 +00:00
Inline spree_last_address into the codebase to attempt to fix errors with it appearing only in prod
This commit is contained in:
1
Gemfile
1
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'
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,5 +1,30 @@
|
||||
Spree::CheckoutController.class_eval do
|
||||
|
||||
private
|
||||
|
||||
def before_payment
|
||||
current_order.payments.destroy_all if request.put?
|
||||
end
|
||||
end
|
||||
|
||||
# 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
|
||||
|
||||
Reference in New Issue
Block a user