Class: Coupon::Tier2ProgramPricing

Inherits:
Coupon
  • Object
show all
Defined in:
app/services/coupon/tier2_program_pricing.rb

Constant Summary collapse

MSRP_ID =
577
TRADE_ID =
584

Instance Attribute Summary collapse

Has many collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#auto_applyObject (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_defaultObject



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_tradeObject



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_nameObject



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.buying_group)
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, buying_group = nil)
  if profile.try(:organization?)
    customer_default_trade
  else
    customer_default #msrp
  end
end

.model_nameObject



14
15
16
# File 'app/services/coupon/tier2_program_pricing.rb', line 14

def self.model_name
  Coupon.model_name
end

.msrp_tier2_pricing_couponObject



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_optionsObject



38
39
40
# File 'app/services/coupon/tier2_program_pricing.rb', line 38

def self.select_options
  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.select_options_for_customer(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.buying_group.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

Returns:

  • (Boolean)


73
74
75
# File 'app/services/coupon/tier2_program_pricing.rb', line 73

def blacklistable?
  true
end

#custom?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'app/services/coupon/tier2_program_pricing.rb', line 30

def custom?
  code.starts_with?('CUSTOM')
end

#customersActiveRecord::Relation<Customer>

Returns:

See Also:



6
# File 'app/services/coupon/tier2_program_pricing.rb', line 6

has_many :customers

#discount_percentageObject



81
82
83
# File 'app/services/coupon/tier2_program_pricing.rb', line 81

def discount_percentage
  amount_goods.to_i
end

#msrp?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


34
35
36
# File 'app/services/coupon/tier2_program_pricing.rb', line 34

def override?
  code.ends_with?('OVERRIDE')
end