Skip to content

Instantly share code, notes, and snippets.

@mhenrixon
Last active December 11, 2015 20:49
Show Gist options
  • Save mhenrixon/4658337 to your computer and use it in GitHub Desktop.
Save mhenrixon/4658337 to your computer and use it in GitHub Desktop.
class Refill
attr_reader :card, :product, :prices, :details, :total_price
def initialize(card, product, discount_price = nil)
@card = card
@product = product
@discount_price = discount_price
@prices = product.prices.map(&:price)
@total_price = if product.product_type === 'discount'
set_discount_price
else
set_regular_price
end
end
def set_discount_price
@details = @card.purse_details
if prices.include?(discount_price.to_i)
discount_price
else
prices[0]
end
end
def set_regular_price
@details = card.period_details
card.period_price
end
end
class Public::RefillsController < ApplicationController
def new
card = Card.find(params[:card_id])
product = Product.find(params[:product_id])
@refill = Refill.new(car, product, params[:discount_price])
find_or_create_order
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment