Class: Coupon::Tier2ProgramPricing
- Inherits:
-
Coupon
- Object
- Coupon
- Coupon::Tier2ProgramPricing
- Defined in:
- app/services/coupon/tier2_program_pricing.rb
Constant Summary collapse
- MSRP_ID =
577- 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)
8 |
# File 'app/services/coupon/tier2_program_pricing.rb', line 8 validates :auto_apply, :inclusion => { :in => [false], :message => "can only be false for this type of coupon" } |
Class Method Details
.customer_default ⇒ Object
18 19 20 |
# File 'app/services/coupon/tier2_program_pricing.rb', line 18 def self.customer_default Coupon.find_by(code: 'PP-LEVEL-ZERO') end |
.customer_default_trade ⇒ Object
22 23 24 |
# File 'app/services/coupon/tier2_program_pricing.rb', line 22 def self.customer_default_trade Coupon.find_by(code: 'PP-SILVER-LEVEL') end |
.friendly_type_name ⇒ Object
77 78 79 |
# File 'app/services/coupon/tier2_program_pricing.rb', line 77 def self.friendly_type_name "Customer Pricing Program" end |
.get_customer_pricing(customer) ⇒ Object
67 68 69 70 71 |
# File 'app/services/coupon/tier2_program_pricing.rb', line 67 def self.get_customer_pricing(customer) return customer_default if !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
59 60 61 62 63 64 65 |
# File 'app/services/coupon/tier2_program_pricing.rb', line 59 def self.get_pricing(profile, = nil) if profile.try(:organization?) customer_default_trade else customer_default #msrp end end |
.model_name ⇒ Object
14 15 16 |
# File 'app/services/coupon/tier2_program_pricing.rb', line 14 def self.model_name Coupon.model_name end |
.msrp_tier2_pricing_coupon ⇒ Object
10 11 12 |
# File 'app/services/coupon/tier2_program_pricing.rb', line 10 def self.msrp_tier2_pricing_coupon Coupon.find_by(code: 'PP-LEVEL-ZERO') end |
.select_options ⇒ Object
38 39 40 |
# File 'app/services/coupon/tier2_program_pricing.rb', line 38 def self. all.order(:title).pluck(:title, :id) end |
.select_options_for_customer(customer, role_ids = []) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/services/coupon/tier2_program_pricing.rb', line 42 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
73 74 75 |
# File 'app/services/coupon/tier2_program_pricing.rb', line 73 def blacklistable? true end |
#custom? ⇒ Boolean
30 31 32 |
# File 'app/services/coupon/tier2_program_pricing.rb', line 30 def custom? code.starts_with?('CUSTOM') end |
#customers ⇒ ActiveRecord::Relation<Customer>
6 |
# File 'app/services/coupon/tier2_program_pricing.rb', line 6 has_many :customers |
#discount_percentage ⇒ Object
81 82 83 |
# File 'app/services/coupon/tier2_program_pricing.rb', line 81 def discount_percentage amount_goods.to_i end |
#msrp? ⇒ Boolean
26 27 28 |
# File 'app/services/coupon/tier2_program_pricing.rb', line 26 def msrp? code == 'PPMSRP' or code == 'PP-LEVEL-ZERO' end |
#override? ⇒ Boolean
34 35 36 |
# File 'app/services/coupon/tier2_program_pricing.rb', line 34 def override? code.ends_with?('OVERRIDE') end |