diff --git a/app/models/spree/product.rb b/app/models/spree/product.rb index 09b239855b..140a508af7 100755 --- a/app/models/spree/product.rb +++ b/app/models/spree/product.rb @@ -52,11 +52,11 @@ module Spree dependent: :destroy has_many :variants, -> { - where(is_master: false).order("#{::Spree::Variant.quoted_table_name}.position ASC") + where(is_master: false).order("spree_variants.position ASC") }, class_name: 'Spree::Variant' has_many :variants_including_master, - -> { order("#{::Spree::Variant.quoted_table_name}.position ASC") }, + -> { order("spree_variants.position ASC") }, class_name: 'Spree::Variant', dependent: :destroy @@ -90,7 +90,7 @@ module Spree validates :supplier, presence: true validates :primary_taxon, presence: true - validates :tax_category_id, presence: true, if: "Spree::Config.products_require_tax_category" + validates :tax_category_id, presence: true, if: proc { Spree::Config[:products_require_tax_category] } validates :variant_unit, presence: true validates :unit_value, presence: { if: ->(p) { %w(weight volume).include? p.variant_unit } } diff --git a/app/models/spree/variant.rb b/app/models/spree/variant.rb index 93430b3b2b..ed94fba1e6 100644 --- a/app/models/spree/variant.rb +++ b/app/models/spree/variant.rb @@ -109,12 +109,13 @@ module Spree } scope :not_hidden_for, lambda { |enterprise| - return where("1=0") if enterprise.blank? + enterprise_id = enterprise&.id.to_i + return none if enterprise_id < 1 joins(" LEFT OUTER JOIN (SELECT * FROM inventory_items - WHERE enterprise_id = #{sanitize enterprise.andand.id}) + WHERE enterprise_id = #{enterprise_id}) AS o_inventory_items ON o_inventory_items.variant_id = spree_variants.id") .where("o_inventory_items.id IS NULL OR o_inventory_items.visible = (?)", true) diff --git a/spec/models/spree/preferences/preferable_spec.rb b/spec/models/spree/preferences/preferable_spec.rb index 3e156fce1f..b355ba415c 100644 --- a/spec/models/spree/preferences/preferable_spec.rb +++ b/spec/models/spree/preferences/preferable_spec.rb @@ -222,7 +222,7 @@ describe Spree::Preferences::Preferable do describe "persisted preferables" do before(:all) do - class CreatePrefTest < ActiveRecord::Migration + class CreatePrefTest < ActiveRecord::Migration[4.2] def self.up create_table :pref_tests do |t| t.string :col diff --git a/spec/models/spree/product_spec.rb b/spec/models/spree/product_spec.rb index c1da45eddc..c3814bebf8 100644 --- a/spec/models/spree/product_spec.rb +++ b/spec/models/spree/product_spec.rb @@ -88,13 +88,13 @@ module Spree describe 'Variants sorting' do context 'without master variant' do it 'sorts variants by position' do - expect(product.variants.to_sql).to match(/ORDER BY (\`|\")spree_variants(\`|\").position ASC/) + expect(product.variants.to_sql).to match(/ORDER BY spree_variants.position ASC/) end end context 'with master variant' do it 'sorts variants by position' do - expect(product.variants_including_master.to_sql).to match(/ORDER BY (\`|\")spree_variants(\`|\").position ASC/) + expect(product.variants_including_master.to_sql).to match(/ORDER BY spree_variants.position ASC/) end end end