mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-04-03 06:59:14 +00:00
Call VariantTagRulesFilterer when variant_tag feature is enabled
We only support either inventory or variant_tag feature, with the later taking precedence if both are turned on.
This commit is contained in:
@@ -118,13 +118,22 @@ module OrderCycles
|
||||
end
|
||||
|
||||
def variants
|
||||
options[:inventory_enabled] ? stocked_variants_and_overrides : stocked_variants
|
||||
return tag_rule_filtered_variants if options[:variant_tag_enabled]
|
||||
|
||||
return stocked_variants_and_overrides if options[:inventory_enabled]
|
||||
|
||||
stocked_variants
|
||||
end
|
||||
|
||||
def stocked_variants
|
||||
Spree::Variant.joins(:stock_items).where(query_stock)
|
||||
end
|
||||
|
||||
def tag_rule_filtered_variants
|
||||
VariantTagRulesFilterer.new(distributor:, customer:,
|
||||
variants_relation: stocked_variants).call
|
||||
end
|
||||
|
||||
def stocked_variants_and_overrides
|
||||
stocked_variants = Spree::Variant.
|
||||
joins("LEFT OUTER JOIN variant_overrides ON variant_overrides.variant_id = spree_variants.id
|
||||
|
||||
@@ -68,6 +68,20 @@ RSpec.describe OrderCycles::DistributedProductsService do
|
||||
|
||||
expect(products_relation).not_to include product
|
||||
end
|
||||
|
||||
context "with variant_tag enabled" do
|
||||
subject(:products_relation) {
|
||||
described_class.new(
|
||||
distributor, order_cycle, customer, variant_tag_enabled: true
|
||||
).products_relation
|
||||
}
|
||||
|
||||
it "calls VariantTagRulesFilterer" do
|
||||
expect(VariantTagRulesFilterer).to receive(:new).and_call_original
|
||||
|
||||
products_relation
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "with variant overrides" do
|
||||
@@ -81,6 +95,12 @@ RSpec.describe OrderCycles::DistributedProductsService do
|
||||
create(:variant_override, hub: distributor, variant:, count_on_hand: 0)
|
||||
}
|
||||
|
||||
it "calls ProductTagRulesFilterer" do
|
||||
expect(ProductTagRulesFilterer).to receive(:new).and_call_original
|
||||
|
||||
products_relation
|
||||
end
|
||||
|
||||
it "does not return product when an override is out of stock" do
|
||||
expect(products_relation).not_to include product
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user