class Promotional::Rule::BasketRule

Attributes

value[R]

Public Class Methods

new(value, no_validate = false) click to toggle source
# File lib/wunder/promotional/rule/basket_rule.rb, line 6
def initialize(value, no_validate = false)
  @value = value

  validate if no_validate == false
end

Public Instance Methods

adjustable?(total) click to toggle source
# File lib/wunder/promotional/rule/basket_rule.rb, line 12
def adjustable?(total)
  return true if total > value
  false
end
calculate_total_discounted_price(total, discount_type) click to toggle source
# File lib/wunder/promotional/rule/basket_rule.rb, line 21
def calculate_total_discounted_price(total, discount_type)
  if discount_type == "percentage"
    discount_price = total - ((total * value) / 100)
  elsif discount_type == "flat_rate"
    discount_price = total
  end

  discount_price
end
eligible?(_item) click to toggle source
# File lib/wunder/promotional/rule/basket_rule.rb, line 17
def eligible?(_item)
  false
end
validate() click to toggle source
# File lib/wunder/promotional/rule/basket_rule.rb, line 31
def validate
  should_be_present("BasketRule::Value", value)
  should_be_a_number("BasketRule::Value",
                     value)
  should_be_more_than("BasketRule::MinQuantity",
                      value, 1)
end