Class: SolidusPromotions::Benefits::AdjustLineItemQuantityGroups::Item

Inherits:
Object
  • Object
show all
Defined in:
app/models/solidus_promotions/benefits/adjust_line_item_quantity_groups.rb

Overview

Used specifically for PercentOnLineItem calculator. That calculator uses ‘line_item.amount`, however we might not necessarily want to discount the entire amount. This class allows us to determine the discount per quantity and then calculate the adjustment amount the way we normally do for flat rate adjustments.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(line_item) ⇒ Item

Returns a new instance of Item.



88
89
90
# File 'app/models/solidus_promotions/benefits/adjust_line_item_quantity_groups.rb', line 88

def initialize(line_item)
  @line_item = line_item
end

Instance Attribute Details

#line_itemObject (readonly)

Returns the value of attribute line_item.



86
87
88
# File 'app/models/solidus_promotions/benefits/adjust_line_item_quantity_groups.rb', line 86

def line_item
  @line_item
end

Instance Method Details

#currencyObject



101
102
103
# File 'app/models/solidus_promotions/benefits/adjust_line_item_quantity_groups.rb', line 101

def currency
  @line_item.currency
end

#discountable_amountObject Also known as: amount



92
93
94
# File 'app/models/solidus_promotions/benefits/adjust_line_item_quantity_groups.rb', line 92

def discountable_amount
  @line_item.discountable_amount / @line_item.quantity.to_d
end

#orderObject



97
98
99
# File 'app/models/solidus_promotions/benefits/adjust_line_item_quantity_groups.rb', line 97

def order
  @line_item.order
end