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 @@ <%= Spree.t(:range) %> <%= Spree.t(:amount) %> <%= Spree.t(:position) %> - <%= Spree.t(:role) %> + <%= Spree.t(:action) %> diff --git a/app/views/spree/admin/volume_prices/_edit_fields.html.erb b/app/views/spree/admin/volume_prices/_edit_fields.html.erb index 85a33991..653382e3 100644 --- a/app/views/spree/admin/volume_prices/_edit_fields.html.erb +++ b/app/views/spree/admin/volume_prices/_edit_fields.html.erb @@ -18,7 +18,7 @@ <%= Spree.t(:range) %> <%= Spree.t(:amount) %> <%= Spree.t(:position) %> - <%= Spree.t(:role) %> + <%= Spree.t(:action) %> diff --git a/app/views/spree/admin/volume_prices/_volume_price_fields.html.erb b/app/views/spree/admin/volume_prices/_volume_price_fields.html.erb index e31db7fb..996c773c 100644 --- a/app/views/spree/admin/volume_prices/_volume_price_fields.html.erb +++ b/app/views/spree/admin/volume_prices/_volume_price_fields.html.erb @@ -23,10 +23,10 @@ <%= error_message_on(f.object, :position) %> <%= f.text_field :position, size: 3, class: 'form-control' %> - - <%= error_message_on(f.object, :role_id) %> - <%= f.collection_select(:role_id, Spree::Role.all, :id, :name, { include_blank: Spree.t('match_choices.none') }, { class: 'select2' }) %> - + <%= link_to_icon_remove_fields f %>