You probably know already that on_display is a computed value (
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.

--
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.

Search Discussions

  • Nate Lowrie at Feb 13, 2013 at 2:40 pm
    I see... This is indeed a problem. I am currently building a plugin for
    explicitly setting sold items and discontinued items. I had put my logic in
    overridden on_display and on_sale methods am it works rather well except
    for this issue. I think I can do the work of kicking this off to a
    background processor. I do have a few questions:

    1. Is the spree core team planning on integrating a background processor
    into spree any time in the near future? If so, which one? I would
    implement the processing in the background server using delayed_job because
    Site5 doesn't support redis server installations.
    2. If I do implement the background processing and include on_display
    and on_sale boolean fields in the products table, will updating the
    available product scope be enough or will I need to modify other scopes?

    Regards,

    Nate
    On Tuesday, February 12, 2013 4:14:16 PM UTC-5, Ryan Bigg wrote:

    You probably know already that on_display is a computed value (
    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 <
    [email protected] <javascript:>> 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] <javascript:>.
    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.
  • Ryan Bigg at Feb 14, 2013 at 11:47 pm

    On Fri, Feb 15, 2013 at 6:15 AM, Nate Lowrie wrote:

    I need this in the next week so I will be building this out. Will using
    delayed_job in an extension conflict with anything you guys are planning on
    doing with the new integration service?

    As far as I know, no it won't conflict with it.
    I feel like it would be an immense benefit for me as a developer to have a
    roadmap on what long term architecture proposals the core team is
    considering/developing. I don't know of any document that let's me know
    what's planned for 2.0 and companion services like the one you just
    mentioned. There have been about a half a dozen different items that I've
    posted about in the last 2 months that have received where the response
    back was it's being developed for 2.0 or some companion service. It would
    be really helpful to know what exactly is being planned in the next few
    months so I can align my extensions and custom code to what the spree core
    team and spreecommerce.com are doing.
    I agree that a roadmap of sorts would be useful. I'm actually flying over
    to DC in 10 days (and I think Brian is coming over too), and during the
    time that I'm over there we're going to be talking strategy. I'm staying
    until March 3. Hopefully one of the things that comes out of it is a better
    idea of what you can expect in Spree 2.0. I'd love for us to put this in a
    publicly visible document when we've had some more internal discussions
    around it. That way, it would be visible for the users and us at all times
    so we all know where we're headed.



    Regards,

    Nate

    On Wednesday, February 13, 2013 5:56:48 PM UTC-5, schof wrote:

    We're working on a new commercial integration service. One of the many
    capabilities will be to do background type jobs so that might be a long
    term option for you. We'll have more details on that later.
    On Wednesday, February 13, 2013 9:40:19 AM UTC-5, Nate Lowrie wrote:

    I see... This is indeed a problem. I am currently building a plugin for
    explicitly setting sold items and discontinued items. I had put my logic in
    overridden on_display and on_sale methods am it works rather well except
    for this issue. I think I can do the work of kicking this off to a
    background processor. I do have a few questions:

    1. Is the spree core team planning on integrating a background
    processor into spree any time in the near future? If so, which one? I
    would implement the processing in the background server using delayed_job
    because Site5 doesn't support redis server installations.
    2. If I do implement the background processing and include
    on_display and on_sale boolean fields in the products table, will updating
    the available product scope be enough or will I need to modify other scopes?

    Regards,

    Nate
    On Tuesday, February 12, 2013 4:14:16 PM UTC-5, Ryan Bigg wrote:

    You probably know already that on_display is a computed value (
    https://github.com/spree/**spree/blob/1-3-stable/core/**
    app/models/spree/product.rb#**L106-L108<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 <
    [email protected]> 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].**com.
    For more options, visit https://groups.google.com/**groups/opt_out<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.

    --
    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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupspree-user @
categoriesrubyonrails
postedFeb 12, '13 at 9:14p
activeFeb 14, '13 at 11:47p
posts3
users2
websitespreecommerce.com
irc#RubyOnRails

2 users in discussion

Ryan Bigg: 2 posts Nate Lowrie: 1 post

People

Translate

site design / logo © 2023 Grokbase