Action Mailer:在结账时将购物车视图发送到电子邮件

时间:2016-07-19 19:41:47

标签: ruby-on-rails actionmailer

我希望收到购物车视图的电子邮件,当客户点击继续结帐按钮时,所有订单都会发送给店主。

我已经有一个联系表单,所以我在配置/ stpm_settings中设置了admin gmail设置。

我不确定我是否在正确的轨道上,但这是我到目前为止: 我创建了一条路线:

get :send_order_mail, to: 'orders#send_order_mail', as: :send_order_mail

我创建了邮件

class OrderMailer < ApplicationMailer
    default :from => "admins@gmail.com"

  def order_send(order, client)
    @order = order
    @client = client
    mail(to: "admins@gmail.com", subject: "New Order")
  end
end

购物车/ show.html.erb底部的提交按钮

<div class="shopping-cart">

  <%= render "shopping_cart" %>
 <h4 class="text-right">Subtotal: <span style="color: green"><%= number_to_currency current_order.subtotal %></span></h4>
 <h4 class="text-right">Shipping: <span style="color: green"><%= number_to_currency current_order.shipping %></span></h4>
  <h4 class="text-right">Order Total: <span style="color: green"><%= number_to_currency current_order.total %></span></h4>

<%= link_to "Send Order by email", :controller => "orders", :action => "send_order_mail" %>
</div>

这是我的推车控制器

class CartsController < ApplicationController
  def show
    @order_items = current_order.order_items
    @shipping = params[:shipping]

    OrderMailer.order_send(@order, @client).deliver
    flash[:notice] = "Order has been sent."
    redirect_to carge_path(@order.id)
  end

  def order_subtotal
   @order_items.sum(:total_price)
  end

0 个答案:

没有答案