From 4b5f2d66d0c1eb52eb65e098fcc816efcc0fd119 Mon Sep 17 00:00:00 2001 From: Mayank Taparia Date: Wed, 30 Jan 2019 22:53:25 +0530 Subject: [PATCH] Show Unique Variants regardless of stock location --- core/app/models/spree/variant.rb | 2 +- core/spec/models/spree/variant_spec.rb | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/core/app/models/spree/variant.rb b/core/app/models/spree/variant.rb index 313823ade79..e41f269795c 100644 --- a/core/app/models/spree/variant.rb +++ b/core/app/models/spree/variant.rb @@ -121,7 +121,7 @@ def self.suppliable Spree::StockItem.arel_table[:count_on_hand].gt(0), Spree::StockItem.arel_table[:backorderable].eq(true) ] - joins(:stock_items).where(arel_conditions.inject(:or)) + joins(:stock_items).where(arel_conditions.inject(:or)).distinct end self.whitelisted_ransackable_associations = %w[option_values product prices default_price] diff --git a/core/spec/models/spree/variant_spec.rb b/core/spec/models/spree/variant_spec.rb index ddea06af52a..9cb6d9bacdc 100644 --- a/core/spec/models/spree/variant_spec.rb +++ b/core/spec/models/spree/variant_spec.rb @@ -783,6 +783,10 @@ expect( subject ).not_to include(out_of_stock_variant) end + it "includes variants only once" do + expect(subject.to_a.count(in_stock_variant)).to be 1 + end + context "inventory levels globally not tracked" do before { Spree::Config.track_inventory_levels = false }