Sha256: 288ce9835465a60a3ec550fffc4a7c10db7de2bdb13e6bbe6d22997e6aa63154

Contents?: true

Size: 1.39 KB

Versions: 62

Compression:

Stored size: 1.39 KB

Contents

module Workarea
  module Pricing
    class Discount
      # This discount allows for basic percent of flat amount
      # off an order total.
      #
      class OrderTotal < Discount
        include FlatOrPercentOff
        include Conditions::OrderTotal
        include Conditions::PromoCodes
        include Conditions::UserTags

        # @private
        def self.model_name
          Discount.model_name
        end

        # Price changes apply at the order level
        #
        # @return [String]
        #
        self.price_level = 'order'
        add_qualifier :has_items?

        # Qualifier method to ensure that the order has
        # some quantity.
        #
        # @param [Workarea::Order] order
        # @return [Boolean]
        #
        def has_items?(order)
          order.quantity > 0
        end

        # Create the price adjustments for amount off the order total.
        # Distributes the discount amount across all items.
        #
        # @param [Pricing::Discount::Order]
        #
        def apply(order)
          total_amount = amount_calculator.calculate(order.subtotal_price)
          distribution = PriceDistributor.for_items(total_amount, order.items)

          order.items.each do |item|
            item_total = distribution[item.id]
            item.adjust_pricing(adjustment_data(item_total, item.quantity))
          end
        end
      end
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-core-3.5.27 app/models/workarea/pricing/discount/order_total.rb
workarea-core-3.5.26 app/models/workarea/pricing/discount/order_total.rb
workarea-core-3.4.45 app/models/workarea/pricing/discount/order_total.rb
workarea-core-3.5.25 app/models/workarea/pricing/discount/order_total.rb
workarea-core-3.5.23 app/models/workarea/pricing/discount/order_total.rb
workarea-core-3.4.44 app/models/workarea/pricing/discount/order_total.rb
workarea-core-3.5.22 app/models/workarea/pricing/discount/order_total.rb
workarea-core-3.4.43 app/models/workarea/pricing/discount/order_total.rb
workarea-core-3.5.21 app/models/workarea/pricing/discount/order_total.rb
workarea-core-3.4.42 app/models/workarea/pricing/discount/order_total.rb
workarea-core-3.5.20 app/models/workarea/pricing/discount/order_total.rb
workarea-core-3.4.41 app/models/workarea/pricing/discount/order_total.rb
workarea-core-3.5.19 app/models/workarea/pricing/discount/order_total.rb
workarea-core-3.4.40 app/models/workarea/pricing/discount/order_total.rb
workarea-core-3.5.18 app/models/workarea/pricing/discount/order_total.rb
workarea-core-3.4.39 app/models/workarea/pricing/discount/order_total.rb
workarea-core-3.5.17 app/models/workarea/pricing/discount/order_total.rb
workarea-core-3.4.38 app/models/workarea/pricing/discount/order_total.rb
workarea-core-3.5.16 app/models/workarea/pricing/discount/order_total.rb
workarea-core-3.4.37 app/models/workarea/pricing/discount/order_total.rb