/
spirzen
/
it-code-examples
Обзор
Документация
Войти
/
spirzen
/
it-code-examples
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
examples/ruby/ruby-511-101-013/main.rb
44 строки
921 B
Spirzen
Code migration pack
09 июн 2026, 01:41
09 июн 2026, 01:41
cebc284
Код
Авторство
О чём код?
def process_order(params) user = User.find_by(email: params[:email]) if user.nil? user = User.create!( email: params[:email], name: params[:name], address: params[:address] ) end order = Order.new order.user = user order.status = :pending total = 0 params[:items].each do |item_params| product = Product.find(item_params[:product_id]) quantity = item_params[:quantity].to_i item_total = product.price * quantity total += item_total order.items << OrderItem.new( product: product, quantity: quantity, unit_price: product.price ) end order.total = total order.tax = total * 0.2 order.grand_total = order.total + order.tax if order.grand_total > 1000 order.apply_discount(5) end order.save! PaymentService.new.process(order) if params[:payment_method] NotificationService.new.order_created(order) order end