Class: SolidusFriendlyPromotions::FriendlyPromotionAdjuster::DiscountOrder
- Inherits:
-
Object
- Object
- SolidusFriendlyPromotions::FriendlyPromotionAdjuster::DiscountOrder
- Defined in:
- app/models/solidus_friendly_promotions/friendly_promotion_adjuster/discount_order.rb
Instance Attribute Summary collapse
-
#dry_run ⇒ Object
readonly
Returns the value of attribute dry_run.
-
#order ⇒ Object
readonly
Returns the value of attribute order.
-
#promotions ⇒ Object
readonly
Returns the value of attribute promotions.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(order, promotions, dry_run: false) ⇒ DiscountOrder
constructor
A new instance of DiscountOrder.
Constructor Details
#initialize(order, promotions, dry_run: false) ⇒ DiscountOrder
Returns a new instance of DiscountOrder.
8 9 10 11 12 |
# File 'app/models/solidus_friendly_promotions/friendly_promotion_adjuster/discount_order.rb', line 8 def initialize(order, promotions, dry_run: false) @order = order @promotions = promotions @dry_run = dry_run end |
Instance Attribute Details
#dry_run ⇒ Object (readonly)
Returns the value of attribute dry_run.
6 7 8 |
# File 'app/models/solidus_friendly_promotions/friendly_promotion_adjuster/discount_order.rb', line 6 def dry_run @dry_run end |
#order ⇒ Object (readonly)
Returns the value of attribute order.
6 7 8 |
# File 'app/models/solidus_friendly_promotions/friendly_promotion_adjuster/discount_order.rb', line 6 def order @order end |
#promotions ⇒ Object (readonly)
Returns the value of attribute promotions.
6 7 8 |
# File 'app/models/solidus_friendly_promotions/friendly_promotion_adjuster/discount_order.rb', line 6 def promotions @promotions end |
Instance Method Details
#call ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/models/solidus_friendly_promotions/friendly_promotion_adjuster/discount_order.rb', line 14 def call return order if order.shipped? SolidusFriendlyPromotions::Promotion.ordered_lanes.each do |lane, _index| lane_promotions = promotions.select { |promotion| promotion.lane == lane } lane_benefits = eligible_benefits_for_promotable(lane_promotions.flat_map(&:benefits), order) perform_order_benefits(lane_benefits, lane) unless dry_run line_item_discounts = adjust_line_items(lane_benefits) shipment_discounts = adjust_shipments(lane_benefits) shipping_rate_discounts = adjust_shipping_rates(lane_benefits) (line_item_discounts + shipment_discounts + shipping_rate_discounts).each do |item, chosen_discounts| item.current_discounts.concat(chosen_discounts) end end order end |