Merge branch 'master' into 2-0-stable-Mar6

This commit is contained in:
luisramos0
2019-03-06 09:19:53 +00:00
79 changed files with 7134 additions and 3387 deletions

View File

@@ -27,19 +27,21 @@ module OpenFoodNetwork
private
def cached_products_json
if Rails.env.production? || Rails.env.staging?
Rails.cache.fetch("products-json-#{@distributor.id}-#{@order_cycle.id}") do
begin
uncached_products_json
rescue ProductsRenderer::NoProducts
nil
end
return uncached_products_json unless use_cached_products?
Rails.cache.fetch("products-json-#{@distributor.id}-#{@order_cycle.id}") do
begin
uncached_products_json
rescue ProductsRenderer::NoProducts
nil
end
else
uncached_products_json
end
end
def use_cached_products?
Spree::Config[:enable_products_cache?] && (Rails.env.production? || Rails.env.staging?)
end
def uncached_products_json
ProductsRenderer.new(@distributor, @order_cycle).products_json
end

View File

@@ -22,20 +22,18 @@ module OpenFoodNetwork
# Uses variant_override.count_on_hand instead of Stock::Quantifier.stock_items.count_on_hand
def total_on_hand
@variant_override.andand.count_on_hand || super
if @variant_override.present? && @variant_override.stock_overridden?
@variant_override.count_on_hand
else
super
end
end
def on_demand
if @variant_override.andand.on_demand.nil?
if @variant_override.andand.count_on_hand.present?
# If we're overriding the stock level of an on_demand variant, show it as not
# on_demand, so our stock control can take effect.
false
else
super
end
if @variant_override.present? && !@variant_override.use_producer_stock_settings?
@variant_override.on_demand
else
@variant_override.andand.on_demand
super
end
end