Guest User

Untitled

a guest
Nov 22nd, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. $('.menu-item-quantity input').change( function() {
  2. updateQuantity(this);
  3. });
  4.  
  5. function updateQuantity(quantityInput){
  6.  
  7. var productRow = $(quantityInput).parent().parent();
  8. var price = parseFloat(productRow.children('.menu-item-price').text());
  9. var quantity = $(quantityInput).val();
  10. var linePrice = price * quantity;
  11.  
  12. productRow.children('.item-total').each(function () {
  13. $(this).fadeOut(fadeTime, function() {
  14. $(this).text(linePrice.toFixed(2));
  15. recalculateCart();
  16. $(this).fadeIn(fadeTime);
  17. });
  18. });
  19. }
  20.  
  21. function renderCart(){
  22.  
  23. var $shoppingCart = $(".shopping-cart");
  24. $shoppingCart.html("");
  25. var visibleAttributes = [ "name", "price" ];
  26. $.each(cart, function(i, item){
  27. var cartItemHTML = "<div class='cart-item'>";
  28. $.each(visibleAttributes, function(i, attribute){
  29. cartItemHTML += "<div class=menu-item-" + attribute + ">" + item[attribute] + "</div>";
  30. });
  31. cartItemHTML += "<div class='menu-item-quantity input'>" + "<input type='number' value='1' min='1'>" + "</div>";
  32. cartItemHTML += "<div class='item-total'>" + item.price + "</div>";
  33. cartItemHTML += "<div class='product-removal'>" + "<button class='remove-menu-item'>" + "X" + "</button>" + "</div>";
  34. cartItemHTML += "</div>";
  35. $shoppingCart.append(cartItemHTML);
  36. recalculateCart()
  37. });
  38. }
Add Comment
Please, Sign In to add comment