Skip to content

Commit

Permalink
Fetch and scope variants for shop in ProductsRenderer only once
Browse files Browse the repository at this point in the history
  • Loading branch information
kristinalim committed Sep 5, 2019
1 parent 725807f commit 0138d07
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions lib/open_food_network/products_renderer.rb
Expand Up @@ -54,14 +54,16 @@ def taxon_order
end

def all_variants_for_shop
# We use the in_stock? method here instead of the in_stock scope because we need to
# look up the stock as overridden by VariantOverrides, and the scope method is not affected
# by them.
scoper = OpenFoodNetwork::ScopeVariantToHub.new(@distributor)
Spree::Variant.
for_distribution(@order_cycle, @distributor).
each { |v| scoper.scope(v) }.
select(&:in_stock?)
@all_variants_for_shop ||= begin
# We use the in_stock? method here instead of the in_stock scope
# because we need to look up the stock as overridden by
# VariantOverrides, and the scope method is not affected by them.
scoper = OpenFoodNetwork::ScopeVariantToHub.new(@distributor)
@all_variants_for_shop = Spree::Variant.
for_distribution(@order_cycle, @distributor).
each { |v| scoper.scope(v) }.
select(&:in_stock?)
end
end

def variants_for_shop_by_id
Expand Down

0 comments on commit 0138d07

Please sign in to comment.