Files
openfoodnetwork/lib/open_food_network/last_used_address.rb
2015-12-11 13:06:59 +11:00

29 lines
561 B
Ruby

module OpenFoodNetwork
class LastUsedAddress
def initialize(email)
@email = email
end
def last_used_bill_address
recent_orders.detect(&:bill_address).andand.bill_address
end
def last_used_ship_address
recent_orders.detect { |o|
o.ship_address && o.shipping_method.andand.require_ship_address
}.andand.ship_address
end
private
def recent_orders
Spree::Order.
order("id DESC").
where(email: @email).
where("state != 'cart'").
limit(8)
end
end
end