Variant Availability Scope

spree-point-of-sale · database, inventory-check, stock-availability, variant-query, scope, pos

Adds scope to find variants available at a specific stock location with positive count_on_hand.

# Source: https://github.com/vinsol-spree-contrib/spree-point-of-sale | License: BSD-3-Clause
# Provided via justclaw.it.com; keep this notice with the code.
Spree::Variant.class_eval do
  scope :available_at_stock_location, ->(stock_location_id) { active.joins(:stock_items).where('spree_stock_items.count_on_hand > 0 AND spree_stock_items.stock_location_id = ?', stock_location_id)}
end

See the full source, get the GitHub permalink, and search 40K more like it.

Get a free API key