Class: Spree::PromotionHandler::FreeShipping

Inherits:
Object
  • Object
show all
Defined in:
app/models/spree/promotion_handler/free_shipping.rb

Overview

Used for activating promotions with shipping rules

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(order) ⇒ FreeShipping


8
9
10
11
# File 'app/models/spree/promotion_handler/free_shipping.rb', line 8

def initialize(order)
  @order = order
  @order_promo_ids = order.promotions.pluck(:id)
end

Instance Attribute Details

#errorObject

Returns the value of attribute error


6
7
8
# File 'app/models/spree/promotion_handler/free_shipping.rb', line 6

def error
  @error
end

#orderObject (readonly)

Returns the value of attribute order


5
6
7
# File 'app/models/spree/promotion_handler/free_shipping.rb', line 5

def order
  @order
end

#order_promo_idsObject (readonly)

Returns the value of attribute order_promo_ids


5
6
7
# File 'app/models/spree/promotion_handler/free_shipping.rb', line 5

def order_promo_ids
  @order_promo_ids
end

#successObject

Returns the value of attribute success


6
7
8
# File 'app/models/spree/promotion_handler/free_shipping.rb', line 6

def success
  @success
end

Instance Method Details

#activateObject


13
14
15
16
17
18
19
# File 'app/models/spree/promotion_handler/free_shipping.rb', line 13

def activate
  promotions.each do |promotion|
    next if promotion.code.present? && !order_promo_ids.include?(promotion.id)

    promotion.activate(order: order) if promotion.eligible?(order)
  end
end