Sha256: 3c8e448d198663975448c2f82caf7e249e83db1ec01bac5cd526e29657656ea1
Contents?: true
Size: 1.09 KB
Versions: 1
Compression:
Stored size: 1.09 KB
Contents
require 'active_model/serializer' module SpreeSignifyd class UserSerializer < ActiveModel::Serializer self.root = false attributes :emailAddress, :username, :createdDate, :lastUpdateDate, :aggregateOrderCount, :aggregateOrderDollars, :phone # this is how to conditionally include attributes in AMS def attributes(*args) hash = super hash[:lastOrderId] = lastOrderId if lastOrderId.present? hash end def emailAddress object.email end def username object.email end def createdDate object.created_at.utc.iso8601 end def lastUpdateDate object.updated_at.utc.iso8601 end def lastOrderId completed_orders.order("completed_at DESC").second.try(:number) end def aggregateOrderCount completed_orders.count end def aggregateOrderDollars completed_orders.sum(:total).to_f end def phone object.orders.order("created_at DESC").first.try!(:ship_address).try!(:phone) end private def completed_orders @order ||= object.orders.complete end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
solidus_signifyd-1.1.0 | app/serializers/spree_signifyd/user_serializer.rb |