From ad2d58771b6531fed4af5114dc7410042e97c654 Mon Sep 17 00:00:00 2001 From: Bo Trethewey Date: Sat, 22 Apr 2017 20:33:12 -0700 Subject: [PATCH] custom method in_cart? added --- app/models/order.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/models/order.rb b/app/models/order.rb index 9dceb58afa..597650157e 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -11,7 +11,15 @@ class Order < ApplicationRecord validates :exp_month, :exp_year, presence: true, format: { with: /\A\d{2}\z/ }, unless: :in_cart? validates :cvv, presence: true, format: { with: /\A\d{3}\z/ }, unless: :in_cart? - def in_cart? - order_state == "pending" +def in_cart? + order_state == "pending" +end + + def sub_total + orderitems.inject(0, :+) + end + + def last_four_digits + card_number.split(//).last(4).join end end