Class: Coupon::Tier2ProgramPricing
- Inherits:
-
Coupon
- Object
- Coupon
- Coupon::Tier2ProgramPricing
- Defined in:
- app/services/coupon/tier2_program_pricing.rb
Overview
Service object: tier2 program pricing.
Constant Summary collapse
- MSRP_ID =
Msrp id.
577- TRADE_ID =
Trade id.
584
Instance Attribute Summary collapse
- #auto_apply ⇒ Object readonly
Has many collapse
Class Method Summary collapse
- .customer_default ⇒ Object
- .customer_default_trade ⇒ Object
- .friendly_type_name ⇒ Object
- .get_customer_pricing(customer) ⇒ Object
- .get_pricing(profile, _buying_group = nil) ⇒ Object
- .model_name ⇒ Object
- .msrp_tier2_pricing_coupon ⇒ Object
- .select_options ⇒ Object
- .select_options_for_customer(customer, role_ids = []) ⇒ Object
Instance Method Summary collapse
- #blacklistable? ⇒ Boolean
- #custom? ⇒ Boolean
- #discount_percentage ⇒ Object
- #msrp? ⇒ Boolean
- #override? ⇒ Boolean
Instance Attribute Details
#auto_apply ⇒ Object (readonly)
11 |
# File 'app/services/coupon/tier2_program_pricing.rb', line 11 validates :auto_apply, inclusion: { in: [false], message: "can only be false for this type of coupon" } |
Class Method Details
.customer_default ⇒ Object
21 22 23 |
# File 'app/services/coupon/tier2_program_pricing.rb', line 21 def self.customer_default Coupon.find_by(code: 'PP-LEVEL-ZERO') end |
.customer_default_trade ⇒ Object
25 26 27 |
# File 'app/services/coupon/tier2_program_pricing.rb', line 25 def self.customer_default_trade Coupon.find_by(code: 'PP-SILVER-LEVEL') end |
.friendly_type_name ⇒ Object
81 82 83 |
# File 'app/services/coupon/tier2_program_pricing.rb', line 81 def self.friendly_type_name "Customer Pricing Program" end |
.get_customer_pricing(customer) ⇒ Object
70 71 72 73 74 75 |
# File 'app/services/coupon/tier2_program_pricing.rb', line 70 def self.get_customer_pricing(customer) return customer_default unless customer.catalog.is_main_catalog? # custom catalog always MSRP return customer_default if customer.profile.e_commerce_misc? # etailer always MSRP get_pricing(customer.profile, customer.) end |
.get_pricing(profile, _buying_group = nil) ⇒ Object
62 63 64 65 66 67 68 |
# File 'app/services/coupon/tier2_program_pricing.rb', line 62 def self.get_pricing(profile, = nil) if profile.try(:organization?) customer_default_trade else customer_default # msrp end end |
.model_name ⇒ Object
17 18 19 |
# File 'app/services/coupon/tier2_program_pricing.rb', line 17 def self.model_name Coupon.model_name end |
.msrp_tier2_pricing_coupon ⇒ Object
13 14 15 |
# File 'app/services/coupon/tier2_program_pricing.rb', line 13 def self.msrp_tier2_pricing_coupon Coupon.find_by(code: 'PP-LEVEL-ZERO') end |
.select_options ⇒ Object
41 42 43 |
# File 'app/services/coupon/tier2_program_pricing.rb', line 41 def self. all.order(:title).pluck(:title, :id) end |
.select_options_for_customer(customer, role_ids = []) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/services/coupon/tier2_program_pricing.rb', line 45 def self.(customer, role_ids = []) qb = Coupon::QueryBuilder.new qb = qb.for_customer(customer) qb = qb.with_role_ids(role_ids) if role_ids.present? programs = all.active.merge(qb.query) results = programs.order(:title).map { |cp| [cp.title, cp.id] } results << [customer.tier2_program_pricing.title, customer.tier2_program_pricing.id] if customer.tier2_program_pricing # Add default for profile and buying group too if (tpp = customer..try(:tier2_program_pricing)) results << [tpp.title, tpp.id] end if (tpp = customer.profile.try(:tier2_program_pricing)) results << [tpp.title, tpp.id] end results.uniq.sort end |
Instance Method Details
#blacklistable? ⇒ Boolean
77 78 79 |
# File 'app/services/coupon/tier2_program_pricing.rb', line 77 def blacklistable? true end |
#custom? ⇒ Boolean
33 34 35 |
# File 'app/services/coupon/tier2_program_pricing.rb', line 33 def custom? code.starts_with?('CUSTOM') end |
#customers ⇒ ActiveRecord::Relation<Customer>
9 |
# File 'app/services/coupon/tier2_program_pricing.rb', line 9 has_many :customers |
#discount_percentage ⇒ Object
85 86 87 |
# File 'app/services/coupon/tier2_program_pricing.rb', line 85 def discount_percentage amount_goods.to_i end |
#msrp? ⇒ Boolean
29 30 31 |
# File 'app/services/coupon/tier2_program_pricing.rb', line 29 def msrp? %w[PPMSRP PP-LEVEL-ZERO].include?(code) end |
#override? ⇒ Boolean
37 38 39 |
# File 'app/services/coupon/tier2_program_pricing.rb', line 37 def override? code.ends_with?('OVERRIDE') end |