Advertisement
Guest User

Untitled

a guest
Jul 31st, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. $(document).ready(function () {
  2. update();
  3. $(".quant").change(function() {
  4.  
  5. update();
  6. });
  7. function update() {
  8.  
  9. var id = $('.quant').attr('data-id');
  10. var sum = 0.0;
  11. var quantity;
  12. $('#myTable > tbody > tr').each(function () {
  13.  
  14.  
  15. quantity = $(this).find('.quant').val();
  16. var price = parseFloat($(this).find('.price').attr('data-price').replace(',', '.'));
  17. var amount = (quantity * price);
  18.  
  19. sum += amount;
  20. $(this).find('.amount').text('' + amount + ' грн');
  21.  
  22. });
  23.  
  24. $('.total').text(sum + ' грн');
  25.  
  26. $.get(
  27. '/Cart/AddTocart',
  28. {
  29. id: id,
  30. returnUrl: '',
  31. quantity: quantity
  32.  
  33. }
  34. );
  35. }
  36.  
  37. });
  38.  
  39. var id = $(this).attr('data-id');
  40.  
  41. var quantity;
  42. $('#myTable > tbody > tr').each(function () {
  43. quantity = $(this).find('.quant').val();
  44. ...
  45. }
  46.  
  47. <thead>
  48. <tr>
  49. <th class="text-center">Товар</th>
  50. <th class="text-center">К-сть</th>
  51. <th>Назва Товару</th>
  52. <th class="text-right">Ціна</th>
  53. <th class="text-right">Загальна ціна</th>
  54. </tr>
  55. </thead>
  56.  
  57. <tbody>
  58. @foreach (var line in Model.Cart.Lines)
  59. {
  60.  
  61.  
  62. IEnumerable<FurnitureImages> images = line.Furniture.Images;
  63. FurnitureImages mainImage = images.Where(x => x.IsMainImage).FirstOrDefault();
  64.  
  65. <tr>
  66. <td class="text-center">
  67. @if (mainImage != null)
  68. {
  69.  
  70. <img src="@Url.Content(mainImage.Path)" style="width:110px; height:70px" />
  71. }
  72.  
  73. </td>
  74.  
  75. <td class="text-center">
  76. <input type="text" data-id="@line.Furniture.FurnitureId" data-price="@line.Furniture.Price" value="@line.Quantity" class="quant" />
  77. </td>
  78. <td class="text-left">@line.Furniture.Name</td>
  79. <td class="text-right price" data-price="@line.Furniture.Price">@((line.Furniture.Price).ToString("#.## грн"))</td>
  80. <td class="text-right amount">@((line.Quantity * line.Furniture.Price).ToString("#.## грн"))</td>
  81. <td>
  82. @using (Html.BeginForm("RemoveFromCart", "Cart", new { Id = line.Furniture.FurnitureId }))
  83. {
  84. @Html.Hidden("Id", line.Furniture.FurnitureId)
  85. @Html.HiddenFor(x => x.ReturnUrl)
  86. <input class="btn btn-sm btn-warning" type="submit" value="Видалити з кошику" />
  87. }
  88.  
  89.  
  90. </td>
  91.  
  92.  
  93. </tr>
  94. }
  95.  
  96. </tbody>
  97.  
  98. <tfoot>
  99.  
  100. <tr>
  101. <td colspan="4" class="text-right"><b>Всього до оплати:</b></td>
  102. <td id="test" class="text-right total">@Model.Cart.ComputeTotalValue().ToString("#.## грн")</td>
  103. </tr>
  104.  
  105.  
  106. </tfoot>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement