Sha256: 987998590add902ecd4e0c47199f097e7b482a7414053ba71a2be8ef1c05745f

Contents?: true

Size: 1.27 KB

Versions: 3

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

module SolidusPromotions
  module OrderDecorator
    module ClassMethods
      def allowed_ransackable_associations
        super + ["solidus_promotions", "solidus_order_promotions"]
      end
    end

    def self.prepended(base)
      base.has_many :solidus_order_promotions,
        class_name: "SolidusPromotions::OrderPromotion",
        dependent: :destroy,
        inverse_of: :order
      base.has_many :solidus_promotions, through: :solidus_order_promotions, source: :promotion
    end

    def discountable_item_total
      line_items.sum(&:discountable_amount)
    end

    def reset_current_discounts
      line_items.each(&:reset_current_discounts)
      shipments.each(&:reset_current_discounts)
    end

    # This helper method excludes line items that are managed by an order benefit for the benefit
    # of calculators and benefits that discount normal line items. Line items that are managed by an
    # order benefits handle their discounts themselves.
    def discountable_line_items
      line_items.reject(&:managed_by_order_benefit)
    end

    def free_from_order_benefit?(line_item, _options)
      !line_item.managed_by_order_benefit
    end

    Spree::Order.singleton_class.prepend self::ClassMethods
    Spree::Order.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/order_decorator.rb
solidus_promotions-4.4.1 app/decorators/models/solidus_promotions/order_decorator.rb
solidus_promotions-4.4.0 app/decorators/models/solidus_promotions/order_decorator.rb