Class: C2eCore::Drops::PromoCodeClaimedDrop
- Defined in:
- /build/app/mailers/c2e_core/drops/promo_code_claimed_drop.rb
Instance Method Summary collapse
-
#company_branch ⇒ CompanyBranchDrop
-
company branch which given this promo code as drop object.
-
-
#description ⇒ String
-
Description of rule which generated this promo code.
-
-
#initialize(args) ⇒ PromoCodeClaimedDrop
constructor
A new instance of PromoCodeClaimedDrop.
-
#is_promo_code ⇒ Boolean
-
Return true when promo code is promo code type.
-
-
#is_voucher ⇒ Boolean
-
Return true when promo code is voucher type.
-
-
#promo_code ⇒ String
-
Value of promo code that customer is allowed to use.
-
-
#sms_description ⇒ String
-
Short version of description of rule which generated this promo code for SMS.
-
-
#unsubscribe_url ⇒ String
-
URL for unsubscribing from marketing actions.
-
-
#valid_until ⇒ DateTime
-
Datetime object containing validity of promo code usage.
-
-
#voucher_discount ⇒ Float
-
Price of current recipe converted into order’s currency.
-
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_branch ⇒ CompanyBranchDrop
Returns - company branch which given this promo code as drop object.
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 |
#description ⇒ String
Returns - 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_code ⇒ Boolean
Returns - 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_voucher ⇒ Boolean
Returns - 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_code ⇒ String
Returns - 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_description ⇒ String
Returns - 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_url ⇒ String
Returns - 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_until ⇒ DateTime
Returns - 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_discount ⇒ Float
Returns - 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 |