Navigation Menu

Skip to content

Commit

Permalink
implement cart_total_price function
Browse files Browse the repository at this point in the history
  • Loading branch information
anndoko committed May 9, 2017
1 parent 156c377 commit d6b68ed
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions app/helpers/carts_helper.rb
@@ -1,2 +1,5 @@
module CartsHelper
def render_cart_total_price(cart)
cart.total_price
end
end
10 changes: 10 additions & 0 deletions app/models/cart.rb
Expand Up @@ -9,4 +9,14 @@ def add_product_to_cart(product)
ci.quantity = 1
ci.save
end

def total_price
sum = 0
cart_items.each do |cart_item|
if cart_item.product.price.present?
sum = cart_item.quantity * cart_item.product.price
end
end
sum
end
end
2 changes: 1 addition & 1 deletion app/views/carts/index.html.erb
Expand Up @@ -43,7 +43,7 @@

<div class="total clearfix">
<span class="pull-right">
<span> 總計 xxx RMB </span>
總計 <%= render_cart_total_price(current_cart) %> RMB
</span>
</div>

Expand Down

0 comments on commit d6b68ed

Please sign in to comment.