Sha256: f18159d109f7af8d091b846481d01b0a750aa214ac63a5105b45b3463d22fd9f
Contents?: true
Size: 781 Bytes
Versions: 14
Compression:
Stored size: 781 Bytes
Contents
module Returnly module Discounts class Order attr_reader :adjustment, :order def initialize(order, adjustment) @adjustment = adjustment @order = order end def discount_amount(line_item, units = 0) return 0.0 if units <= 0 units = line_item.quantity if units > line_item.quantity (adjustment.amount * price_percent(line_item) / 100) * weight_of(line_item, units.to_d) end private def price_percent(line_item) (line_item.price * 100 / order_items_price).round(2, :down) end def order_items_price order.line_items.sum(&:price) end def weight_of(line_item, units) (units / line_item.quantity).round(2, :down) end end end end
Version data entries
14 entries across 14 versions & 2 rubygems