Class: C2eCore::Drops::PromoCodeClaimedDrop

Inherits:
BaseDrop
  • Object
show all
Defined in:
/build/app/mailers/c2e_core/drops/promo_code_claimed_drop.rb

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ PromoCodeClaimedDrop

Returns a new instance of PromoCodeClaimedDrop.



7
8
9
10
11
12
# File '/build/app/mailers/c2e_core/drops/promo_code_claimed_drop.rb', line 7

def initialize(args)
  super()
  @promo_code_invitation = args[:promo_code_invitation]
  @company_branch = args[:company_branch]
  @customer = args[:customer]
end

Instance Method Details

#company_branchCompanyBranchDrop

Returns - company branch which given this promo code as drop object.

Returns:



15
16
17
18
19
# File '/build/app/mailers/c2e_core/drops/promo_code_claimed_drop.rb', line 15

def company_branch
  stored_value __method__ do
    CompanyBranchDrop.new @company_branch
  end
end

#descriptionString

Returns - Description of rule which generated this promo code.

Returns:

  • (String)
    • Description of rule which generated this promo code.



32
33
34
# File '/build/app/mailers/c2e_core/drops/promo_code_claimed_drop.rb', line 32

def description
  C2eCore::JsonLocalization.locale_for(@promo_code_invitation.description&.dig("full"), I18n.locale).to_s
end

#is_promo_codeBoolean

Returns - Return true when promo code is promo code type.

Returns:

  • (Boolean)
    • Return true when promo code is promo code type.



47
48
49
# File '/build/app/mailers/c2e_core/drops/promo_code_claimed_drop.rb', line 47

def is_promo_code
  !@promo_code_invitation.promo_code.voucher?
end

#is_voucherBoolean

Returns - Return true when promo code is voucher type.

Returns:

  • (Boolean)
    • Return true when promo code is voucher type.



42
43
44
# File '/build/app/mailers/c2e_core/drops/promo_code_claimed_drop.rb', line 42

def is_voucher
  @promo_code_invitation.promo_code.voucher?
end

#promo_codeString

Returns - Value of promo code that customer is allowed to use. E.g.: desata_zdarma.

Returns:

  • (String)
    • Value of promo code that customer is allowed to use. E.g.: desata_zdarma



22
23
24
# File '/build/app/mailers/c2e_core/drops/promo_code_claimed_drop.rb', line 22

def promo_code
  @promo_code_invitation.promo_code.code.to_s
end

#sms_descriptionString

Returns - Short version of description of rule which generated this promo code for SMS.

Returns:

  • (String)
    • Short version of description of rule which generated this promo code for SMS.



37
38
39
# File '/build/app/mailers/c2e_core/drops/promo_code_claimed_drop.rb', line 37

def sms_description
  C2eCore::JsonLocalization.locale_for(@promo_code_invitation.description&.dig("sms"), I18n.locale).to_s
end

#unsubscribe_urlString

Returns - URL for unsubscribing from marketing actions.

Returns:

  • (String)
    • URL for unsubscribing from marketing actions.



59
60
61
# File '/build/app/mailers/c2e_core/drops/promo_code_claimed_drop.rb', line 59

def unsubscribe_url
  C2eCore::Users::MarketingService.new(customer_id: @customer.id, company_branch_id: @company_branch.id).unsubscribe_url
end

#valid_untilDateTime

Returns - Datetime object containing validity of promo code usage. E.g.: “26. 7. 2023, 13:00”.

Returns:

  • (DateTime)
    • Datetime object containing validity of promo code usage. E.g.: “26. 7. 2023, 13:00”



27
28
29
# File '/build/app/mailers/c2e_core/drops/promo_code_claimed_drop.rb', line 27

def valid_until
  I18n.l @promo_code_invitation.valid_until, format: :short_year
end

#voucher_discountFloat

Returns - Price of current recipe converted into order’s currency. E.g.: 78.

Returns:

  • (Float)
    • Price of current recipe converted into order’s currency. E.g.: 78



52
53
54
55
56
# File '/build/app/mailers/c2e_core/drops/promo_code_claimed_drop.rb', line 52

def voucher_discount
  return 0 unless @promo_code_invitation.promo_code.voucher?

  @company_branch.default_currency.convert_and_round(Currency.internal, @promo_code_invitation.promo_code.discount)
end