Sha256: 8fd67aa5048982481433c1fe587bc81ec32353f4b03d79b520b31ebb6dcb8a0b

Contents?: true

Size: 682 Bytes

Versions: 3

Compression:

Stored size: 682 Bytes

Contents

# frozen_string_literal: true

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

        money_methods :total_before_tax, :promo_total
      end
    end

    def total_before_tax
      amount + promo_total
    end

    def promo_total
      discounts.sum(&:amount)
    end

    Spree::ShippingRate.prepend SolidusPromotions::DiscountableAmount
    Spree::ShippingRate.prepend self
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
solidus_promotions-4.4.2 app/decorators/models/solidus_promotions/shipping_rate_decorator.rb
solidus_promotions-4.4.1 app/decorators/models/solidus_promotions/shipping_rate_decorator.rb
solidus_promotions-4.4.0 app/decorators/models/solidus_promotions/shipping_rate_decorator.rb