Class: Spree::Promotion::Actions::CreateItemAdjustments
- Inherits:
-
Spree::PromotionAction
- Object
- ApplicationRecord
- Base
- Spree::PromotionAction
- Spree::Promotion::Actions::CreateItemAdjustments
- Includes:
- AdjustmentSource, CalculatedAdjustments
- Defined in:
- app/models/spree/promotion/actions/create_item_adjustments.rb
Instance Method Summary collapse
Methods inherited from Base
belongs_to_required_by_default, for_store, has_many_inversing, json_api_columns, json_api_permitted_attributes, json_api_type, page, spree_base_scopes, spree_base_uniqueness_scope
Methods included from Spree::Preferences::Preferable
#clear_preferences, #default_preferences, #defined_preferences, #deprecated_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_deprecated, #preference_type, #set_preference
Instance Method Details
#compute_amount(line_item) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/models/spree/promotion/actions/create_item_adjustments.rb', line 19 def compute_amount(line_item) return 0 unless promotion.line_item_actionable?(line_item.order, line_item) amounts = [line_item.amount, compute(line_item)] order = line_item.order # Prevent negative order totals amounts << order.amount - order.adjustments.eligible.sum(:amount).abs if order.adjustments.eligible.any? amounts.min * -1 end |
#perform(options = {}) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'app/models/spree/promotion/actions/create_item_adjustments.rb', line 10 def perform( = {}) order = [:order] promotion = [:promotion] create_unique_adjustments(order, order.line_items) do |line_item| promotion.line_item_actionable?(order, line_item) end end |