Sha256: c4cac2fee4446eefbe75560b4e73d55efa0e3c76138b9358f23372878bcbff1d
Contents?: true
Size: 1020 Bytes
Versions: 3
Compression:
Stored size: 1020 Bytes
Contents
require 'json' module SolidusMailchimpSync # Intentionally does not sync images, let variants do that. # class ProductSerializer attr_reader :product def initialize(product) @product = product unless product.persisted? raise ArgumentError, "Can't serialize a non-saved product: #{product}" end end # We don't include image or url, variants can have those anyway, # and variants are actually editable, do it there. def as_json hash = { id: product.id.to_s, handle: product.slug, title: product.name, description: product.description, variants: variants_json } if product.available_on hash[:published_at_foreign] = product.available_on.iso8601 end hash end def variants_json product.variants_including_master.collect do |variant| VariantSynchronizer.new(variant).serializer.as_json end end def to_json JSON.dump(as_json) end end end
Version data entries
3 entries across 3 versions & 1 rubygems