Sha256: dc7a25089085200ae568a428f837e8ab7dd231efc24b7c3a0c0b55134e6a0768

Contents?: true

Size: 537 Bytes

Versions: 5

Compression:

Stored size: 537 Bytes

Contents

require 'json'

module SolidusMailchimpSync
  # Line item for Cart or Order, mailchimp serializes the same
  class LineItemSerializer
    attr_reader :line_item

    def initialize(line_item)
      @line_item = line_item
    end

    def as_json
      {
        id: line_item.id.to_s,
        product_id: line_item.product.id.to_s,
        product_variant_id: line_item.variant.id.to_s,
        quantity: line_item.quantity,
        price: line_item.price.to_f
      }
    end

    def to_json
      JSON.dump(as_json)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
solidus_mailchimp_sync-1.0.0.beta05 app/serializers/solidus_mailchimp_sync/line_item_serializer.rb
solidus_mailchimp_sync-1.0.0.beta04 app/serializers/solidus_mailchimp_sync/line_item_serializer.rb
solidus_mailchimp_sync-1.0.0.beta03 app/serializers/solidus_mailchimp_sync/line_item_serializer.rb
solidus_mailchimp_sync-1.0.0.beta02 app/serializers/solidus_mailchimp_sync/line_item_serializer.rb
solidus_mailchimp_sync-1.0.0.beta01 app/serializers/solidus_mailchimp_sync/line_item_serializer.rb