Search code examples
ruby-on-railsspree

How to ignore the available_on attribute of Spree::Product?


Spree::Product.available_on is not a required field but the product won't be shown unless you set a date in the past to it.

Is there any way to avoid this?

Let's say all products are always available.


Solution

  • You can always override spree, in your case you need to change this line from:

    base_scope = Spree::Product.spree_base_scopes.active
    

    to

    base_scope = Spree::Product.spree_base_scopes
    

    The active method is defined here, you can see how it is checking for the available_on date.

    With that being said, I think it will be easier if you set an available_on date for all of your products:

    Spree::Product.update(available_on: 1.day.ago)