Adapt line_item.sufficient_stock? to spree 2

This commit is contained in:
luisramos0
2018-12-20 20:31:10 +00:00
parent d641705053
commit 1835d97013

View File

@@ -111,18 +111,15 @@ Spree::LineItem.class_eval do
final_weight_volume / quantity
end
# MONKEYPATCH of Spree method
# Enables scoping of variant to hub/shop, so we check stock against relevant overrides if they exist
# Also skips stock check if requested quantity is zero
# Overrides Spree version to:
# - skip stock check if skip_stock_check flag is active
# - skip stock check if requested quantity is zero or negative
# - scope variants to hub and thus acivate variant overrides
def sufficient_stock?
return true if quantity == 0 # This line added
scoper.scope(variant) # This line added
return true if variant.on_demand
if new_record? || !order.completed?
variant.on_hand >= quantity
else
variant.on_hand >= (quantity - self.changed_attributes['quantity'].to_i)
end
return true if skip_stock_check
return true if quantity <= 0
scoper.scope(variant)
variant.can_supply?(quantity)
end
def scoper