https://github.com/spree/spree/blob/1-3-stable/core/app/models/spree/product.rb#L106-L108
).
I agree that it's a bug. The one solution I can think of for it is caching
this value in a database column and recalculating it using a background job
runner whenever Spree::Config[:show_zero_stock_products] or the stock level
for a product changes. This would involve a ton of work, mainly because
Spree doesn't use a background job runner right now. I'd love for it to,
though.
On Tue, Feb 12, 2013 at 11:31 PM, Nate Lowrie
wrote:
It seems spree is doing something that I find strange. It seems that we
are not filtering the products collection for on_display until we hit the
view.
*Products Controller*
*
*
def index
@searcher = Config.searcher_class.new(params)
@searcher.current_user = try_spree_current_user
@products = @searcher.retrieve_products
respond_with(@products)
end
*In /views/spree/shared/_products.html.erb*
*
*
<% products.each do |product| %>
<% if product.on_display? %>
So, what is happening here is that we are filtering the products with
on_display? = false in the products view after we already paginate on the
collection. As a result, if I display 16 products per page and 5 of them
have an on_display = false on the first page, when the view is rendered we
will only have 11 on the first page, yet a full 16 on the next. This looks
silly.
Imagine if you have a whole bunch of seasonal items that you want to hide
when they go out of stock (by setting the show_zero_stock_products
preference to false) until next christmas season. You have 30 products
that on_display now evaluates to false and when the Christmas taxon that
the products are tied to is rendered, the first page is completely blank
and the second page would only have 2 products on it.
Is there a way to do the on_display filter BEFORE we pass the collection
to the view? I checked the spree master branch and it doesn't seem to be
changed. I really think that this is a bug and should be fixed in core, but
I am open to patching it myself if I can figure out the syntax.
Regards,
Nate
--
You received this message because you are subscribed to the Google Groups
"Spree" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.
--are not filtering the products collection for on_display until we hit the
view.
*Products Controller*
*
*
def index
@searcher = Config.searcher_class.new(params)
@searcher.current_user = try_spree_current_user
@products = @searcher.retrieve_products
respond_with(@products)
end
*In /views/spree/shared/_products.html.erb*
*
*
<% products.each do |product| %>
<% if product.on_display? %>
So, what is happening here is that we are filtering the products with
on_display? = false in the products view after we already paginate on the
collection. As a result, if I display 16 products per page and 5 of them
have an on_display = false on the first page, when the view is rendered we
will only have 11 on the first page, yet a full 16 on the next. This looks
silly.
Imagine if you have a whole bunch of seasonal items that you want to hide
when they go out of stock (by setting the show_zero_stock_products
preference to false) until next christmas season. You have 30 products
that on_display now evaluates to false and when the Christmas taxon that
the products are tied to is rendered, the first page is completely blank
and the second page would only have 2 products on it.
Is there a way to do the on_display filter BEFORE we pass the collection
to the view? I checked the spree master branch and it doesn't seem to be
changed. I really think that this is a bug and should be fixed in core, but
I am open to patching it myself if I can figure out the syntax.
Regards,
Nate
--
You received this message because you are subscribed to the Google Groups
"Spree" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.
You received this message because you are subscribed to the Google Groups "Spree" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.