2016-07-13 3 views
0

주문 총액을 계산하기 위해 장바구니 앱에서 총 장바구니 비용에 배송비를 추가하는 방법을 파악하는 데 문제가 있습니다.총계에 배송비 추가

지금까지 나는 모든 주문을 합산하고 주문 부분합을 계산하는 루비 코드를 가지고 있습니다. 운송 옵션이있는 간단한 html 입력 양식도 추가했습니다. 내가 이해할 수없는 것은 선택된 운송 옵션으로 소계를 추가하는 f}입니다. 나는 레일에서 이것을 할 수있는 간단한 방법이있는 것처럼 느껴지지만 그것이 무엇이 될지 짐작할 수 없다. 어떤 도움

_shopping_cart.html.erb

<% if [email protected]_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> 
+0

나는 당신의 질문은 무엇을 의미하는지 상상할 수 없다. 그것은 완전히 일치하지 않습니다. 당신이 주장하는대로, 이것을 합산 한 코드와 그 코드, 그리고 다른 코드를 가지고 있다면, 운송 비용을 추가하는 것이 많은 편입니다. 나는 그런 코드가 존재한다고 실제로 생각하지 않는다. 포함 된 스 니펫이 합계를 계산하는 것과 아무런 관련이 없다는 사실이 나를 확신으로 채우는 것은 아닙니다. –

답변

0

에 미리

덕분에 나는 당신이하고 싶은 생각 :

shipping_cost + cart.total