diff --git a/app/models/spree/line_item_decorator.rb b/app/models/spree/line_item_decorator.rb index a691d6fd..fdf779d6 100644 --- a/app/models/spree/line_item_decorator.rb +++ b/app/models/spree/line_item_decorator.rb @@ -6,24 +6,28 @@ module Spree::LineItemDecorator # chosen for the product. This is mainly for compatibility with spree_sale_products # # Assumption here is that the volume price currency is the same as the product currency - - def self.prepended(base) - old_copy_price = base.instance_method(:copy_price) - define_method(:copy_price) do - old_copy_price.bind(self).call - return unless variant + def copy_price + return unless variant - if changed? && changes.keys.include?('quantity') - vprice = variant.volume_price(quantity, order.user) - if price.present? && vprice <= variant.price - self.price = vprice and return - end + if changed? && changes.keys.include?('quantity') + vprice = variant.volume_price(quantity, order.user) + if price.present? && vprice <= variant.price + self.price = vprice and return end self.price = variant.price if price.nil? end end + + def update_price + vprice = variant.volume_price(quantity, order.user) + if price.present? && vprice <= variant.price + self.price = variant.volume_price(quantity, order.user) and return + end + self.price = variant.price if price.nil? + end + end Spree::LineItem.prepend Spree::LineItemDecorator diff --git a/app/models/spree/variant_decorator.rb b/app/models/spree/variant_decorator.rb index 870a4d24..9cc22950 100644 --- a/app/models/spree/variant_decorator.rb +++ b/app/models/spree/variant_decorator.rb @@ -12,21 +12,11 @@ def self.prepended(base) def join_volume_prices(user = nil) table = Spree::VolumePrice.arel_table - if user - Spree::VolumePrice.where( - (table[:variant_id].eq(id) - .or(table[:volume_price_model_id].in(volume_price_models.ids))) - .and(table[:role_id].eq(user.resolve_role.try(:id))) - ) - .order(position: :asc) - else - Spree::VolumePrice.where( - (table[:variant_id] - .eq(id) - .or(table[:volume_price_model_id].in(volume_price_models.ids))) - .and(table[:role_id].eq(nil)) - ).order(position: :asc) - end + Spree::VolumePrice.where( + (table[:variant_id] + .eq(id) + .or(table[:volume_price_model_id].in(volume_price_models.ids))) + ).order(position: :asc) end # calculates the price based on quantity diff --git a/app/views/spree/admin/variants/_edit_fields.html.erb b/app/views/spree/admin/variants/_edit_fields.html.erb index e0a61cd1..a078fac3 100644 --- a/app/views/spree/admin/variants/_edit_fields.html.erb +++ b/app/views/spree/admin/variants/_edit_fields.html.erb @@ -14,7 +14,7 @@