diff --git a/app/models/concerns/product_stock.rb b/app/models/concerns/product_stock.rb index 4f01b3069f..60e98d7791 100644 --- a/app/models/concerns/product_stock.rb +++ b/app/models/concerns/product_stock.rb @@ -4,7 +4,7 @@ module ProductStock extend ActiveSupport::Concern def on_demand - if has_variants? + if variants? raise 'Cannot determine product on_demand value of product with multiple variants' if variants.size > 1 variants.first.on_demand @@ -14,7 +14,7 @@ module ProductStock end def on_hand - if has_variants? + if variants? variants.map(&:on_hand).reduce(:+) else master.on_hand diff --git a/app/models/spree/option_type.rb b/app/models/spree/option_type.rb index f0260a13d2..91b65c97bb 100644 --- a/app/models/spree/option_type.rb +++ b/app/models/spree/option_type.rb @@ -9,6 +9,10 @@ module Spree validates :name, :presentation, presence: true default_scope -> { order("#{table_name}.position") } - accepts_nested_attributes_for :option_values, reject_if: lambda { |ov| ov[:name].blank? || ov[:presentation].blank? }, allow_destroy: true + accepts_nested_attributes_for :option_values, + reject_if: lambda { |ov| + ov[:name].blank? || ov[:presentation].blank? + }, + allow_destroy: true end end diff --git a/app/models/spree/price.rb b/app/models/spree/price.rb index d0dab12359..47c8eb2134 100644 --- a/app/models/spree/price.rb +++ b/app/models/spree/price.rb @@ -15,7 +15,7 @@ module Spree alias :display_price :display_amount def money - Spree::Money.new(amount || 0, { currency: currency }) + Spree::Money.new(amount || 0, currency: currency) end def price diff --git a/app/models/spree/product.rb b/app/models/spree/product.rb index 612ed9c57f..5ea1ad0c59 100755 --- a/app/models/spree/product.rb +++ b/app/models/spree/product.rb @@ -68,7 +68,7 @@ module Spree has_many :stock_items, through: :variants delegate_belongs_to :master, :sku, :price, :currency, :display_amount, :display_price, :weight, - :height, :width, :depth, :is_master, :has_default_price?, :cost_currency, + :height, :width, :depth, :is_master, :default_price?, :cost_currency, :price_in, :amount_in, :unit_value, :unit_description delegate_belongs_to :master, :cost_price if Variant.table_exists? && Variant.column_names.include?('cost_price') @@ -150,8 +150,12 @@ module Spree } scope :visible_for, lambda { |enterprise| - joins('LEFT OUTER JOIN spree_variants AS o_spree_variants ON (o_spree_variants.product_id = spree_products.id)'). - joins('LEFT OUTER JOIN inventory_items AS o_inventory_items ON (o_spree_variants.id = o_inventory_items.variant_id)'). + joins(' + LEFT OUTER JOIN spree_variants AS o_spree_variants + ON (o_spree_variants.product_id = spree_products.id)'). + joins(' + LEFT OUTER JOIN inventory_items AS o_inventory_items + ON (o_spree_variants.id = o_inventory_items.variant_id)'). where('o_inventory_items.enterprise_id = (?) AND visible = (?)', enterprise, true) } @@ -225,7 +229,7 @@ module Spree end # the master variant is not a member of the variants array - def has_variants? + def variants? variants.any? end diff --git a/app/models/spree/variant.rb b/app/models/spree/variant.rb index 26a3d0327b..8fa350444b 100644 --- a/app/models/spree/variant.rb +++ b/app/models/spree/variant.rb @@ -39,7 +39,8 @@ module Spree has_many :prices, class_name: 'Spree::Price', dependent: :destroy - delegate_belongs_to :default_price, :display_price, :display_amount, :price, :price=, :currency if Spree::Price.table_exists? + delegate_belongs_to :default_price, :display_price, :display_amount, + :price, :price=, :currency has_many :exchange_variants has_many :exchanges, through: :exchange_variants @@ -52,7 +53,7 @@ module Spree validates :price, numericality: { greater_than_or_equal_to: 0 }, presence: true, if: proc { Spree::Config[:require_master_price] } - validates :cost_price, numericality: { greater_than_or_equal_to: 0, allow_nil: true } if table_exists? && column_names.include?('cost_price') + validates :cost_price, numericality: { greater_than_or_equal_to: 0, allow_nil: true } validates :unit_value, presence: true, if: ->(variant) { %w(weight volume).include?(variant.product.andand.variant_unit) @@ -219,7 +220,7 @@ module Spree option_values.detect { |o| o.option_type.name == opt_name }.try(:presentation) end - def has_default_price? + def default_price? !default_price.nil? end diff --git a/lib/spree/product_duplicator.rb b/lib/spree/product_duplicator.rb index 8866f85fa5..7c27e058d7 100644 --- a/lib/spree/product_duplicator.rb +++ b/lib/spree/product_duplicator.rb @@ -12,7 +12,7 @@ module Spree new_product = duplicate_product # don't dup the actual variants, just the characterising types - new_product.option_types = product.option_types if product.has_variants? + new_product.option_types = product.option_types if product.variants? # allow site to do some customization new_product.__send__(:duplicate_extra, product) if new_product.respond_to?(:duplicate_extra) diff --git a/spec/lib/spree/product_duplicator_spec.rb b/spec/lib/spree/product_duplicator_spec.rb index 7978465a5e..0a04ec4161 100644 --- a/spec/lib/spree/product_duplicator_spec.rb +++ b/spec/lib/spree/product_duplicator_spec.rb @@ -10,7 +10,7 @@ module Spree taxons: [], product_properties: [property], master: variant, - has_variants?: false + variants?: false end let(:new_product) do