Class: Spree::PromotionHandler::Coupon

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

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Coupon) initialize(order)

Returns a new instance of Coupon



7
8
9
# File 'app/models/spree/promotion_handler/coupon.rb', line 7

def initialize(order)
  @order = order
end

Instance Attribute Details

- (Object) error

Returns the value of attribute error



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

def error
  @error
end

- (Object) order (readonly)

Returns the value of attribute order



4
5
6
# File 'app/models/spree/promotion_handler/coupon.rb', line 4

def order
  @order
end

- (Object) status_code

Returns the value of attribute status_code



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

def status_code
  @status_code
end

- (Object) success

Returns the value of attribute success



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

def success
  @success
end

Instance Method Details

- (Object) apply



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/models/spree/promotion_handler/coupon.rb', line 11

def apply
  if order.coupon_code.present?
    if promotion.present? && promotion.actions.exists?
      handle_present_promotion(promotion)
    elsif promotion_code && promotion_code.promotion.inactive?
      set_error_code :coupon_code_expired
    else
      set_error_code :coupon_code_not_found
    end
  end

  self
end

- (Object) promotion



35
36
37
38
39
40
41
# File 'app/models/spree/promotion_handler/coupon.rb', line 35

def promotion
  @promotion ||= begin
    if promotion_code && promotion_code.promotion.active?
      promotion_code.promotion
    end
  end
end

- (Object) set_error_code(c)



30
31
32
33
# File 'app/models/spree/promotion_handler/coupon.rb', line 30

def set_error_code(c)
  @status_code = c
  @error = Spree.t(c)
end

- (Object) set_success_code(c)



25
26
27
28
# File 'app/models/spree/promotion_handler/coupon.rb', line 25

def set_success_code(c)
  @status_code = c
  @success = Spree.t(c)
end

- (Boolean) successful?

Returns:

  • (Boolean)


43
44
45
# File 'app/models/spree/promotion_handler/coupon.rb', line 43

def successful?
  success.present? && error.blank?
end