Spree::ProductsController.class_eval do
  before_filter :can_show_product, :only => :show

  private
  def can_show_product
    @product ||= Spree::Product.find_by_permalink!(params[:id])
    if @product.stores.empty? || !@product.stores.include?(current_store)
      render :file => "#{::Rails.root}/public/404", :status => 404, :formats => [:html]
    end
  end

end

Spree::ProductsController.class_eval do
  before_filter :can_show_product, :only => :show

  private
  def can_show_product
    @product ||= Spree::Product.find_by_permalink!(params[:id])
    if @product.stores.empty? || !@product.stores.include?(current_store)
      raise ActiveRecord::RecordNotFound
    end
  end

end

Raise an ActiveRecord::RecordNotFound exception in ProductsController
Raise an ActiveRecord::RecordNotFound exception in ProductsController

By rendering the 404 template, it renders within the layout and looks ugly. Raising an AR::RecordNotFound exception here will render the 404 page normally.
