Reputation: 6531
I'm a newbie in spree rails, and using rails spree, my question is in admin panel of products it's Count On Hand is zero or negative, but it still does not show out of stock on product show page, however there is method on product's show page:
<% unless variant.can_supply? %>
<span class="out-of-stock">
<%= Spree.t(:out_of_stock) %>
</span>
<% end %>
I can't get it how this can_supply?
works.
Kindly help me out to implement out of stock functionality.
Thanks in advance.
Upvotes: 0
Views: 500
Reputation: 1
It does not show out of stock because by default track_inventory_levels is set to false. So to make it work set
Spree::Config[:track_inventory_levels]=true
You can set this value in spree.rb file which can be found in config/initializers folder.
Upvotes: 0
Reputation: 6513
def can_supply?(required = 1)
variant.available? && (total_on_hand >= required || backorderable?)
end
It just checks if the variant has any stock items which have the required stock or can be backordered.
Upvotes: 1