mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-13 04:00:21 +00:00
Fetch indexed variant overrides in one go
This commit is contained in:
@@ -4,17 +4,19 @@ module OpenFoodNetwork
|
||||
class ScopeProductToHub
|
||||
def initialize(hub)
|
||||
@hub = hub
|
||||
@variant_overrides = VariantOverride.indexed @hub
|
||||
end
|
||||
|
||||
def scope(product)
|
||||
product.send :extend, OpenFoodNetwork::ScopeProductToHub::ScopeProductToHub
|
||||
product.instance_variable_set :@hub, @hub
|
||||
product.instance_variable_set :@variant_overrides, @variant_overrides
|
||||
end
|
||||
|
||||
|
||||
module ScopeProductToHub
|
||||
def variants_distributed_by(order_cycle, distributor)
|
||||
super.each { |v| ScopeVariantToHub.new(@hub).scope(v) }
|
||||
super.each { |v| ScopeVariantToHub.new(@hub, @variant_overrides).scope(v) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
module OpenFoodNetwork
|
||||
class ScopeVariantToHub
|
||||
def initialize(hub)
|
||||
def initialize(hub, variant_overrides=nil)
|
||||
@hub = hub
|
||||
@variant_overrides = variant_overrides || VariantOverride.indexed(@hub)
|
||||
end
|
||||
|
||||
def scope(variant)
|
||||
variant.send :extend, OpenFoodNetwork::ScopeVariantToHub::ScopeVariantToHub
|
||||
variant.instance_variable_set :@hub, @hub
|
||||
variant.instance_variable_set :@variant_override, VariantOverride.send(:for, @hub, variant)
|
||||
variant.instance_variable_set :@variant_override, @variant_overrides[variant]
|
||||
end
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user