Only scope with variant override when inventory enabled

This commit is contained in:
Gaetan Craig-Riou
2025-06-05 18:31:38 +10:00
parent f30b899569
commit 82c99891eb
2 changed files with 29 additions and 8 deletions

View File

@@ -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

View File

@@ -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