Sha256: 2bf824b7459421807384fce4a6c7df5807b6f805dc224b106d3ec356e4587975

Contents?: true

Size: 599 Bytes

Versions: 2

Compression:

Stored size: 599 Bytes

Contents

module RailsMarketplace
	class Order < ActiveRecord::Base
		has_many :order_products
		has_many :products, :through => :order_products
		belongs_to :customer
		belongs_to :seller

		def save_products(cart_products)
			cart_products.each do |cart_product|
				order_products << OrderProduct.new(product_id: cart_product.product_id, quantity: cart_product.quantity, price: cart_product.price)
			end
		end

		def order_subtotal
			subtotal = 0
			order_products.each do |order_product|
				subtotal += order_product.quantity * order_product.price
			end
			subtotal
		end
	end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rails_marketplace-0.0.2 app/models/rails_marketplace/order.rb
rails_marketplace-0.0.1 app/models/rails_marketplace/order.rb