Sha256: eaf577920be45591065711d6ddec2dc9657279d7c965cbfc2892e1ca735a02ab

Contents?: true

Size: 857 Bytes

Versions: 2

Compression:

Stored size: 857 Bytes

Contents

module Spree
  module Wombat
    class AssemblyShipmentSerializer < ShipmentSerializer

      attributes :items

      def items
        i = []
        object.line_items.each do |li|
          next if li.nil?

          hsh = {
            product_id: li.variant.sku,
            name: li.name,
            quantity: li.quantity,
            price: li.price.to_f
          }

          if li.parts.present?
            bundled_items = []
            li.parts.each do |part|
              bundled_items << {
                product_id: part.sku,
                name: part.name,
                quantity: li.count_of(part),
                price: part.price.to_f
              }
            end
            hsh[:bundled_items] = bundled_items
          end
          i << hsh
        end
        i
      end
    end if defined?(ShipmentSerializer)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
solidus_product_bundle-1.0.1 app/serializers/spree/wombat/assembly_shipment_serializer.rb
solidus_product_bundle-1.0.0 app/serializers/spree/wombat/assembly_shipment_serializer.rb