Sha256: 34136c411ad260f6f588119147067e223fbc98f824e284f70b7f4c28c7e8d638

Contents?: true

Size: 1.62 KB

Versions: 1

Compression:

Stored size: 1.62 KB

Contents

module Spree
  module V2
    module Storefront
      class CartSerializer < BaseSerializer
        set_type :cart

        attributes :number, :item_total, :total, :ship_total, :adjustment_total, :created_at,
                   :updated_at, :included_tax_total, :additional_tax_total, :display_additional_tax_total,
                   :display_included_tax_total, :tax_total, :currency, :state, :token, :email,
                   :display_item_total, :display_ship_total, :display_adjustment_total, :display_tax_total,
                   :promo_total, :display_promo_total, :item_count, :special_instructions, :display_total

        has_many   :line_items
        has_many   :variants
        has_many   :promotions, id_method_name: :promotion_id do |cart|
          # we only want to display applied and valid promotions
          # sometimes Order can have multiple promotions but the promo engine
          # will only apply those that are more beneficial for the customer
          # TODO: we should probably move this code out of the serializer
          promotion_ids = cart.all_adjustments.eligible.nonzero.promotion.map { |a| a.source.promotion_id }.uniq

          cart.order_promotions.where(promotion_id: promotion_ids).uniq(&:promotion_id)
        end
        has_many   :payments do |cart|
          cart.payments.valid
        end
        has_many   :shipments

        belongs_to :user
        belongs_to :billing_address,
          id_method_name: :bill_address_id,
          serializer: :address

        belongs_to :shipping_address,
          id_method_name: :ship_address_id,
          serializer: :address
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
spree_api-3.7.0.rc1 app/serializers/spree/v2/storefront/cart_serializer.rb