Skip to content

Instantly share code, notes, and snippets.

@HoyaBoya
Created February 3, 2014 18:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HoyaBoya/8789997 to your computer and use it in GitHub Desktop.
Save HoyaBoya/8789997 to your computer and use it in GitHub Desktop.
def product_scope
variants_associations = [{ option_values: :option_type }, {images_for_variant: {variant_images: :image}}, :default_price, :prices, :images, { variant_description: :description }]
if current_api_user.has_spree_role?("admin")
scope = Spree::Product.with_deleted.accessible_by(current_ability, :read)
.includes(:product_properties, {:option_types => :option_values}, variants: variants_associations, master: variants_associations)
unless params[:show_deleted]
scope = scope.not_deleted
end
else
scope = Spree::Product.accessible_by(current_ability, :read).active
.includes(:product_properties, {:option_types => :option_values}, variants: variants_associations, master: variants_associations)
end
scope
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment