简体   繁体   English

将运费加到总计

[英]Add shipping price to total

I am having trouble figuring out how to add shipping cost to my total cart cost in the view of my shopping cart app to calculate an order total. 我在我的购物车应用程序视图中无法计算出如何将运费增加到我的购物车总费用中,从而无法计算订单总额。

So far I have ruby code that adds up all of the orders and calculates a order subtotal. 到目前为止,我有ruby代码,该代码将所有订单加起来并计算订单小计。 I have also added a simple html input form with the shipping options. 我还添加了带有运输选项的简单html输入表单。 What I cant figure is how to add the subtotal up with the shipping option that is selected. 我无法确定的是如何将小计与所选的运输选项相加。 I feel like there is a simple way to to this in rails but I cant figure out what that would be. 我觉得有一个简单的方法可以解决这个问题,但是我不知道那是什么。

Thanks in advance for any help 预先感谢您的任何帮助

_shopping_cart.html.erb _shopping_cart.html.erb

<% if !@order_item.nil? && @order_item.errors.any? %>
  <div class="alert alert-danger">
    <ul>
    <% @order_item.errors.full_messages.each do |msg| %>
      <li><%= msg %></li>
    <% end %>
    </ul>
  </div>
<% end %>
<% if @order_items.size == 0 %>
  <p class="text-center">
    There are no items in your shopping cart.  Please <%= link_to "go back", root_path %> and add some items to your cart.
  </p>
<% else %>
  <% @order_items.each do |order_item| %>
    <%= render 'carts/cart_row', product: order_item.product, order_item: order_item, show_total: true %>
  <% end %>
   <p class="text-center">Order Subtotal=<%= @order_items.sum(:total_price)%></p>
<% end %>
<P class="text-center">Please select shipping:</P>
<P class="text-center"><LABEL ACCESSKEY=C><INPUT TYPE=radio NAME="payment_method" VALUE="2.5" CHECKED> $2.50 US Standard</LABEL><BR>
<LABEL ACCESSKEY=D><INPUT TYPE=radio NAME="payment_method" VALUE="5.5"> $5.50 US Priority</LABEL><BR>
<LABEL ACCESSKEY=M><INPUT TYPE=radio NAME="payment_method" VALUE="9.5"> $9.50 International</LABEL><BR>
<LABEL ACCESSKEY=N><INPUT TYPE=radio NAME="payment_method" VALUE="14.5">  $14.50 International Priority</LABEL></P>

我想你想做:

shipping_cost + cart.total

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM