Sha256: cc975ae2b324e3e6a88465ec3ab7366771f2fc4595cc987957fa904726910581
Contents?: true
Size: 912 Bytes
Versions: 1
Compression:
Stored size: 912 Bytes
Contents
module Sprangular::UserDecorator def self.prepended(klass) klass.has_many :addresses, class_name: 'Spree::Address' end def past_bill_addresses past_addresses :bill_address end def past_ship_addresses past_addresses :ship_address end def completed_orders orders.complete.order('updated_at DESC') end private def past_addresses(address_type) addresses = (past_orders_with_most_recent_first(address_type).map(&address_type) + [send(address_type)]).compact addresses.uniq do |a| [a.lastname.to_s, a.firstname.to_s, a.address1.to_s, a.address2.to_s, a.city.to_s, a.zipcode.to_s, a.phone.to_s, a.state_id.to_s, a.state_name.to_s, a.country_id.to_s] end end def past_orders_with_most_recent_first(address_type) completed_orders.includes(address_type => [:state, :country]) end end Spree.user_class.send(:prepend, Sprangular::UserDecorator)
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
sprangular-0.1.0 | app/models/spree/user_decorator.rb |