Skip to content

Instantly share code, notes, and snippets.

@0xjmp
Created May 3, 2014 01:27
Show Gist options
  • Select an option

  • Save 0xjmp/1fe3b68a72ff64b17cdb to your computer and use it in GitHub Desktop.

Select an option

Save 0xjmp/1fe3b68a72ff64b17cdb to your computer and use it in GitHub Desktop.
json.products @products do |product|
json.(product, :id, :price, :permalink)
end
def index
taxon = Spree::Taxon.where(permalink: params[:taxon]).first
raise InvalidTaxon if taxon.blank? || params[:taxon].match('swatch')
@products = SizeFilterService.new(taxon, params).filter!
end
Jbuilder.encode do |json|
json.(@product, :id, :name, :sku, :description, :price)
json.permalink @product.slug
json.in_stock @product.in_stock?
json.collection @product.collection.name.titelize if @product.collection.present?
json.images @product.images do |image|
json.original_image_url image.attachment.url(:original)
json.image_url image.attachment.url(:product_medium)
json.large_image_url image.attachment.url(:large)
json.mini_image_url image.attachment.url(:mini)
end
json.variants @product.variants do |variant|
json.(variant, :sku, :id, :product_id)
json.in_stock variant.in_stock?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment