mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-05 22:26:07 +00:00
Only scope with variant override when inventory enabled
This commit is contained in:
@@ -41,8 +41,16 @@ class ProductsRenderer
|
||||
distributed_products.products_relation
|
||||
end
|
||||
results = filter(results)
|
||||
# Scope results with variant_overrides
|
||||
paginate(results).each { |product| product_scoper.scope(product) }
|
||||
|
||||
paginated_products = paginate(results)
|
||||
|
||||
# TODO test this ?
|
||||
if options[:inventory_enabled]
|
||||
# Scope results with variant_overrides
|
||||
paginated_products.each { |product| product_scoper.scope(product) }
|
||||
end
|
||||
|
||||
paginated_products
|
||||
end
|
||||
end
|
||||
|
||||
@@ -117,8 +125,9 @@ class ProductsRenderer
|
||||
where(product_id: products)
|
||||
|
||||
if options[:inventory_enabled]
|
||||
# Scope results with variant_overrides
|
||||
scoper = OpenFoodNetwork::ScopeVariantToHub.new(distributor)
|
||||
variants = variants.each { |v| scoper.scope(v) } # Scope results with variant_overrides
|
||||
variants = variants.each { |v| scoper.scope(v) }
|
||||
end
|
||||
|
||||
variants
|
||||
|
||||
@@ -205,11 +205,23 @@ RSpec.describe ProductsRenderer do
|
||||
expect(products_renderer.products_json).to include "998.0"
|
||||
end
|
||||
|
||||
it "loads tag_list for variants" do
|
||||
products_renderer = ProductsRenderer.new(distributor, order_cycle, customer, {},
|
||||
inventory_enabled: true)
|
||||
VariantOverride.create(variant:, hub: distributor, tag_list: 'lalala')
|
||||
expect(products_renderer.products_json).to include "[\"lalala\"]"
|
||||
context "when inventory is enabled" do
|
||||
it "loads tag_list for variants" do
|
||||
products_renderer = ProductsRenderer.new(distributor, order_cycle, customer, {},
|
||||
inventory_enabled: true)
|
||||
VariantOverride.create(variant:, hub: distributor, tag_list: 'lalala')
|
||||
expect(products_renderer.products_json).to include "[\"lalala\"]"
|
||||
end
|
||||
|
||||
it "loads variant override" do
|
||||
products_renderer = ProductsRenderer.new(distributor, order_cycle, customer, {},
|
||||
inventory_enabled: true)
|
||||
VariantOverride.create(variant:, hub: distributor, price: 25.00)
|
||||
|
||||
json = products_renderer.products_json
|
||||
first_variant = JSON.parse(json).first["variants"].first
|
||||
expect(first_variant["price_with_fees"]).to eq("25.0")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user