Class: Spree::Promotion::Actions::CreateItemAdjustments Private
- Inherits:
-
Spree::PromotionAction
- Object
- ActiveRecord::Base
- Base
- Spree::PromotionAction
- Spree::Promotion::Actions::CreateItemAdjustments
- Includes:
- AdjustmentSource, CalculatedAdjustments
- Defined in:
- app/models/spree/promotion/actions/create_item_adjustments.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Direct Known Subclasses
Instance Method Summary collapse
-
#compute_amount(adjustable) ⇒ Object
private
Ensure a negative amount which does not exceed the sum of the order’s item_total and ship_total.
- #perform(payload = {}) ⇒ Object private
-
#remove_from(order) ⇒ void
private
Removes any adjustments generated by this action from the order’s line items.
Methods included from AdjustmentSource
#deals_with_adjustments_for_deleted_source
Methods included from CalculatedAdjustments
#calculator_type, #calculator_type=
Methods inherited from Base
display_includes, #initialize_preference_defaults, page, preference
Methods included from Spree::Preferences::Preferable
#default_preferences, #defined_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_type, #set_preference
Instance Method Details
#compute_amount(adjustable) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Ensure a negative amount which does not exceed the sum of the order’s item_total and ship_total
31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/models/spree/promotion/actions/create_item_adjustments.rb', line 31 def compute_amount(adjustable) order = adjustable.is_a?(Order) ? adjustable : adjustable.order return 0 unless promotion.line_item_actionable?(order, adjustable) promotion_amount = calculator.compute(adjustable) if !promotion_amount.is_a?(BigDecimal) Spree::Deprecation.warn "#{calculator.class.name}#compute returned #{promotion_amount.inspect}, it should return a BigDecimal" end promotion_amount ||= BigDecimal.new(0) promotion_amount = promotion_amount.abs [adjustable.amount, promotion_amount].min * -1 end |
#perform(payload = {}) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/models/spree/promotion/actions/create_item_adjustments.rb', line 15 def perform(payload = {}) order = payload[:order] promotion = payload[:promotion] promotion_code = payload[:promotion_code] result = false line_items_to_adjust(promotion, order).each do |line_item| current_result = create_adjustment(line_item, order, promotion_code) result ||= current_result end result end |
#remove_from(order) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Removes any adjustments generated by this action from the order’s
line items.
47 48 49 50 51 52 53 54 55 |
# File 'app/models/spree/promotion/actions/create_item_adjustments.rb', line 47 def remove_from(order) order.line_items.each do |line_item| line_item.adjustments.each do |adjustment| if adjustment.source == self line_item.adjustments.destroy(adjustment) end end end end |