Sha256: 25a53da361cb7dfee3f66cc8518b51a224b39e14efec7db20e229df830ff67fa

Contents?: true

Size: 529 Bytes

Versions: 2

Compression:

Stored size: 529 Bytes

Contents

module Spree
  class ShippingMatrix < ActiveRecord::Base
    has_many :rules, ->{ order('min_line_item_total DESC') },
                     class_name: Spree::ShippingMatrixRule,
                     inverse_of: :matrix

    accepts_nested_attributes_for :rules, allow_destroy: true,
                                          reject_if: :rule_blank?

    validates :name, presence: true

    private

    def rule_blank?(attributes)
      attributes['min_line_item_total'].blank? || attributes['amount'].blank?
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
spree_shipping_matrix-0.2.0 app/models/spree/shipping_matrix.rb
spree_shipping_matrix-0.1.0 app/models/spree/shipping_matrix.rb