Module: SolidusVolumePricing::SpreeVariantPatch

Defined in:
app/patches/models/solidus_volume_pricing/spree_variant_patch.rb

Class Method Summary collapse

Class Method Details

.prepended(base) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/patches/models/solidus_volume_pricing/spree_variant_patch.rb', line 5

def self.prepended(base)
  base.class_eval do
    has_and_belongs_to_many :volume_price_models
    has_many :volume_prices, -> { order(position: :asc) }, dependent: :destroy
    has_many :model_volume_prices, -> {
      order(position: :asc)
    }, class_name: "::Spree::VolumePrice", through: :volume_price_models, source: :volume_prices
    accepts_nested_attributes_for :volume_prices, allow_destroy: true,
      reject_if: proc { |volume_price|
        volume_price[:amount].blank? && volume_price[:range].blank?
      }
  end
end