mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-04-04 07:09:14 +00:00
29 lines
561 B
Ruby
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
|