Module: SolidusFriendlyPromotions::ShippingRateDecorator

Defined in:
app/decorators/models/solidus_friendly_promotions/shipping_rate_decorator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.prepended(base) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'app/decorators/models/solidus_friendly_promotions/shipping_rate_decorator.rb', line 5

def self.prepended(base)
  base.class_eval do
    has_many :discounts,
      class_name: "SolidusFriendlyPromotions::ShippingRateDiscount",
      foreign_key: :shipping_rate_id,
      dependent: :destroy,
      inverse_of: :shipping_rate,
      autosave: true

    money_methods :total_before_tax, :promo_total
  end
end

Instance Method Details

#promo_totalObject



22
23
24
# File 'app/decorators/models/solidus_friendly_promotions/shipping_rate_decorator.rb', line 22

def promo_total
  discounts.sum(&:amount)
end

#total_before_taxObject



18
19
20
# File 'app/decorators/models/solidus_friendly_promotions/shipping_rate_decorator.rb', line 18

def total_before_tax
  amount + promo_total
end