From f158d350f10ae6850c7ee168f0345197c3265d5c Mon Sep 17 00:00:00 2001 From: HombreLaser Date: Sun, 16 Apr 2023 11:29:54 -0600 Subject: Añade método total a ProductOrder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/product_order.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/models/product_order.rb b/app/models/product_order.rb index 004f8fc..5194e6d 100644 --- a/app/models/product_order.rb +++ b/app/models/product_order.rb @@ -5,4 +5,12 @@ class ProductOrder < ApplicationRecord belongs_to :order belongs_to :product + + def total + if quantity < 5 + product.unitary_price * quantity + else + product.bulk_price * quantity + end + end end -- cgit v1.2.3